-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VTAdmin(web): Add workflow start/stop actions
Signed-off-by: Noble Mittal <[email protected]>
- Loading branch information
1 parent
639b1de
commit 3c77866
Showing
5 changed files
with
208 additions
and
5 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
77 changes: 77 additions & 0 deletions
77
web/vtadmin/src/components/routes/workflows/WorkflowAction.tsx
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,77 @@ | ||
import React from 'react'; | ||
import { Icon, Icons } from '../../Icon'; | ||
import Dialog from '../../dialog/Dialog'; | ||
import { UseMutationResult } from 'react-query'; | ||
|
||
interface WorkflowActionProps { | ||
isOpen: boolean; | ||
mutation: UseMutationResult<any, any, any>; | ||
title: string; | ||
confirmText: string; | ||
successText: string; | ||
errorText: string; | ||
loadingText: string; | ||
description?: string; | ||
body?: JSX.Element; | ||
successBody?: JSX.Element; | ||
closeDialog: () => void; | ||
} | ||
|
||
const WorkflowAction: React.FC<WorkflowActionProps> = ({ | ||
isOpen, | ||
closeDialog, | ||
mutation, | ||
title, | ||
confirmText, | ||
description, | ||
successText, | ||
successBody, | ||
loadingText, | ||
errorText, | ||
body, | ||
}) => { | ||
const onCloseDialog = () => { | ||
setTimeout(mutation.reset, 500); | ||
closeDialog(); | ||
}; | ||
|
||
const hasRun = mutation.data || mutation.error; | ||
return ( | ||
<Dialog | ||
isOpen={isOpen} | ||
confirmText={hasRun ? 'Close' : confirmText} | ||
cancelText="Cancel" | ||
onConfirm={hasRun ? onCloseDialog : mutation.mutate} | ||
loadingText={loadingText} | ||
loading={mutation.isLoading} | ||
onCancel={onCloseDialog} | ||
onClose={onCloseDialog} | ||
hideCancel={hasRun} | ||
title={hasRun ? undefined : title} | ||
description={hasRun ? undefined : description} | ||
> | ||
<div className="w-full"> | ||
{!hasRun && body} | ||
{mutation.data && !mutation.error && ( | ||
<div className="w-full flex flex-col justify-center items-center"> | ||
<span className="flex h-12 w-12 relative items-center justify-center"> | ||
<Icon className="fill-current text-green-500" icon={Icons.checkSuccess} /> | ||
</span> | ||
<div className="text-lg mt-3 font-bold text-center">{successText}</div> | ||
{successBody} | ||
</div> | ||
)} | ||
{mutation.error && ( | ||
<div className="w-full flex flex-col justify-center items-center"> | ||
<span className="flex h-12 w-12 relative items-center justify-center"> | ||
<Icon className="fill-current text-red-500" icon={Icons.alertFail} /> | ||
</span> | ||
<div className="text-lg mt-3 font-bold text-center">{errorText}</div> | ||
</div> | ||
)} | ||
</div> | ||
</Dialog> | ||
); | ||
}; | ||
|
||
export default WorkflowAction; |
68 changes: 68 additions & 0 deletions
68
web/vtadmin/src/components/routes/workflows/WorkflowActions.tsx
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,68 @@ | ||
import React, { useState } from 'react'; | ||
import Dropdown from '../../dropdown/Dropdown'; | ||
import MenuItem from '../../dropdown/MenuItem'; | ||
import { Icons } from '../../Icon'; | ||
import WorkflowAction from './WorkflowAction'; | ||
import { useStartWorkflow, useStopWorkflow } from '../../../hooks/api'; | ||
|
||
interface WorkflowActionsProps { | ||
keyspace: string; | ||
clusterID: string; | ||
name: string; | ||
} | ||
|
||
const WorkflowActions: React.FC<WorkflowActionsProps> = ({ keyspace, clusterID, name }) => { | ||
const [currentDialog, setCurrentDialog] = useState<string>(''); | ||
const closeDialog = () => setCurrentDialog(''); | ||
|
||
const startWorkflowMutation = useStartWorkflow({ keyspace, clusterID, name }); | ||
|
||
const stopWorkflowMutation = useStopWorkflow({ keyspace, clusterID, name }); | ||
|
||
return ( | ||
<div className="w-min inline-block"> | ||
<Dropdown dropdownButton={Icons.info} position="bottom-right"> | ||
<MenuItem onClick={() => setCurrentDialog('Start Workflow')}>Start Workflow</MenuItem> | ||
<MenuItem onClick={() => setCurrentDialog('Stop Workflow')}>Stop Workflow</MenuItem> | ||
</Dropdown> | ||
<WorkflowAction | ||
title="Start Workflow" | ||
description={`Starts a VReplication Workflow`} | ||
confirmText="Start" | ||
loadingText="Starting" | ||
mutation={startWorkflowMutation} | ||
successText="Started workflow" | ||
errorText="Error starting workflow" | ||
closeDialog={closeDialog} | ||
isOpen={currentDialog === 'Start Workflow'} | ||
successBody={ | ||
<div className="text-sm"> | ||
{startWorkflowMutation.data && startWorkflowMutation.data.summary && ( | ||
<div className="text-sm">{startWorkflowMutation.data.summary}</div> | ||
)} | ||
</div> | ||
} | ||
/> | ||
<WorkflowAction | ||
title="Stop Workflow" | ||
description={`Stops a VReplication Workflow`} | ||
confirmText="Stop" | ||
loadingText="Stoping" | ||
mutation={stopWorkflowMutation} | ||
successText="Stoped workflow" | ||
errorText="Error stoping workflow" | ||
closeDialog={closeDialog} | ||
isOpen={currentDialog === 'Stop Workflow'} | ||
successBody={ | ||
<div className="text-sm"> | ||
{stopWorkflowMutation.data && stopWorkflowMutation.data.summary && ( | ||
<div className="text-sm">{stopWorkflowMutation.data.summary}</div> | ||
)} | ||
</div> | ||
} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default WorkflowActions; |
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