Skip to content

Commit 1031b05

Browse files
committed
fix(orchestarator):Disable abort when workflow execution does not exist
Signed-off-by: Lior Soffer <[email protected]>
1 parent 54dcb42 commit 1031b05

File tree

3 files changed

+93
-44
lines changed

3 files changed

+93
-44
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@red-hat-developer-hub/backstage-plugin-orchestrator': patch
3+
---
4+
5+
Disable abort when workflow execution does not exist

workspaces/orchestrator/plugins/orchestrator/src/components/InfoDialog.tsx

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 The Backstage Authors
2+
* Copyright Red Hat, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
import React, { forwardRef, ForwardRefRenderFunction } from 'react';
1718

1819
import {
@@ -45,7 +46,13 @@ const useStyles = makeStyles(_theme => ({
4546
},
4647
dialogActions: {
4748
justifyContent: 'flex-start',
48-
paddingLeft: _theme.spacing(2),
49+
paddingLeft: _theme.spacing(3),
50+
paddingBottom: _theme.spacing(2),
51+
},
52+
title: {
53+
position: 'absolute',
54+
left: 20,
55+
top: 20,
4956
},
5057
}));
5158

@@ -60,7 +67,9 @@ export const RefForwardingInfoDialog: ForwardRefRenderFunction<
6067
<Dialog onClose={_ => onClose} open={open} ref={forwardedRef}>
6168
<DialogTitle>
6269
<Box>
63-
<Typography variant="h5">{title}</Typography>
70+
<Typography className={classes.title} variant="h5">
71+
{title}
72+
</Typography>
6473
<IconButton
6574
className={classes.closeBtn}
6675
aria-label="close"

workspaces/orchestrator/plugins/orchestrator/src/components/WorkflowInstancePage.tsx

+76-41
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import Snackbar from '@material-ui/core/Snackbar';
4242
import { createStyles, makeStyles, Theme } from '@material-ui/core/styles';
4343
import CloseIcon from '@material-ui/icons/Close';
4444
import ErrorIcon from '@material-ui/icons/Error';
45+
import { AlertTitle } from '@material-ui/lab';
4546
import Alert from '@material-ui/lab/Alert';
4647
import ArrowDropDown from '@mui/icons-material/ArrowDropDown';
4748
import StartIcon from '@mui/icons-material/Start';
@@ -70,36 +71,89 @@ import { WorkflowInstancePageContent } from './WorkflowInstancePageContent';
7071
const useStyles = makeStyles((theme: Theme) =>
7172
createStyles({
7273
abortButton: {
73-
backgroundColor: theme.palette.error.main,
74-
color: theme.palette.getContrastText(theme.palette.error.main),
74+
backgroundColor: theme.palette.error.dark,
75+
color: theme.palette.getContrastText(theme.palette.error.dark),
7576
'&:hover': {
7677
backgroundColor: theme.palette.error.dark,
78+
filter: 'brightness(90%)',
7779
},
7880
},
81+
modalText: {
82+
fontSize: '1.1rem',
83+
},
84+
errorColor: {
85+
color: theme.palette.error.dark,
86+
},
7987
}),
8088
);
8189

8290
export type AbortConfirmationDialogActionsProps = {
8391
handleSubmit: () => void;
8492
handleCancel: () => void;
93+
isAborting: boolean;
94+
canAbort: boolean;
8595
};
8696

