-
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 (#16675)
Signed-off-by: Noble Mittal <noblemittal@outlook.com>
- Loading branch information
1 parent
5d562c7
commit c768b62
Showing
5 changed files
with
234 additions
and
1 deletion.
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
89 changes: 89 additions & 0 deletions
89
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,89 @@ | ||
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; | ||
refetchWorkflows: Function; | ||
closeDialog: () => void; | ||
} | ||
|
||
const WorkflowAction: React.FC<WorkflowActionProps> = ({ | ||
isOpen, | ||
closeDialog, | ||
mutation, | ||
title, | ||
confirmText, | ||
description, | ||
successText, | ||
successBody, | ||
loadingText, | ||
errorText, | ||
refetchWorkflows, | ||
body, | ||
}) => { | ||
const onCloseDialog = () => { | ||
setTimeout(mutation.reset, 500); | ||
closeDialog(); | ||
}; | ||
|
||
const hasRun = mutation.data || mutation.error; | ||
const onConfirm = () => { | ||
mutation.mutate( | ||
{}, | ||
{ | ||
onSuccess: () => { | ||
refetchWorkflows(); | ||
}, | ||
} | ||
); | ||
}; | ||
return ( | ||
<Dialog | ||
isOpen={isOpen} | ||
confirmText={hasRun ? 'Close' : confirmText} | ||
cancelText="Cancel" | ||
onConfirm={hasRun ? onCloseDialog : onConfirm} | ||
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; |
79 changes: 79 additions & 0 deletions
79
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,79 @@ | ||
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 { | ||
refetchWorkflows: Function; | ||
keyspace: string; | ||
clusterID: string; | ||
name: string; | ||
} | ||
|
||
const WorkflowActions: React.FC<WorkflowActionsProps> = ({ refetchWorkflows, 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" | ||
confirmText="Start" | ||
loadingText="Starting" | ||
mutation={startWorkflowMutation} | ||
successText="Started workflow" | ||
errorText={`Error occured while starting workflow ${name}`} | ||
closeDialog={closeDialog} | ||
isOpen={currentDialog === 'Start Workflow'} | ||
refetchWorkflows={refetchWorkflows} | ||
successBody={ | ||
<div className="text-sm"> | ||
{startWorkflowMutation.data && startWorkflowMutation.data.summary && ( | ||
<div className="text-sm">{startWorkflowMutation.data.summary}</div> | ||
)} | ||
</div> | ||
} | ||
body={ | ||
<div className="text-sm mt-3"> | ||
Start the <span className="font-mono bg-gray-300">{name}</span> workflow. | ||
</div> | ||
} | ||
/> | ||
<WorkflowAction | ||
title="Stop Workflow" | ||
confirmText="Stop" | ||
loadingText="Stopping" | ||
mutation={stopWorkflowMutation} | ||
successText="Stopped workflow" | ||
errorText={`Error occured while stopping workflow ${name}`} | ||
closeDialog={closeDialog} | ||
isOpen={currentDialog === 'Stop Workflow'} | ||
refetchWorkflows={refetchWorkflows} | ||
successBody={ | ||
<div className="text-sm"> | ||
{stopWorkflowMutation.data && stopWorkflowMutation.data.summary && ( | ||
<div className="text-sm">{stopWorkflowMutation.data.summary}</div> | ||
)} | ||
</div> | ||
} | ||
body={ | ||
<div className="text-sm mt-3"> | ||
Stop the <span className="font-mono bg-gray-300">{name}</span> workflow. | ||
</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