Skip to content

Commit 536f0c4

Browse files
committed
VTAdmin(web): Refetch workflows after performing workflow actions
Signed-off-by: Noble Mittal <noblemittal@outlook.com>
1 parent 3c77866 commit 536f0c4

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

web/vtadmin/src/components/routes/Workflows.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ import { QueryLoadingPlaceholder } from '../placeholders/QueryLoadingPlaceholder
3737
import { UseQueryResult } from 'react-query';
3838
import { ReadOnlyGate } from '../ReadOnlyGate';
3939
import WorkflowActions from './workflows/WorkflowActions';
40+
import { isReadOnlyMode } from '../../util/env';
4041

4142
export const ThrottleThresholdSeconds = 60;
4243

4344
const COLUMNS = ['Workflow', 'Source', 'Target', 'Streams', 'Last Updated', 'Actions'];
45+
const READ_ONLY_COLUMNS = ['Workflow', 'Source', 'Target', 'Streams', 'Last Updated'];
4446

4547
export const Workflows = () => {
4648
useDocumentTitle('Workflows');
@@ -188,6 +190,7 @@ export const Workflows = () => {
188190
<ReadOnlyGate>
189191
<DataCell>
190192
<WorkflowActions
193+
refetchWorkflows={workflowsQuery.refetch}
191194
keyspace={row.keyspace as string}
192195
clusterID={row.clusterID as string}
193196
name={row.name as string}
@@ -212,7 +215,11 @@ export const Workflows = () => {
212215
value={filter || ''}
213216
/>
214217

215-
<DataTable columns={COLUMNS} data={sortedData} renderRows={renderRows} />
218+
<DataTable
219+
columns={isReadOnlyMode() ? READ_ONLY_COLUMNS : COLUMNS}
220+
data={sortedData}
221+
renderRows={renderRows}
222+
/>
216223

217224
<QueryLoadingPlaceholder query={workflowsQuery as UseQueryResult} />
218225
</ContentContainer>

web/vtadmin/src/components/routes/workflows/WorkflowAction.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ interface WorkflowActionProps {
1414
description?: string;
1515
body?: JSX.Element;
1616
successBody?: JSX.Element;
17+
refetchWorkflows: Function;
1718
closeDialog: () => void;
1819
}
1920

@@ -28,6 +29,7 @@ const WorkflowAction: React.FC<WorkflowActionProps> = ({
2829
successBody,
2930
loadingText,
3031
errorText,
32+
refetchWorkflows,
3133
body,
3234
}) => {
3335
const onCloseDialog = () => {
@@ -36,12 +38,22 @@ const WorkflowAction: React.FC<WorkflowActionProps> = ({
3638
};
3739

3840
const hasRun = mutation.data || mutation.error;
41+
const onConfirm = () => {
42+
mutation.mutate(
43+
{},
44+
{
45+
onSuccess: () => {
46+
refetchWorkflows();
47+
},
48+
}
49+
);
50+
};
3951
return (
4052
<Dialog
4153
isOpen={isOpen}
4254
confirmText={hasRun ? 'Close' : confirmText}
4355
cancelText="Cancel"
44-
onConfirm={hasRun ? onCloseDialog : mutation.mutate}
56+
onConfirm={hasRun ? onCloseDialog : onConfirm}
4557
loadingText={loadingText}
4658
loading={mutation.isLoading}
4759
onCancel={onCloseDialog}

web/vtadmin/src/components/routes/workflows/WorkflowActions.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import WorkflowAction from './WorkflowAction';
66
import { useStartWorkflow, useStopWorkflow } from '../../../hooks/api';
77

88
interface WorkflowActionsProps {
9+
refetchWorkflows: Function;
910
keyspace: string;
1011
clusterID: string;
1112
name: string;
1213
}
1314

14-
const WorkflowActions: React.FC<WorkflowActionsProps> = ({ keyspace, clusterID, name }) => {
15+
const WorkflowActions: React.FC<WorkflowActionsProps> = ({ refetchWorkflows, keyspace, clusterID, name }) => {
1516
const [currentDialog, setCurrentDialog] = useState<string>('');
1617
const closeDialog = () => setCurrentDialog('');
1718

@@ -27,39 +28,49 @@ const WorkflowActions: React.FC<WorkflowActionsProps> = ({ keyspace, clusterID,
2728
</Dropdown>
2829
<WorkflowAction
2930
title="Start Workflow"
30-
description={`Starts a VReplication Workflow`}
3131
confirmText="Start"
3232
loadingText="Starting"
3333
mutation={startWorkflowMutation}
3434
successText="Started workflow"
35-
errorText="Error starting workflow"
35+
errorText={`Error occured while starting workflow ${name}`}
3636
closeDialog={closeDialog}
3737
isOpen={currentDialog === 'Start Workflow'}
38+
refetchWorkflows={refetchWorkflows}
3839
successBody={
3940
<div className="text-sm">
4041
{startWorkflowMutation.data && startWorkflowMutation.data.summary && (
4142
<div className="text-sm">{startWorkflowMutation.data.summary}</div>
4243
)}
4344
</div>
4445
}
46+
body={
47+
<div className="text-sm mt-3">
48+
Starts the <span className="font-mono bg-gray-300">{name}</span> workflow.
49+
</div>
50+
}
4551
/>
4652
<WorkflowAction
4753
title="Stop Workflow"
48-
description={`Stops a VReplication Workflow`}
4954
confirmText="Stop"
50-
loadingText="Stoping"
55+
loadingText="Stopping"
5156
mutation={stopWorkflowMutation}
52-
successText="Stoped workflow"
53-
errorText="Error stoping workflow"
57+
successText="Stopped workflow"
58+
errorText={`Error occured while stopping workflow ${name}`}
5459
closeDialog={closeDialog}
5560
isOpen={currentDialog === 'Stop Workflow'}
61+
refetchWorkflows={refetchWorkflows}
5662
successBody={
5763
<div className="text-sm">
5864
{stopWorkflowMutation.data && stopWorkflowMutation.data.summary && (
5965
<div className="text-sm">{stopWorkflowMutation.data.summary}</div>
6066
)}
6167
</div>
6268
}
69+
body={
70+
<div className="text-sm mt-3">
71+
Stops the <span className="font-mono bg-gray-300">{name}</span> workflow.
72+
</div>
73+
}
6374
/>
6475
</div>
6576
);

0 commit comments

Comments
 (0)