87-
const AbortConfirmationDialogContent = () => (
88-
<div>
89-
<b>
90-
Are you sure you want to abort this workflow run? <br /> <br />
91-
Aborting will stop all in-progress and pending steps immediately. Any
92-
incomplete tasks will not be saved.
93-
</b>
94-
</div>
95-
);
97+
const AbortConfirmationDialogContent = ({
98+
canAbort,
99+
}: {
100+
canAbort: boolean;
101+
}) => {
102+
const classes = useStyles();
103+
return (
104+
<div>
105+
<p className={classes.modalText}>
106+
Are you sure you want to abort this workflow run? <br /> <br />
107+
Aborting will stop all in-progress and pending steps immediately. Any
108+
incomplete tasks will not be saved.
109+
</p>
110+
{!canAbort && (
111+
<Box sx={{ width: '100%' }}>
112+
<Alert severity="info">
113+
<AlertTitle>Run completed</AlertTitle>
114+
It is not possible to abort the run as it has already been
115+
completed.
116+
</Alert>
117+
</Box>
118+
)}
119+
</div>
120+
);
121+
};
122+
123+
const AbortConfirmationDialogActions = (
124+
props: AbortConfirmationDialogActionsProps,
125+
) => {
126+
const classes = useStyles();
127+
return (
128+
<>
129+
<Button
130+
onClick={props.handleSubmit}
131+
variant="contained"
132+
className={classes.abortButton}
133+
startIcon={props.isAborting ? <CircularProgress size="1rem" /> : null}
134+
disabled={props.isAborting || !props.canAbort}
135+
>
136+
{' '}
137+
Abort
138+
</Button>
139+
<Button
140+
onClick={props.handleCancel}
141+
variant="outlined"
142+
color="primary"
143+
disabled={props.isAborting}
144+
>
145+
{' '}
146+
Cancel
147+
</Button>
148+
</>
149+
);
150+
};
96151

97152
export const WorkflowInstancePage = ({
98153
instanceId,
99154
}: {
100155
instanceId?: string;
101156
}) => {
102-
const classes = useStyles();
103157
const navigate = useNavigate();
104158
const orchestratorApi = useApi(orchestratorApiRef);
105159
const executeWorkflowLink = useRouteRef(executeWorkflowRouteRef);
@@ -125,32 +179,6 @@ export const WorkflowInstancePage = ({
125179
setIsRerunSnackbarOpen(false);
126180
};
127181

128-
const AbortConfirmationDialogActions = (
129-
props: AbortConfirmationDialogActionsProps,
130-
) => (
131-
<>
132-
<Button
133-
onClick={props.handleSubmit}
134-
variant="contained"
135-
className={classes.abortButton}
136-
startIcon={isAborting ? <CircularProgress size="1rem" /> : null}
137-
disabled={isAborting}
138-
>
139-
{' '}
140-
Abort
141-
</Button>
142-
<Button
143-
onClick={props.handleCancel}
144-
variant="outlined"
145-
color="primary"
146-
disabled={isAborting}
147-
>
148-
{' '}
149-
Cancel
150-
</Button>
151-
</>
152-
);
153-
154182
const fetchInstance = React.useCallback(async () => {
155183
if (!instanceId && !queryInstanceId) {
156184
return undefined;
@@ -266,6 +294,8 @@ export const WorkflowInstancePage = ({
266294
else if (option === 'retrigger') handleRetrigger();
267295
};
268296

297+
const classes = useStyles();
298+
269299
return (
270300
<BaseOrchestratorPage
271301
title={value?.instance.id}
@@ -280,8 +310,11 @@ export const WorkflowInstancePage = ({
280310
<InfoDialog
281311
title={
282312
<Box display="flex" alignItems="center">
283-
<ErrorIcon color="error" style={{ marginRight: 8 }} />
284-
<b>Abort workflow</b>
313+
<ErrorIcon
314+
className={classes.errorColor}
315+
style={{ marginRight: 8 }}
316+
/>
317+
<b>Abort workflow run?</b>
285318
</Box>
286319
}
287320
onClose={toggleAbortConfirmationDialog}
@@ -290,9 +323,11 @@ export const WorkflowInstancePage = ({
290323
<AbortConfirmationDialogActions
291324
handleCancel={toggleAbortConfirmationDialog}
292325
handleSubmit={handleAbort}
326+
isAborting={isAborting}
327+
canAbort={canAbort}
293328
/>
294329
}
295-
children={<AbortConfirmationDialogContent />}
330+
children={<AbortConfirmationDialogContent canAbort={canAbort} />}
296331
/>
297332
<Grid container item justifyContent="flex-end" spacing={1}>
298333
<Grid item>

0 commit comments

Comments
 (0)