Skip to content

Commit

Permalink
Un-memoize functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jgyselov committed Oct 10, 2024
1 parent cf079dd commit da0cbe4
Showing 1 changed file with 10 additions and 25 deletions.
35 changes: 10 additions & 25 deletions libs/ui-lib/lib/cim/components/common/CpuArchitectureDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ClusterDetailsValues>();
const [{ name, value }, , { setValue }] = useField<SupportedCpuArchitecture>('cpuArchitecture');
const [cpuArchOpen, setCpuArchOpen] = React.useState(false);
const fieldId = getFieldId(name, 'input');
const { setValue: setUserManagedNetworking } = useFormikHelpers<boolean>('userManagedNetworking');

const onCpuArchToggle = React.useCallback(() => {
if (cpuArchOpen) {
setCpuArchOpen(false);
} else {
setCpuArchOpen(true);
}
}, [cpuArchOpen]);
const onCpuArchSelect = (e?: React.SyntheticEvent<HTMLDivElement>) => {
const val = e?.currentTarget.id as SupportedCpuArchitecture;
setValue(val);
setUserManagedNetworking(val === CpuArchitecture.s390x);

const onCpuArchSelect = React.useCallback(
(e?: React.SyntheticEvent<HTMLDivElement>) => {
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 ? (
<FormGroup isInline fieldId={fieldId} label={t('ai:CPU architecture')} required>
<Dropdown
toggle={
<DropdownToggle onToggle={onCpuArchToggle} className="pf-u-w-100">
<DropdownToggle onToggle={() => setCpuArchOpen(!cpuArchOpen)} className="pf-u-w-100">
{value ? architectureData[value].label : t('ai:CPU architecture')}
</DropdownToggle>
}
Expand Down

0 comments on commit da0cbe4

Please sign in to comment.