From c66d5e9828c49a14366a26c32d80c988cfb3d4bd Mon Sep 17 00:00:00 2001 From: jgyselov Date: Thu, 10 Oct 2024 14:32:55 +0200 Subject: [PATCH] Un-memoize functions --- .../common/CpuArchitectureDropdown.tsx | 35 ++++++------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/libs/ui-lib/lib/cim/components/common/CpuArchitectureDropdown.tsx b/libs/ui-lib/lib/cim/components/common/CpuArchitectureDropdown.tsx index 070249e187..286777c650 100644 --- a/libs/ui-lib/lib/cim/components/common/CpuArchitectureDropdown.tsx +++ b/libs/ui-lib/lib/cim/components/common/CpuArchitectureDropdown.tsx @@ -3,49 +3,34 @@ import { Dropdown, DropdownItem, DropdownToggle, FormGroup } from '@patternfly/r 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')} }