Skip to content

Commit

Permalink
feat(orchestrator): display a alert dialog when the user fails to abo…
Browse files Browse the repository at this point in the history
…rt a running workflow (janus-idp#1239)

* Display a alert dialog when the user fails to abort a running workflow

* Update plugins/orchestrator/src/components/WorkflowInstancePage.tsx

Co-authored-by: Jonathan Kilzi <[email protected]>

* Remove redundant fragment

* Make the message props mandatory

---------

Co-authored-by: Jonathan Kilzi <[email protected]>
  • Loading branch information
yzhao583 and jkilzi authored Feb 22, 2024
1 parent af8e072 commit 44cb11b
Showing 1 changed file with 42 additions and 6 deletions.
48 changes: 42 additions & 6 deletions plugins/orchestrator/src/components/WorkflowInstancePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,24 @@ export type AbortConfirmationDialogActionsProps = {
handleCancel: () => void;
};

export type AbortAlertDialogActionsProps = {
handleClose: () => void;
};

export type AbortAlertDialogContentProps = {
message: string;
};

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

const AbortAlertDialogContent = (props: AbortAlertDialogContentProps) => (
<div>
The abort operation failed with the following error: {props.message}
</div>
);

const AbortConfirmationDialogActions = (
props: AbortConfirmationDialogActionsProps,
) => (
Expand All @@ -50,6 +64,12 @@ const AbortConfirmationDialogActions = (
</>
);

const AbortAlertDialogActions = (props: AbortAlertDialogActionsProps) => (
<Button onClick={props.handleClose} color="primary">
OK
</Button>
);

export const WorkflowInstancePage = ({
instanceId,
}: {
Expand All @@ -63,6 +83,9 @@ export const WorkflowInstancePage = ({
);
const [isAbortConfirmationDialogOpen, setIsAbortConfirmationDialogOpen] =
useState(false);
const [isAbortAlertDialogOpen, setIsAbortAlertDialogOpen] = useState(false);
const [abortWorkflowInstanceErrorMsg, setAbortWorkflowInstanceErrorMsg] =
useState('');

const fetchInstance = React.useCallback(async () => {
if (!instanceId && !queryInstanceId) {
Expand Down Expand Up @@ -100,18 +123,18 @@ export const WorkflowInstancePage = ({
setIsAbortConfirmationDialogOpen(!isAbortConfirmationDialogOpen);
};

const toggleAbortAlertDialog = () => {
setIsAbortAlertDialogOpen(!isAbortAlertDialogOpen);
};

const handleAbort = React.useCallback(async () => {
if (value) {
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
}`,
);
setAbortWorkflowInstanceErrorMsg(`${(e as Error).message}`);
setIsAbortAlertDialogOpen(true);
}
setIsAbortConfirmationDialogOpen(false);
}
Expand Down Expand Up @@ -155,6 +178,19 @@ export const WorkflowInstancePage = ({
}
children={<AbortConfirmationDialogContent />}
/>
<InfoDialog
title="Abort workflow failed"
onClose={toggleAbortAlertDialog}
open={isAbortAlertDialogOpen}
dialogActions={
<AbortAlertDialogActions handleClose={toggleAbortAlertDialog} />
}
children={
<AbortAlertDialogContent
message={abortWorkflowInstanceErrorMsg}
/>
}
/>
<Grid container item justifyContent="flex-end" spacing={1}>
{!canRerun && (
<Grid item>
Expand Down

0 comments on commit 44cb11b

Please sign in to comment.