Skip to content

Commit

Permalink
Changes related with Assisted Migration (#2691)
Browse files Browse the repository at this point in the history
  • Loading branch information
ammont82 authored Nov 6, 2024
1 parent e21935a commit 29bbfef
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
2 changes: 2 additions & 0 deletions libs/ui-lib/lib/common/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,5 @@ export const operatorLabels = (
};

export const AI_UI_TAG = 'ui_ocm';

export const AI_ASSISTED_MIGRATION_TAG = 'assisted_migration';
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useClusterWizardContext } from '../clusterWizard/ClusterWizardContext';
import DeleteCustomManifestModal from './manifestsConfiguration/DeleteCustomManifestModal';
import { ClustersService } from '../../services';
import { ClustersAPI } from '../../services/apis';
import { useLocation } from 'react-router-dom-v5-compat';

const Label = () => {
return (
Expand All @@ -37,6 +38,18 @@ const CustomManifestCheckbox = ({ clusterId, isDisabled }: CustomManifestCheckbo
const fieldId = getFieldId(name, 'input');
const clusterWizardContext = useClusterWizardContext();
const [isDeleteCustomManifestsOpen, setDeleteCustomManifestsOpen] = React.useState(false);
const location = useLocation();

React.useEffect(() => {
const searchParams = new URLSearchParams(location.search);
const isAssistedMigration = searchParams.get('source') === 'assisted_migration';

if (isAssistedMigration) {
setValue(true);
clusterWizardContext.setCustomManifestsStep(true);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [location]);

const cleanCustomManifests = React.useCallback(async () => {
const { data: manifests } = await ClustersAPI.getManifests(clusterId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { useNavigate } from 'react-router-dom-v5-compat';
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';
Expand Down Expand Up @@ -37,6 +37,7 @@ const ClusterDetails = ({ cluster, infraEnv }: ClusterDetailsProps) => {
loading: loadingOCPVersions,
latestVersions: versions,
} = useOpenshiftVersionsContext();
const location = useLocation();

const handleClusterUpdate = React.useCallback(
async (
Expand Down Expand Up @@ -72,7 +73,9 @@ const ClusterDetails = ({ cluster, infraEnv }: ClusterDetailsProps) => {
async (params: ClusterCreateParamsWithStaticNetworking, addCustomManifests: boolean) => {
clearAlerts();
try {
const cluster = await ClustersService.create(params);
const searchParams = new URLSearchParams(location.search);
const isAssistedMigration = searchParams.get('source') === 'assisted_migration';
const cluster = await ClustersService.create(params, isAssistedMigration);
navigate(`../${cluster.id}`, { state: ClusterWizardFlowStateNew });
await UISettingService.update(cluster.id, { addCustomManifests });
} catch (e) {
Expand All @@ -84,7 +87,7 @@ const ClusterDetails = ({ cluster, infraEnv }: ClusterDetailsProps) => {
}
}
},
[clearAlerts, navigate, addAlert, dispatch],
[clearAlerts, location.search, navigate, addAlert, dispatch],
);

const navigation = <ClusterWizardNavigation cluster={cluster} />;
Expand Down
7 changes: 5 additions & 2 deletions libs/ui-lib/lib/ocm/services/ClustersService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ import omit from 'lodash-es/omit.js';
import ClustersAPI from '../../common/api/assisted-service/ClustersAPI';
import HostsService from './HostsService';
import InfraEnvsService from './InfraEnvsService';
import { AI_UI_TAG } from '../../common/config/constants';
import { AI_ASSISTED_MIGRATION_TAG, AI_UI_TAG } from '../../common/config/constants';
import { isInOcm } from '../../common/api/axiosClient';

const ClustersService = {
findHost(hosts: Cluster['hosts'] = [], hostId: Host['id']) {
return hosts.find((host) => host.id === hostId);
},

async create(params: ClusterCreateParamsWithStaticNetworking) {
async create(params: ClusterCreateParamsWithStaticNetworking, isAssistedMigration?: boolean) {
if (isAssistedMigration) {
params.tags = AI_ASSISTED_MIGRATION_TAG;
}
const { data: cluster } = await ClustersAPI.register(omit(params, 'staticNetworkConfig'));
const infraEnvCreateParams: InfraEnvCreateParams = {
name: `${params.name}_infra-env`,
Expand Down

0 comments on commit 29bbfef

Please sign in to comment.