Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import {
} from '@patternfly/react-core';
import { AgentClusterInstallK8sResource, ClusterDeploymentK8sResource, OsImage } from '../../types';
import { ClusterImageSetK8sResource } from '../../types/k8s/cluster-image-set';
import { getOCPVersions, getSelectedVersion } from '../helpers';
import { getOCPVersions } from '../helpers';
import { useTranslation } from '../../../common/hooks/use-translation-wrapper';

import {
ClusterDetailsFormFields,
ClusterDetailsFormFieldsProps,
Expand All @@ -38,17 +39,14 @@ export const ClusterDeploymentDetailsFormWrapper = ({
}) => {
const { activeStep, goToPrevStep, goToNextStep, close } = useWizardContext();
const { syncError } = React.useContext(ClusterDeploymentWizardContext);
const { submitForm, isSubmitting, isValid, isValidating, dirty } =
useFormikContext<ClusterDetailsValues>();
const { isSubmitting, isValid, isValidating } = useFormikContext<ClusterDetailsValues>();
const { t } = useTranslation();

// ClusterDeploymentDetailsFormWrapper is exclusively used by ClusterDeploymentWizard (edit flow).
// No form submission needed here—just navigate to the next step.
const handleOnNext = React.useCallback(() => {
if (dirty) {
void submitForm();
} else {
void goToNextStep();
}
}, [dirty, goToNextStep, submitForm]);
void goToNextStep();
}, [goToNextStep]);

const footer = React.useMemo(
() => (
Expand Down Expand Up @@ -84,8 +82,7 @@ export const ClusterDeploymentDetailsFormWrapper = ({
);
};

const ClusterDeploymentDetailsForm: React.FC<ClusterDeploymentDetailsFormProps> = ({
agentClusterInstall,
export const ClusterDeploymentDetailsForm: React.FC<ClusterDeploymentDetailsFormProps> = ({
clusterDeployment,
clusterImages,
extensionAfter,
Expand All @@ -103,26 +100,21 @@ const ClusterDeploymentDetailsForm: React.FC<ClusterDeploymentDetailsFormProps>
[clusterImages, isNutanix, osImages],
);

const forceOpenshiftVersion = agentClusterInstall
? getSelectedVersion(clusterImages, agentClusterInstall)
: undefined;
const isEditFlow = !!clusterDeployment;

const { values } = useFormikContext<ClusterDetailsValues>();

const [cpuArchitectures, allowHighlyAvailable] = React.useMemo(() => {
const cpuArchitectures = [CpuArchitecture.x86, CpuArchitecture.ARM, CpuArchitecture.s390x];
const version = allVersions.find(
(ver) => ver.value === values.openshiftVersion || ver.version === forceOpenshiftVersion,
);
const version = allVersions.find((ver) => ver.value === values.openshiftVersion);
const isMulti = version?.cpuArchitectures?.[0] === CpuArchitecture.MULTI;

const highlyAvailableSupported = toNumber(version?.version?.split('.')?.[1]) >= 18;
return [
(isMulti ? cpuArchitectures : version?.cpuArchitectures) as SupportedCpuArchitecture[],
highlyAvailableSupported && !isMulti,
];
}, [allVersions, forceOpenshiftVersion, values.openshiftVersion]);
}, [allVersions, values.openshiftVersion]);

return (
<>
Expand All @@ -140,7 +132,6 @@ const ClusterDeploymentDetailsForm: React.FC<ClusterDeploymentDetailsFormProps>
versions={versions}
allVersions={allVersions}
isEditFlow={isEditFlow}
forceOpenshiftVersion={forceOpenshiftVersion}
extensionAfter={extensionAfter}
isNutanix={isNutanix}
cpuArchitectures={cpuArchitectures}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { getNetworkType } from '../helpers';

export type ClusterDetailsFormFieldsProps = {
isEditFlow: boolean;
forceOpenshiftVersion?: string;
extensionAfter?: { [key: string]: React.ReactElement };
versions: OpenshiftVersionOptionType[];
allVersions: OpenshiftVersionOptionType[];
Expand Down Expand Up @@ -50,7 +49,6 @@ export const ClusterDetailsFormFields: React.FC<ClusterDetailsFormFieldsProps> =
isEditFlow,
versions,
allVersions,
forceOpenshiftVersion,
extensionAfter,
isNutanix,
cpuArchitectures,
Expand All @@ -63,7 +61,7 @@ export const ClusterDetailsFormFields: React.FC<ClusterDetailsFormFieldsProps> =
const { name, baseDnsDomain } = values;

React.useEffect(() => {
if (!versions.length && !values.openshiftVersion) {
if (!versions.length && !values.openshiftVersion && !isEditFlow) {
const fallbackOpenShiftVersion = allVersions.find((version) => version.default);
setFieldValue('customOpenshiftSelect', fallbackOpenShiftVersion);
setFieldValue('openshiftVersion', fallbackOpenShiftVersion?.value);
Expand Down Expand Up @@ -138,9 +136,11 @@ export const ClusterDetailsFormFields: React.FC<ClusterDetailsFormFieldsProps> =
isRequired
/>
)}
{forceOpenshiftVersion ? (
{isEditFlow ? (
<StaticTextField name="openshiftVersion" label="OpenShift version" isRequired>
{t('ai:OpenShift')} {forceOpenshiftVersion}
{t('ai:OpenShift')}{' '}
{allVersions.find((v) => v.value === values.openshiftVersion)?.version ||
values.openshiftVersion}
</StaticTextField>
) : (
<>
Expand Down
Loading