diff --git a/libs/ui-lib/lib/cim/components/common/CpuArchitectureDropdown.tsx b/libs/ui-lib/lib/cim/components/common/CpuArchitectureDropdown.tsx index f1227f649a..c25e7df4d9 100644 --- a/libs/ui-lib/lib/cim/components/common/CpuArchitectureDropdown.tsx +++ b/libs/ui-lib/lib/cim/components/common/CpuArchitectureDropdown.tsx @@ -4,49 +4,34 @@ import { Dropdown, DropdownItem, DropdownToggle } from '@patternfly/react-core/d import { useTranslation } from '../../../common/hooks/use-translation-wrapper'; import { architectureData, - ClusterDetailsValues, CpuArchitecture, getFieldId, StaticField, SupportedCpuArchitecture, } from '../../../common'; -import { useField, useFormikContext } from 'formik'; +import { useField } from 'formik'; +import { useFormikHelpers } from '../../../common/hooks/useFormikHelpers'; 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'); + const { setValue: setUserManagedNetworking } = useFormikHelpers('userManagedNetworking'); - const onCpuArchToggle = React.useCallback(() => { - if (cpuArchOpen) { - setCpuArchOpen(false); - } else { - setCpuArchOpen(true); - } - }, [cpuArchOpen]); + const onCpuArchSelect = (e?: React.SyntheticEvent) => { + const val = e?.currentTarget.id as SupportedCpuArchitecture; + setValue(val); + setUserManagedNetworking(val === CpuArchitecture.s390x); - const onCpuArchSelect = React.useCallback( - (e?: React.SyntheticEvent) => { - const val = e?.currentTarget.id as SupportedCpuArchitecture; - setValue(val); - - if (val === CpuArchitecture.s390x) { - setFieldValue('userManagedNetworking', true); - } else { - setFieldValue('userManagedNetworking', false); - } - setCpuArchOpen(false); - }, - [setValue, setFieldValue], - ); + setCpuArchOpen(false); + }; return !isDisabled ? ( + setCpuArchOpen(!cpuArchOpen)} className="pf-u-w-100"> {value ? architectureData[value].label : t('ai:CPU architecture')} }