Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

Navigate to plan page automatically when starting migration #531

Merged
2 commits merged into from Apr 7, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/app/Plans/PlansPage.tsx
Expand Up @@ -10,6 +10,7 @@ import {
} from '@patternfly/react-core';
import spacing from '@patternfly/react-styles/css/utilities/Spacing/spacing';
import { PlusCircleIcon } from '@patternfly/react-icons';
import { useHistory } from 'react-router-dom';

import {
useHasSufficientProvidersQuery,
Expand All @@ -26,12 +27,19 @@ import {
QuerySpinnerMode,
ResolvedQueries,
} from '@app/common/components/ResolvedQuery';
import { IMigration } from '@app/queries/types/migrations.types';

const PlansPage: React.FunctionComponent = () => {
const sufficientProvidersQuery = useHasSufficientProvidersQuery();
const clusterProvidersQuery = useClusterProvidersQuery();
const plansQuery = usePlansQuery();
const [createMigration, createMigrationResult] = useCreateMigrationMutation();

const history = useHistory();
const onMigrationStarted = (migration: IMigration) => {
history.push(`/plans/${migration.spec.plan.name}`);
};
const [createMigration, createMigrationResult] = useCreateMigrationMutation(onMigrationStarted);

const [setCutover, setCutoverResult] = useSetCutoverMutation();

return (
Expand Down
6 changes: 3 additions & 3 deletions src/app/queries/migrations.ts
Expand Up @@ -21,7 +21,7 @@ import { MOCK_MIGRATIONS } from './mocks/migrations.mock';
const migrationResource = new ForkliftResource(ForkliftResourceKind.Migration, META.namespace);

export const useCreateMigrationMutation = (
onSuccess?: () => void
onSuccess?: (migration: IMigration) => void
): MutationResultPair<IKubeResponse<IMigration>, KubeClientError, IPlan, unknown> => {
const client = useAuthorizedK8sClient();
const queryCache = useQueryCache();
Expand Down Expand Up @@ -49,11 +49,11 @@ export const useCreateMigrationMutation = (
return await client.create(migrationResource, migration);
},
{
onSuccess: () => {
onSuccess: ({ data }) => {
queryCache.invalidateQueries('plans');
queryCache.invalidateQueries('migrations');
pollFasterAfterMutation();
onSuccess && onSuccess();
onSuccess && onSuccess(data);
},
}
);
Expand Down