Skip to content

Commit b8f3d7b

Browse files
committed
fix: implement stopping workflows before deletion
1 parent cdaff6a commit b8f3d7b

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

src/components/TerminateWorkflowButton.tsx renamed to src/components/DeleteWorkflowButton.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
getGetRunningWorkflowQueryKey,
44
getGetRunningWorkflowsQueryKey,
55
useDeleteRunningWorkflow,
6+
useStopRunningWorkflow,
67
} from "@squonk/data-manager-client/workflow";
78

89
import { Button } from "@mui/material";
@@ -12,47 +13,47 @@ import { WORKFLOW_DONE_PHASES } from "../constants/results";
1213
import { useEnqueueError } from "../hooks/useEnqueueStackError";
1314
import { WarningDeleteButton } from "./WarningDeleteButton";
1415

15-
interface TerminateWorkflowButtonProps {
16+
interface DeleteWorkflowButtonProps {
1617
runningWorkflowId: string;
1718
status?: RunningWorkflowGetResponseStatus;
1819
disabled?: boolean;
1920
}
2021

21-
export const TerminateWorkflowButton = ({
22+
export const DeleteWorkflowButton = ({
2223
runningWorkflowId,
2324
status,
2425
disabled = false,
25-
}: TerminateWorkflowButtonProps) => {
26+
}: DeleteWorkflowButtonProps) => {
2627
const queryClient = useQueryClient();
2728
const { mutateAsync: deleteWorkflow } = useDeleteRunningWorkflow();
29+
const { mutateAsync: stopWorkflow } = useStopRunningWorkflow();
2830
const { enqueueError, enqueueSnackbar } = useEnqueueError();
2931

3032
const done = WORKFLOW_DONE_PHASES.includes(status ?? RunningWorkflowGetResponseStatus.RUNNING);
3133

32-
const verb = done ? "Delete" : "Terminate";
34+
const verb = done ? "Delete" : "Stop";
3335

34-
const handleTerminate = async () => {
36+
const handleClick = async () => {
3537
try {
36-
await deleteWorkflow({ runningWorkflowId });
38+
await (done ? deleteWorkflow({ runningWorkflowId }) : stopWorkflow({ runningWorkflowId }));
39+
enqueueSnackbar(`Workflow has been ${done ? "deleted" : "stopped"}`, { variant: "success" });
40+
} catch (error) {
41+
enqueueError(error);
42+
} finally {
3743
void queryClient.invalidateQueries({
3844
queryKey: getGetRunningWorkflowQueryKey(runningWorkflowId),
3945
});
4046
void queryClient.invalidateQueries({ queryKey: getGetRunningWorkflowsQueryKey() });
41-
enqueueSnackbar(`Workflow has been ${done ? "deleted" : "terminated"}`, {
42-
variant: "success",
43-
});
44-
} catch (error) {
45-
enqueueError(error);
4647
}
4748
};
4849

4950
return (
5051
<WarningDeleteButton
51-
modalId={`terminate-workflow-${runningWorkflowId}`}
52+
modalId={`stop-workflow-${runningWorkflowId}`}
5253
submitText={verb}
5354
title={`${verb} Workflow`}
5455
tooltipText={`${verb} this workflow`}
55-
onDelete={handleTerminate}
56+
onDelete={handleClick}
5657
>
5758
{({ openModal }) => (
5859
<Button disabled={disabled} onClick={openModal}>

src/components/RunningWorkflowCard/RunningWorkflowCard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { Alert } from "@mui/material";
55

66
import { useIsUserAdminOrEditorOfCurrentProject } from "../../hooks/projectHooks";
77
import { CenterLoader } from "../CenterLoader";
8+
import { DeleteWorkflowButton } from "../DeleteWorkflowButton";
89
import { ResultCard } from "../results/ResultCard";
9-
import { TerminateWorkflowButton } from "../TerminateWorkflowButton";
1010
import { RunningWorkflowCollapsed } from "./RunningWorkflowCollapsed";
1111

1212
export interface RunningWorkflowCardProps {
@@ -49,7 +49,7 @@ export const RunningWorkflowCard = ({
4949
<ResultCard
5050
accentColor="#f1c40f"
5151
actions={() => (
52-
<TerminateWorkflowButton
52+
<DeleteWorkflowButton
5353
disabled={!hasPermission}
5454
runningWorkflowId={runningWorkflowId}
5555
status={workflow?.status ?? workflowSummary?.status}

0 commit comments

Comments
 (0)