Skip to content

Commit

Permalink
Finish cpuArchitecture dropdown changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jgyselov committed Sep 24, 2024
1 parent ad4e353 commit b95f2b3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const ClusterDetailsFormFields: React.FC<ClusterDetailsFormFieldsProps> =
}) => {
const { values, setFieldValue } = useFormikContext<ClusterDetailsValues>();
const { name, baseDnsDomain, highAvailabilityMode } = values;

const nameInputRef = React.useRef<HTMLInputElement>();
React.useEffect(() => {
nameInputRef.current?.focus();
Expand Down Expand Up @@ -111,7 +112,7 @@ export const ClusterDetailsFormFields: React.FC<ClusterDetailsFormFieldsProps> =
{!isNutanix && (
<>
<SNOControlGroup versions={versions} highAvailabilityMode={highAvailabilityMode} />
<CpuArchitectureDropdown />
<CpuArchitectureDropdown isDisabled={isEditFlow} />
</>
)}
{extensionAfter?.['openshiftVersion'] && extensionAfter['openshiftVersion']}
Expand Down
33 changes: 26 additions & 7 deletions libs/ui-lib/lib/cim/components/common/CpuArchitectureDropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import * as React from 'react';
import { Dropdown, DropdownItem, DropdownToggle, FormGroup } from '@patternfly/react-core';
import { useTranslation } from '../../../common/hooks/use-translation-wrapper';
import { architectureData, getFieldId, SupportedCpuArchitecture } from '../../../common';
import { useField } from 'formik';
import {
architectureData,
ClusterDetailsValues,
CpuArchitecture,
getFieldId,
StaticField,
SupportedCpuArchitecture,
} from '../../../common';
import { useField, useFormikContext } from 'formik';

const CpuArchitectureDropdown = () => {
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');
Expand All @@ -20,14 +28,21 @@ const CpuArchitectureDropdown = () => {

const onCpuArchSelect = React.useCallback(
(e?: React.SyntheticEvent<HTMLDivElement>) => {
setValue(e?.currentTarget.id as SupportedCpuArchitecture);
const val = e?.currentTarget.id as SupportedCpuArchitecture;
setValue(val);

if (val === CpuArchitecture.s390x) {
setFieldValue('userManagedNetworking', true);
} else {
setFieldValue('userManagedNetworking', false);
}
setCpuArchOpen(false);
},
[setValue],
[setValue, setFieldValue],
);

return (
<FormGroup isInline fieldId={fieldId} label={t('ai:CPU architecture')}>
return !isDisabled ? (
<FormGroup isInline fieldId={fieldId} label={t('ai:CPU architecture')} required>
<Dropdown
toggle={
<DropdownToggle onToggle={onCpuArchToggle} className="pf-u-w-100">
Expand Down Expand Up @@ -63,6 +78,10 @@ const CpuArchitectureDropdown = () => {
className="pf-u-w-100"
/>
</FormGroup>
) : (
<StaticField name={'cpuArchitecture'} label={t('ai:CPU architecture')} isRequired>
{architectureData[value].label}
</StaticField>
);
};

Expand Down
10 changes: 9 additions & 1 deletion libs/ui-lib/lib/cim/components/helpers/clusterDeployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,13 @@ export const getClusterDeploymentCpuArchitecture = (
arch = clusterDeployment.metadata?.annotations?.[CPU_ARCHITECTURE_ANNOTATION_KEY];
}

return arch === CpuArchitecture.ARM ? CpuArchitecture.ARM : CpuArchitecture.x86;
switch (arch) {
case CpuArchitecture.ARM:
return CpuArchitecture.ARM;
case CpuArchitecture.s390x:
return CpuArchitecture.s390x
default:
return CpuArchitecture.x86;
}

};
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const getClusterDetailsInitialValues = ({
diskEncryption: cluster?.diskEncryption ?? {},
cpuArchitecture: cluster?.cpuArchitecture || getDefaultCpuArchitecture(),
platform: cluster?.platform?.type || 'none',
userManagedNetworking: cluster?.userManagedNetworking || false,
};
};

Expand Down
1 change: 1 addition & 0 deletions libs/ui-lib/lib/common/components/clusterWizard/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type ClusterDetailsValues = {
diskEncryption: DiskEncryption;
cpuArchitecture: string;
platform: PlatformType;
userManagedNetworking: boolean;
};

export type HostsValidationsProps<S extends string, V extends string[]> = {
Expand Down

0 comments on commit b95f2b3

Please sign in to comment.