From 59c8b47189a0e057358b435ec6edfa72bef6f973 Mon Sep 17 00:00:00 2001 From: R-Lawton Date: Thu, 24 Oct 2024 19:11:22 +0100 Subject: [PATCH 1/2] Fixed forms to be less squashed and fixed dns policy to not have lb be a requiremnet Signed-off-by: R-Lawton --- .../KuadrantDNSPolicyCreatePage.tsx | 155 +++++++++++------- src/components/KuadrantTLSCreatePage.tsx | 76 ++++----- src/components/dnspolicy/HealthCheckField.tsx | 25 ++- .../dnspolicy/LoadBalancingField.tsx | 90 ++++++---- src/components/dnspolicy/types.ts | 4 +- src/components/kuadrant.css | 1 + 6 files changed, 217 insertions(+), 134 deletions(-) diff --git a/src/components/KuadrantDNSPolicyCreatePage.tsx b/src/components/KuadrantDNSPolicyCreatePage.tsx index 8df526d..c063469 100644 --- a/src/components/KuadrantDNSPolicyCreatePage.tsx +++ b/src/components/KuadrantDNSPolicyCreatePage.tsx @@ -47,13 +47,13 @@ const KuadrantDNSPolicyCreatePage: React.FC = () => { const [loadBalancing, setLoadBalancing] = React.useState({ geo: '', weight: null, - defaultGeo: true, + defaultGeo: '', }); const [healthCheck, setHealthCheck] = React.useState({ endpoint: '', failureThreshold: null, port: null, - protocol: null, + protocol: '', }); const [providerRefs, setProviderRefs] = React.useState([]); const [creationTimestamp, setCreationTimestamp] = React.useState(''); @@ -64,6 +64,9 @@ const KuadrantDNSPolicyCreatePage: React.FC = () => { const namespaceEdit = pathSplit[3]; const [formDisabled, setFormDisabled] = React.useState(false); const [create, setCreate] = React.useState(true); + const [loadBalancingExpanded, setLoadBalancingExpanded] = React.useState(false); + const [healthExpanded, setHealthExpanded] = React.useState(false); + let isFormValid = false; const createDNSPolicy = () => { @@ -71,7 +74,11 @@ const KuadrantDNSPolicyCreatePage: React.FC = () => { healthCheck.endpoint || healthCheck.failureThreshold || healthCheck.port || - healthCheck.protocol; + healthCheck.protocol != ''; + + const hasLoadBalancing = + loadBalancing.geo || loadBalancing.defaultGeo != '' || loadBalancing.weight; + return { apiVersion: resourceGVKMapping['DNSPolicy'].group + '/' + resourceGVKMapping['DNSPolicy'].version, @@ -88,13 +95,18 @@ const KuadrantDNSPolicyCreatePage: React.FC = () => { kind: 'Gateway', name: selectedGateway.name, }, - loadBalancing: { - weight: loadBalancing.weight, - geo: loadBalancing.geo, - defaultGeo: loadBalancing.defaultGeo, - }, providerRefs: providerRefs.length > 0 ? [providerRefs[0]] : [], - + ...(hasLoadBalancing + ? { + loadBalancing: { + ...(loadBalancing?.weight ? { weight: loadBalancing.weight } : {}), + ...(loadBalancing?.geo ? { geo: loadBalancing.geo } : {}), + ...(loadBalancing.defaultGeo !== '' + ? { defaultGeo: loadBalancing.defaultGeo } + : {}), + }, + } + : {}), ...(hasHealthCheck ? { healthCheck: { @@ -256,17 +268,23 @@ const KuadrantDNSPolicyCreatePage: React.FC = () => { const handleCancelResource = () => { handleCancel(selectedNamespace, dnsPolicy, history); }; - - if ( - policyName && - selectedNamespace && - selectedGateway.name && - setProviderRefs && - loadBalancing.geo && - loadBalancing.weight - ) { - isFormValid = true; - } + const formValidation = () => { + if ( + policyName && + selectedGateway.name && + providerRefs.length > 0 && + (!loadBalancingExpanded || + (loadBalancing.geo && loadBalancing.weight && loadBalancing.defaultGeo !== '')) && + (!healthExpanded || + (healthCheck.endpoint && + healthCheck.failureThreshold > 0 && + healthCheck.port > 0 && + healthCheck.protocol !== '')) + ) { + isFormValid = true; + } + return isFormValid; + }; return ( <> @@ -313,48 +331,71 @@ const KuadrantDNSPolicyCreatePage: React.FC = () => { {createView === 'form' ? (
-
- - - - - {t('Unique name of the DNS Policy')} - - - - - - 0 ? providerRefs[0].name : ''} - onChange={handleProviderRefs} - placeholder={t('Provider Ref')} - /> - - - - - -
- + + + + + {t('Unique name of the DNS Policy')} + + + + + + 0 ? providerRefs[0].name : ''} + onChange={handleProviderRefs} + placeholder={t('Provider Ref')} + /> + + + + {t( + 'Reference to an existing secret resource containing DNS provider credentials and configuration', + )} + + + + + setLoadBalancingExpanded(!loadBalancingExpanded)} + > + + + setHealthExpanded(!healthExpanded)} + > + + +