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
30 changes: 2 additions & 28 deletions libs/ui-lib/lib/ocm/components/clusterWizard/ClusterDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import { useLocation, useNavigate } from 'react-router-dom-v5-compat';
import { useDispatch } from 'react-redux';
import { useAlerts, LoadingState, ClusterWizardStep, ErrorState } from '../../../common';
import { usePullSecret } from '../../hooks';
import {
ClustersAPI,
getApiErrorMessage,
handleApiError,
isUnknownServerError,
} from '../../../common/api';
import { getApiErrorMessage, handleApiError, isUnknownServerError } from '../../../common/api';
import { setServerUpdateError, updateCluster } from '../../store/slices/current-cluster/slice';
import { useClusterWizardContext } from './ClusterWizardContext';
import { canNextClusterDetails, ClusterWizardFlowStateNew } from './wizardTransition';
Expand All @@ -23,7 +18,6 @@ import {
UISettingService,
} from '../../services';
import { Cluster, InfraEnv } from '@openshift-assisted/types/assisted-installer-service';
import { useFeature } from '../../hooks/use-feature';

type ClusterDetailsProps = {
cluster?: Cluster;
Expand All @@ -44,7 +38,6 @@ const ClusterDetails = ({ cluster, infraEnv }: ClusterDetailsProps) => {
latestVersions: versions,
} = useOpenShiftVersionsContext();
const location = useLocation();
const isSingleClusterFeatureEnabled = useFeature('ASSISTED_INSTALLER_SINGLE_CLUSTER_FEATURE');

const handleClusterUpdate = React.useCallback(
async (
Expand Down Expand Up @@ -83,25 +76,6 @@ const ClusterDetails = ({ cluster, infraEnv }: ClusterDetailsProps) => {
const searchParams = new URLSearchParams(location.search);
const isAssistedMigration = searchParams.get('source') === 'assisted_migration';
const cluster = await ClustersService.create(params, isAssistedMigration);
if (isSingleClusterFeatureEnabled) {
try {
await ClustersAPI.updateInstallConfig(
cluster.id,
JSON.stringify(JSON.stringify({ featureSet: 'TechPreviewNoUpgrade' })),
);
} catch (e) {
handleApiError(e, () =>
addAlert({
title: 'Failed to update install-config',
message: getApiErrorMessage(e),
}),
);
if (isUnknownServerError(e as Error)) {
dispatch(setServerUpdateError());
}
return;
}
}
navigate(`../${cluster.id}`, { state: ClusterWizardFlowStateNew });
await UISettingService.update(cluster.id, { addCustomManifests });
//TO-DO: Assisted-Migration. Provisional code. Needs to be removed when MTV integration be finished
Expand All @@ -117,7 +91,7 @@ const ClusterDetails = ({ cluster, infraEnv }: ClusterDetailsProps) => {
}
}
},
[clearAlerts, location.search, navigate, addAlert, dispatch, isSingleClusterFeatureEnabled],
[clearAlerts, location.search, navigate, addAlert, dispatch],
);

const navigation = <ClusterWizardNavigation cluster={cluster} />;
Expand Down
30 changes: 29 additions & 1 deletion libs/ui-lib/lib/ocm/components/clusterWizard/HostDiscovery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
useAlerts,
getHostDiscoveryInitialValues,
useFormikAutoSave,
ClustersAPI,
} from '../../../common';
import HostInventory from '../clusterConfiguration/HostInventory';
import { useClusterWizardContext } from './ClusterWizardContext';
Expand All @@ -22,13 +23,17 @@ import {
Cluster,
V2ClusterUpdateParams,
} from '@openshift-assisted/types/assisted-installer-service';
import { useFeature } from '../../hooks/use-feature';

const HostDiscoveryForm = ({ cluster }: { cluster: Cluster }) => {
const { alerts } = useAlerts();
const { errors, touched, isSubmitting, isValid } = useFormikContext<HostDiscoveryValues>();
const clusterWizardContext = useClusterWizardContext();
const isAutoSaveRunning = useFormikAutoSave();
const errorFields = getFormikErrorFields(errors, touched);
const isSingleClusterFeatureEnabled = useFeature('ASSISTED_INSTALLER_SINGLE_CLUSTER_FEATURE');
const { addAlert } = useAlerts();
const dispatch = useDispatch();

const isNextDisabled =
!isValid ||
Expand All @@ -37,13 +42,36 @@ const HostDiscoveryForm = ({ cluster }: { cluster: Cluster }) => {
isSubmitting ||
!canNextHostDiscovery({ cluster });

const onNext = React.useCallback(async () => {
if (isSingleClusterFeatureEnabled) {
try {
await ClustersAPI.updateInstallConfig(
cluster.id,
JSON.stringify(JSON.stringify({ featureSet: 'TechPreviewNoUpgrade' })),
);
} catch (e) {
handleApiError(e, () =>
addAlert({
title: 'Failed to update install-config',
message: getApiErrorMessage(e),
}),
);
if (isUnknownServerError(e as Error)) {
dispatch(setServerUpdateError());
}
return;
}
}
clusterWizardContext.moveNext();
}, [addAlert, cluster.id, clusterWizardContext, dispatch, isSingleClusterFeatureEnabled]);

const footer = (
<ClusterWizardFooter
cluster={cluster}
errorFields={errorFields}
isSubmitting={isSubmitting}
isNextDisabled={isNextDisabled}
onNext={() => clusterWizardContext.moveNext()}
onNext={() => void onNext()}
onBack={() => clusterWizardContext.moveBack()}
isBackDisabled={isSubmitting || isAutoSaveRunning}
/>
Expand Down
Loading