From b95f2b38a4d65a005412e6f9d24c0700632a456f Mon Sep 17 00:00:00 2001 From: jgyselov Date: Tue, 24 Sep 2024 14:32:45 +0200 Subject: [PATCH] Finish cpuArchitecture dropdown changes --- .../ClusterDetailsFormFields.tsx | 3 +- .../common/CpuArchitectureDropdown.tsx | 33 +++++++++++++++---- .../components/helpers/clusterDeployment.ts | 10 +++++- .../clusterWizard/clusterDetailsValidation.ts | 1 + .../common/components/clusterWizard/types.ts | 1 + 5 files changed, 39 insertions(+), 9 deletions(-) diff --git a/libs/ui-lib/lib/cim/components/ClusterDeployment/ClusterDetailsFormFields.tsx b/libs/ui-lib/lib/cim/components/ClusterDeployment/ClusterDetailsFormFields.tsx index 1ab8fcc61f..45f722b334 100644 --- a/libs/ui-lib/lib/cim/components/ClusterDeployment/ClusterDetailsFormFields.tsx +++ b/libs/ui-lib/lib/cim/components/ClusterDeployment/ClusterDetailsFormFields.tsx @@ -52,6 +52,7 @@ export const ClusterDetailsFormFields: React.FC = }) => { const { values, setFieldValue } = useFormikContext(); const { name, baseDnsDomain, highAvailabilityMode } = values; + const nameInputRef = React.useRef(); React.useEffect(() => { nameInputRef.current?.focus(); @@ -111,7 +112,7 @@ export const ClusterDetailsFormFields: React.FC = {!isNutanix && ( <> - + )} {extensionAfter?.['openshiftVersion'] && extensionAfter['openshiftVersion']} diff --git a/libs/ui-lib/lib/cim/components/common/CpuArchitectureDropdown.tsx b/libs/ui-lib/lib/cim/components/common/CpuArchitectureDropdown.tsx index 41690b144c..070249e187 100644 --- a/libs/ui-lib/lib/cim/components/common/CpuArchitectureDropdown.tsx +++ b/libs/ui-lib/lib/cim/components/common/CpuArchitectureDropdown.tsx @@ -1,11 +1,19 @@ import * as React from 'react'; import { Dropdown, DropdownItem, DropdownToggle, FormGroup } from '@patternfly/react-core'; import { useTranslation } from '../../../common/hooks/use-translation-wrapper'; -import { architectureData, getFieldId, SupportedCpuArchitecture } from '../../../common'; -import { useField } from 'formik'; +import { + architectureData, + ClusterDetailsValues, + CpuArchitecture, + getFieldId, + StaticField, + SupportedCpuArchitecture, +} from '../../../common'; +import { useField, useFormikContext } from 'formik'; -const CpuArchitectureDropdown = () => { +const CpuArchitectureDropdown = ({ isDisabled = false }: { isDisabled?: boolean }) => { const { t } = useTranslation(); + const { setFieldValue } = useFormikContext(); const [{ name, value }, , { setValue }] = useField('cpuArchitecture'); const [cpuArchOpen, setCpuArchOpen] = React.useState(false); const fieldId = getFieldId(name, 'input'); @@ -20,14 +28,21 @@ const CpuArchitectureDropdown = () => { const onCpuArchSelect = React.useCallback( (e?: React.SyntheticEvent) => { - setValue(e?.currentTarget.id as SupportedCpuArchitecture); + const val = e?.currentTarget.id as SupportedCpuArchitecture; + setValue(val); + + if (val === CpuArchitecture.s390x) { + setFieldValue('userManagedNetworking', true); + } else { + setFieldValue('userManagedNetworking', false); + } setCpuArchOpen(false); }, - [setValue], + [setValue, setFieldValue], ); - return ( - + return !isDisabled ? ( + @@ -63,6 +78,10 @@ const CpuArchitectureDropdown = () => { className="pf-u-w-100" /> + ) : ( + + {architectureData[value].label} + ); }; diff --git a/libs/ui-lib/lib/cim/components/helpers/clusterDeployment.ts b/libs/ui-lib/lib/cim/components/helpers/clusterDeployment.ts index bf64e39f98..1e9a36a110 100644 --- a/libs/ui-lib/lib/cim/components/helpers/clusterDeployment.ts +++ b/libs/ui-lib/lib/cim/components/helpers/clusterDeployment.ts @@ -234,5 +234,13 @@ export const getClusterDeploymentCpuArchitecture = ( arch = clusterDeployment.metadata?.annotations?.[CPU_ARCHITECTURE_ANNOTATION_KEY]; } - return arch === CpuArchitecture.ARM ? CpuArchitecture.ARM : CpuArchitecture.x86; + switch (arch) { + case CpuArchitecture.ARM: + return CpuArchitecture.ARM; + case CpuArchitecture.s390x: + return CpuArchitecture.s390x + default: + return CpuArchitecture.x86; + } + }; diff --git a/libs/ui-lib/lib/common/components/clusterWizard/clusterDetailsValidation.ts b/libs/ui-lib/lib/common/components/clusterWizard/clusterDetailsValidation.ts index dde1da3de0..4bc2d27f39 100644 --- a/libs/ui-lib/lib/common/components/clusterWizard/clusterDetailsValidation.ts +++ b/libs/ui-lib/lib/common/components/clusterWizard/clusterDetailsValidation.ts @@ -76,6 +76,7 @@ export const getClusterDetailsInitialValues = ({ diskEncryption: cluster?.diskEncryption ?? {}, cpuArchitecture: cluster?.cpuArchitecture || getDefaultCpuArchitecture(), platform: cluster?.platform?.type || 'none', + userManagedNetworking: cluster?.userManagedNetworking || false, }; }; diff --git a/libs/ui-lib/lib/common/components/clusterWizard/types.ts b/libs/ui-lib/lib/common/components/clusterWizard/types.ts index 5a89e7634b..471ac077e2 100644 --- a/libs/ui-lib/lib/common/components/clusterWizard/types.ts +++ b/libs/ui-lib/lib/common/components/clusterWizard/types.ts @@ -31,6 +31,7 @@ export type ClusterDetailsValues = { diskEncryption: DiskEncryption; cpuArchitecture: string; platform: PlatformType; + userManagedNetworking: boolean; }; export type HostsValidationsProps = {