diff --git a/src/app/Plans/PlansPage.tsx b/src/app/Plans/PlansPage.tsx index 62c6a7bdd..fc6d1d637 100644 --- a/src/app/Plans/PlansPage.tsx +++ b/src/app/Plans/PlansPage.tsx @@ -10,37 +10,23 @@ 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, usePlansQuery, - useCreateMigrationMutation, useClusterProvidersQuery, - useSetCutoverMutation, } from '@app/queries'; import PlansTable from './components/PlansTable'; import CreatePlanButton from './components/CreatePlanButton'; -import { - ResolvedQuery, - QuerySpinnerMode, - ResolvedQueries, -} from '@app/common/components/ResolvedQuery'; -import { IMigration } from '@app/queries/types/migrations.types'; +import { ResolvedQueries } from '@app/common/components/ResolvedQuery'; const PlansPage: React.FunctionComponent = () => { const sufficientProvidersQuery = useHasSufficientProvidersQuery(); const clusterProvidersQuery = useClusterProvidersQuery(); const plansQuery = usePlansQuery(); - const history = useHistory(); - const onMigrationStarted = (migration: IMigration) => { - history.push(`/plans/${migration.spec.plan.name}`); - }; - const [createMigration, createMigrationResult] = useCreateMigrationMutation(onMigrationStarted); - - const [setCutover, setCutoverResult] = useSetCutoverMutation(); + const errorContainerRef = React.useRef(null); return ( <> @@ -48,20 +34,7 @@ const PlansPage: React.FunctionComponent = () => { Migration plans - - +
{ ) : ( )} diff --git a/src/app/Plans/components/MigrateOrCutoverButton.tsx b/src/app/Plans/components/MigrateOrCutoverButton.tsx new file mode 100644 index 000000000..3c4d6b689 --- /dev/null +++ b/src/app/Plans/components/MigrateOrCutoverButton.tsx @@ -0,0 +1,73 @@ +import * as React from 'react'; +import { createPortal } from 'react-dom'; +import { useHistory } from 'react-router-dom'; +import { Button, Spinner } from '@patternfly/react-core'; +import spacing from '@patternfly/react-styles/css/utilities/Spacing/spacing'; +import { useCreateMigrationMutation, useSetCutoverMutation } from '@app/queries'; +import { IMigration } from '@app/queries/types/migrations.types'; +import { IPlan } from '@app/queries/types'; +import { PlanActionButtonType } from './PlansTable'; +import { ResolvedQuery, QuerySpinnerMode } from '@app/common/components/ResolvedQuery'; + +interface IMigrateOrCutoverButtonProps { + plan: IPlan; + buttonType: PlanActionButtonType; + isBeingStarted: boolean; + errorContainerRef: React.RefObject; +} + +const MigrateOrCutoverButton: React.FunctionComponent = ({ + plan, + buttonType, + isBeingStarted, + errorContainerRef, +}: IMigrateOrCutoverButtonProps) => { + const history = useHistory(); + const onMigrationStarted = (migration: IMigration) => { + history.push(`/plans/${migration.spec.plan.name}`); + }; + const [createMigration, createMigrationResult] = useCreateMigrationMutation(onMigrationStarted); + const [setCutover, setCutoverResult] = useSetCutoverMutation(); + if (isBeingStarted || createMigrationResult.isLoading || setCutoverResult.isLoading) { + return ; + } + return ( + <> + + {(createMigrationResult.isError || setCutoverResult.isError) && errorContainerRef.current + ? createPortal( + <> + + + , + errorContainerRef.current + ) + : null} + + ); +}; + +export default MigrateOrCutoverButton; diff --git a/src/app/Plans/components/PlansTable.tsx b/src/app/Plans/components/PlansTable.tsx index 06118d725..5087f6027 100644 --- a/src/app/Plans/components/PlansTable.tsx +++ b/src/app/Plans/components/PlansTable.tsx @@ -1,6 +1,5 @@ import * as React from 'react'; import { - Button, Flex, FlexItem, Level, @@ -9,7 +8,6 @@ import { Progress, ProgressMeasureLocation, ProgressVariant, - Spinner, Text, Tooltip, } from '@patternfly/react-core'; @@ -30,7 +28,6 @@ import { Th, Tr, } from '@patternfly/react-table'; -import spacing from '@patternfly/react-styles/css/utilities/Spacing/spacing'; import alignment from '@patternfly/react-styles/css/utilities/Alignment/alignment'; import { Link } from 'react-router-dom'; import { useSelectionState } from '@konveyor/lib-ui'; @@ -47,15 +44,11 @@ import TableEmptyState from '@app/common/components/TableEmptyState'; import { findLatestMigration, findProvidersByRefs, - ISetCutoverArgs, useInventoryProvidersQuery, useMigrationsQuery, } from '@app/queries'; import './PlansTable.css'; -import { IKubeResponse, KubeClientError } from '@app/client/types'; -import { IMigration } from '@app/queries/types/migrations.types'; -import { MutateFunction, MutationResult } from 'react-query'; import { canPlanBeStarted, getPlanStatusTitle, @@ -64,21 +57,18 @@ import { } from './helpers'; import { isSameResource } from '@app/queries/helpers'; import StatusCondition from '@app/common/components/StatusCondition'; +import MigrateOrCutoverButton from './MigrateOrCutoverButton'; + +export type PlanActionButtonType = 'Start' | 'Restart' | 'Cutover'; interface IPlansTableProps { plans: IPlan[]; - createMigration: MutateFunction, KubeClientError, IPlan>; - createMigrationResult: MutationResult, KubeClientError>; - setCutover: MutateFunction, KubeClientError, ISetCutoverArgs, unknown>; - setCutoverResult: MutationResult, KubeClientError>; + errorContainerRef: React.RefObject; } const PlansTable: React.FunctionComponent = ({ plans, - createMigration, - createMigrationResult, - setCutover, - setCutoverResult, + errorContainerRef, }: IPlansTableProps) => { const providersQuery = useInventoryProvidersQuery(); const migrationsQuery = useMigrationsQuery(); @@ -196,10 +186,8 @@ const PlansTable: React.FunctionComponent = ({ const rows: IRow[] = []; - type ActionButtonType = 'Start' | 'Restart' | 'Cutover'; - currentPageItems.forEach((plan: IPlan) => { - let buttonType: ActionButtonType | null = null; + let buttonType: PlanActionButtonType | null = null; let title = ''; let variant: ProgressVariant | undefined; @@ -302,23 +290,12 @@ const PlansTable: React.FunctionComponent = ({ flexWrap={{ default: 'nowrap' }} > - {isBeingStarted ? ( - - ) : ( - - )} +