Skip to content

Commit 92ec8c6

Browse files
Abort confirm dialog
1 parent e8db473 commit 92ec8c6

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

ui.frontend/src/components/CodeExecuteButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Button, ButtonGroup, Content, Dialog, DialogContainer, Divider, Form, H
22
import Alert from '@spectrum-icons/workflow/Alert';
33
import Checkmark from '@spectrum-icons/workflow/Checkmark';
44
import Close from '@spectrum-icons/workflow/Close';
5-
import Gears from '@spectrum-icons/workflow/Gears';
5+
import PlayCircle from '@spectrum-icons/workflow/PlayCircle';
66
import React, { useState } from 'react';
77
import { FormProvider, useForm } from 'react-hook-form';
88
import { toastRequest } from '../utils/api';
@@ -96,7 +96,7 @@ const CodeExecuteButton: React.FC<CodeExecuteButtonProps> = ({ code, onDescribeF
9696
return (
9797
<>
9898
<Button aria-label="Execute" variant="accent" onPress={handleExecute} isPending={isPending || described} isDisabled={isDisabled}>
99-
<Gears />
99+
<PlayCircle />
100100
<Text>Execute</Text>
101101
</Button>
102102
<DialogContainer onDismiss={handleCloseDialog}>

ui.frontend/src/components/ExecutionAbortButton.tsx

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { Button, Text } from '@adobe/react-spectrum';
1+
import { Button, ButtonGroup, Content, Dialog, DialogTrigger, Divider, Heading, Text } from '@adobe/react-spectrum';
22
import { ToastQueue } from '@react-spectrum/toast';
33
import Cancel from '@spectrum-icons/workflow/Cancel';
4+
import StopCircle from '@spectrum-icons/workflow/StopCircle';
45
import React, { useState } from 'react';
6+
import { useDeepCompareEffect } from 'react-use';
57
import { appState } from '../hooks/app.ts';
68
import { pollExecutionPending } from '../hooks/execution';
79
import { apiRequest } from '../utils/api';
@@ -14,8 +16,16 @@ interface ExecutionAbortButtonProps {
1416
}
1517

1618
const ExecutionAbortButton: React.FC<ExecutionAbortButtonProps> = ({ execution, onComplete }) => {
19+
const [showDialog, setShowDialog] = useState(false);
1720
const [isAborting, setIsAborting] = useState(false);
1821

22+
// Auto-close dialog if execution is no longer pending
23+
useDeepCompareEffect(() => {
24+
if (showDialog && (!execution || !isExecutionPending(execution.status))) {
25+
setShowDialog(false);
26+
}
27+
}, [execution, showDialog]);
28+
1929
const onAbort = async () => {
2030
if (!execution?.id) {
2131
console.warn('Code execution cannot be aborted as it is not running!');
@@ -49,14 +59,41 @@ const ExecutionAbortButton: React.FC<ExecutionAbortButtonProps> = ({ execution,
4959
});
5060
} finally {
5161
setIsAborting(false);
62+
setShowDialog(false);
5263
}
5364
};
5465

66+
const renderAbortDialog = () => (
67+
<>
68+
<Heading>
69+
<Text>Confirmation</Text>
70+
</Heading>
71+
<Divider />
72+
<Content>
73+
<p>This action will abort current code execution.</p>
74+
<p>Be aware that aborting execution may leave data in an inconsistent state.</p>
75+
</Content>
76+
<ButtonGroup>
77+
<Button variant="secondary" onPress={() => setShowDialog(false)} isDisabled={isAborting}>
78+
<Cancel />
79+
<Text>Cancel</Text>
80+
</Button>
81+
<Button variant="negative" style="fill" onPress={onAbort} isPending={isAborting}>
82+
<StopCircle />
83+
<Text>Abort</Text>
84+
</Button>
85+
</ButtonGroup>
86+
</>
87+
);
88+
5589
return (
56-
<Button variant="negative" isDisabled={!execution || !isExecutionPending(execution.status) || isAborting} onPress={onAbort}>
57-
<Cancel />
58-
<Text>Abort</Text>
59-
</Button>
90+
<DialogTrigger isOpen={showDialog} onOpenChange={setShowDialog}>
91+
<Button variant="negative" isDisabled={!execution || !isExecutionPending(execution.status) || isAborting} onPress={() => setShowDialog(true)}>
92+
<StopCircle />
93+
<Text>Abort</Text>
94+
</Button>
95+
<Dialog>{renderAbortDialog()}</Dialog>
96+
</DialogTrigger>
6097
);
6198
};
6299

0 commit comments

Comments
 (0)