Skip to content

Commit

Permalink
feat(orchestrator): display a confirmation dialog before the user abo…
Browse files Browse the repository at this point in the history
…rts a running workflow (#1215)

* display a confirmation dialog before the user aborts a running workflow

* Fix lint issue

* Move dialog action component out of the parent component
  • Loading branch information
yzhao583 authored Feb 18, 2024
1 parent a7e936d commit 1453cf8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 20 deletions.
2 changes: 1 addition & 1 deletion plugins/orchestrator/src/components/InfoDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type InfoDialogProps = {
open: boolean;
onClose?: () => void;
dialogActions?: React.ReactNode;
children: React.ReactNode;
children?: React.ReactNode;
};

export type ParentComponentRef = HTMLElement;
Expand Down
73 changes: 54 additions & 19 deletions plugins/orchestrator/src/components/WorkflowInstancePage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';

import {
Expand Down Expand Up @@ -27,8 +27,29 @@ import { executeWorkflowRouteRef, workflowInstanceRouteRef } from '../routes';
import { isNonNullable } from '../utils/TypeGuards';
import { buildUrl } from '../utils/UrlUtils';
import { BaseOrchestratorPage } from './BaseOrchestratorPage';
import { InfoDialog } from './InfoDialog';
import { WorkflowInstancePageContent } from './WorkflowInstancePageContent';

export type AbortConfirmationDialogActionsProps = {
handleSubmit: () => void;
handleCancel: () => void;
};

const AbortConfirmationDialogContent = () => (
<div>Are you sure you want to abort this workflow instance?</div>
);

const AbortConfirmationDialogActions = (
props: AbortConfirmationDialogActionsProps,
) => (
<>
<Button onClick={props.handleCancel}>Cancel</Button>
<Button onClick={props.handleSubmit} color="primary">
Ok
</Button>
</>
);

export const WorkflowInstancePage = ({
instanceId,
}: {
Expand All @@ -40,6 +61,8 @@ export const WorkflowInstancePage = ({
const { instanceId: queryInstanceId } = useRouteRefParams(
workflowInstanceRouteRef,
);
const [isAbortConfirmationDialogOpen, setIsAbortConfirmationDialogOpen] =
useState(false);

const fetchInstance = React.useCallback(async () => {
if (!instanceId && !queryInstanceId) {
Expand Down Expand Up @@ -73,26 +96,24 @@ export const WorkflowInstancePage = ({
[value],
);

const toggleAbortConfirmationDialog = () => {
setIsAbortConfirmationDialogOpen(!isAbortConfirmationDialogOpen);
};

const handleAbort = React.useCallback(async () => {
if (value) {
// eslint-disable-next-line no-alert
const yes = window.confirm(
'Are you sure you want to abort this instance?',
);

if (yes) {
try {
await orchestratorApi.abortWorkflow(value.instance.id);
restart();
} catch (e) {
// eslint-disable-next-line no-alert
window.alert(
`The abort operation failed with the following error: ${
(e as Error).message
}`,
);
}
try {
await orchestratorApi.abortWorkflow(value.instance.id);
restart();
} catch (e) {
// eslint-disable-next-line no-alert
window.alert(
`The abort operation failed with the following error: ${
(e as Error).message
}`,
);
}
setIsAbortConfirmationDialogOpen(false);
}
}, [orchestratorApi, restart, value]);

Expand Down Expand Up @@ -122,14 +143,28 @@ export const WorkflowInstancePage = ({
{!loading && isNonNullable(value) ? (
<>
<ContentHeader title="">
<InfoDialog
title="Abort workflow"
onClose={toggleAbortConfirmationDialog}
open={isAbortConfirmationDialogOpen}
dialogActions={
<AbortConfirmationDialogActions
handleCancel={toggleAbortConfirmationDialog}
handleSubmit={handleAbort}
/>
}
children={<AbortConfirmationDialogContent />}
/>
<Grid container item justifyContent="flex-end" spacing={1}>
{!canRerun && (
<Grid item>
<Button
variant="contained"
color="secondary"
disabled={!canAbort}
onClick={canAbort ? handleAbort : undefined}
onClick={
canAbort ? toggleAbortConfirmationDialog : undefined
}
>
Abort
</Button>
Expand Down

0 comments on commit 1453cf8

Please sign in to comment.