From 768214998baab56eb15c4d5cc5c9d3e2f7d3f4c7 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 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')} }