This repository has been archived by the owner on Jan 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Track migrate/cutover request state locally to the button instead of …
…at the plans page level (#537)
- Loading branch information
Showing
3 changed files
with
89 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<HTMLDivElement>; | ||
} | ||
|
||
const MigrateOrCutoverButton: React.FunctionComponent<IMigrateOrCutoverButtonProps> = ({ | ||
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 <Spinner size="md" className={spacing.mxLg} />; | ||
} | ||
return ( | ||
<> | ||
<Button | ||
variant="secondary" | ||
onClick={() => { | ||
if (buttonType === 'Start' || buttonType === 'Restart') { | ||
createMigration(plan); | ||
} else if (buttonType === 'Cutover') { | ||
setCutover({ plan, cutover: new Date().toISOString() }); | ||
} | ||
}} | ||
> | ||
{buttonType} | ||
</Button> | ||
{(createMigrationResult.isError || setCutoverResult.isError) && errorContainerRef.current | ||
? createPortal( | ||
<> | ||
<ResolvedQuery | ||
result={createMigrationResult} | ||
errorTitle="Error starting migration" | ||
errorsInline={false} | ||
spinnerMode={QuerySpinnerMode.None} | ||
className={spacing.mbMd} | ||
/> | ||
<ResolvedQuery | ||
result={setCutoverResult} | ||
errorTitle="Error setting cutover time" | ||
errorsInline={false} | ||
spinnerMode={QuerySpinnerMode.None} | ||
className={spacing.mbMd} | ||
/> | ||
</>, | ||
errorContainerRef.current | ||
) | ||
: null} | ||
</> | ||
); | ||
}; | ||
|
||
export default MigrateOrCutoverButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters