From 8750641cdbe4dfdc6c6b8a6bdce599def0af4caa Mon Sep 17 00:00:00 2001 From: Montse Ortega Date: Thu, 12 Dec 2024 12:06:19 +0100 Subject: [PATCH] Disable items from the dropdown depending OCP version and CPU architecture --- libs/locales/lib/en/translation.json | 1 + .../ClusterDetailsFormFields.tsx | 9 ++- .../ControlPlaneNodesDropdown.tsx | 74 ++++++++++++++----- 3 files changed, 64 insertions(+), 20 deletions(-) diff --git a/libs/locales/lib/en/translation.json b/libs/locales/lib/en/translation.json index df1c2d439c..4acf9af135 100644 --- a/libs/locales/lib/en/translation.json +++ b/libs/locales/lib/en/translation.json @@ -836,6 +836,7 @@ "ai:This IP was allocated by the DHCP server.": "This IP was allocated by the DHCP server.", "ai:This name will replace the original discovered hostname.": "This name will replace the original discovered hostname.", "ai:This option is not available for Nutanix platform": "This option is not available for Nutanix platform", + "ai:This option is not available with the current configurations. Make sure that OpenShift version is 4.18 or newer and CPU architecture is x86_64. ": "This option is not available with the current configurations. Make sure that OpenShift version is 4.18 or newer and CPU architecture is x86_64. ", "ai:This option is not editable after the draft cluster is created": "This option is not editable after the draft cluster is created", "ai:this script.": "this script.", "ai:This stage may take a while to finish. To view detailed information, click the events log link below.": "This stage might take a while to finish. To view detailed information, click the events log link.", diff --git a/libs/ui-lib/lib/cim/components/ClusterDeployment/ClusterDetailsFormFields.tsx b/libs/ui-lib/lib/cim/components/ClusterDeployment/ClusterDetailsFormFields.tsx index 2190098557..b61477656f 100644 --- a/libs/ui-lib/lib/cim/components/ClusterDeployment/ClusterDetailsFormFields.tsx +++ b/libs/ui-lib/lib/cim/components/ClusterDeployment/ClusterDetailsFormFields.tsx @@ -52,7 +52,7 @@ export const ClusterDetailsFormFields: React.FC = cpuArchitectures, }) => { const { values, setFieldValue } = useFormikContext(); - const { name, baseDnsDomain } = values; + const { name, baseDnsDomain, cpuArchitecture, openshiftVersion } = values; const nameInputRef = React.useRef(); React.useEffect(() => { @@ -110,7 +110,12 @@ export const ClusterDetailsFormFields: React.FC = }} /> )} - + {!isNutanix && ( )} diff --git a/libs/ui-lib/lib/common/components/clusterConfiguration/ControlPlaneNodesDropdown.tsx b/libs/ui-lib/lib/common/components/clusterConfiguration/ControlPlaneNodesDropdown.tsx index ea836167e1..721f73a214 100644 --- a/libs/ui-lib/lib/common/components/clusterConfiguration/ControlPlaneNodesDropdown.tsx +++ b/libs/ui-lib/lib/common/components/clusterConfiguration/ControlPlaneNodesDropdown.tsx @@ -3,41 +3,79 @@ import { Dropdown, DropdownItem, DropdownToggle, FormGroup, Tooltip } from '@pat import { useTranslation } from '../../hooks/use-translation-wrapper'; import { getFieldId, StaticField } from '../..'; import { useField } from 'formik'; +import toNumber from 'lodash-es/toNumber'; +import { TFunction } from 'react-i18next'; interface ControlPlaneNodesOption { - value: string; + value: number; label: string; } -const isDropdownItemEnabled = (controlPlaneNodeCount: string, isNutanix?: boolean): boolean => { - return (controlPlaneNodeCount === '1' && !isNutanix) || controlPlaneNodeCount !== '1'; +const isDropdownItemEnabled = ( + controlPlaneNodeCount: number, + isNutanix?: boolean, + openshiftVersion?: string, + cpuArch?: string, +): boolean => { + if (controlPlaneNodeCount === 4 || controlPlaneNodeCount === 5) { + return parseFloat(openshiftVersion || '') >= 4.18 && cpuArch === 'x86_64'; + } else if (controlPlaneNodeCount === 1) { + return !isNutanix; + } + return true; }; +const getDisabledReason = ( + controlPlaneNodeCount: number, + t: TFunction, +): string => { + if (controlPlaneNodeCount === 4 || controlPlaneNodeCount === 5) { + return t( + 'ai:This option is not available with the current configurations. Make sure that OpenShift version is 4.18 or newer and CPU architecture is x86_64. ', + ); + } else if (controlPlaneNodeCount === 1) { + return t('ai:This option is not available for Nutanix platform'); + } else { + return ''; + } +}; + +interface ControlPlaneNodesDropdownProps { + isDisabled?: boolean; + isNutanix?: boolean; + cpuArchitecture?: string; + openshiftVersion?: string; +} + const ControlPlaneNodesDropdown = ({ isDisabled = false, isNutanix, -}: { - isDisabled?: boolean; - isNutanix?: boolean; -}) => { + cpuArchitecture, + openshiftVersion, +}: ControlPlaneNodesDropdownProps) => { const { t } = useTranslation(); - const [{ name, value }, , { setValue }] = useField('controlPlaneAgents'); - const [current, setCurrent] = React.useState('3'); + const [{ name, value }, , { setValue }] = useField('controlPlaneAgents'); + const [current, setCurrent] = React.useState(3); const options: ControlPlaneNodesOption[] = [ - { value: '1', label: t('ai:1 (Single Node OpenShift - not highly available cluster)') }, - { value: '3', label: t('ai:3 (highly available cluster)') }, - { value: '4', label: t('ai:4 (highly available cluster+)') }, - { value: '5', label: t('ai:5 (highly available cluster++)') }, + { value: 1, label: t('ai:1 (Single Node OpenShift - not highly available cluster)') }, + { value: 3, label: t('ai:3 (highly available cluster)') }, + { value: 4, label: t('ai:4 (highly available cluster+)') }, + { value: 5, label: t('ai:5 (highly available cluster++)') }, ]; const dropdownItems = options.map(({ value, label }) => { - const isItemEnabled = isDropdownItemEnabled(value, isNutanix); - const disabledReason = t('ai:This option is not available for Nutanix platform'); + const isItemEnabled = isDropdownItemEnabled( + value, + isNutanix, + openshiftVersion, + cpuArchitecture, + ); + const disabledReason = getDisabledReason(value, t); return ( @@ -53,8 +91,8 @@ const ControlPlaneNodesDropdown = ({ const onControlPlaneSelect = (e?: React.SyntheticEvent) => { const val = e?.currentTarget.id as string; - setValue(val); - setCurrent(val); + setValue(toNumber(val)); + setCurrent(toNumber(val)); setControlPlanelOpen(false); };