Skip to content

Commit d9510bf

Browse files
committed
pages/Run/index.tsx: Add kill run button
Signed-off-by: Devansh3712 <[email protected]>
1 parent 3a30b59 commit d9510bf

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/pages/Run/index.tsx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import { useQueryParams, StringParam, NumberParam } from "use-query-params";
22
import { styled, useTheme } from "@mui/material/styles";
33
import { useParams } from "react-router-dom";
4+
import { useState } from "react";
45
import Typography from "@mui/material/Typography";
56
import Button from "@mui/material/Button";
67
import ButtonGroup from "@mui/material/ButtonGroup";
8+
import Alert from "@mui/material/Alert";
9+
import Box from "@mui/material/Box";
10+
import CircularProgress from "@mui/material/CircularProgress";
11+
import Snackbar from "@mui/material/Snackbar";
712
import { format } from "date-fns";
813
import SourceBranch from "mdi-material-ui/SourceBranch";
914
import { Helmet } from "react-helmet";
@@ -35,6 +40,28 @@ export default function Run() {
3540
page: NumberParam,
3641
pageSize: NumberParam,
3742
});
43+
const [kill, setKill] = useState(false);
44+
const [success, setSuccess] = useState(false);
45+
const [error, setError] = useState(false);
46+
const killRun = async () => {
47+
setKill(true);
48+
// Using a mock API endpoint for testing
49+
const response = await fetch("https://reqres.in/api/users/2?delay=3");
50+
const status = response.status;
51+
if (status === 200) setSuccess(true);
52+
else setError(true);
53+
setKill(false);
54+
};
55+
const handleClose = (
56+
event?: React.SyntheticEvent | Event,
57+
reason?: string
58+
) => {
59+
if (reason === "clickaway") {
60+
return;
61+
}
62+
setSuccess(false);
63+
setError(false);
64+
};
3865
const { name } = useParams<RunParams>();
3966
const query = useRun(name === undefined ? "" : name);
4067
if (query === null) return <Typography>404</Typography>;
@@ -70,6 +97,35 @@ export default function Run() {
7097
<Typography>scheduled on {date}</Typography>
7198
</Link>
7299
</div>
100+
<div
101+
style={{
102+
display: "flex",
103+
}}
104+
>
105+
<Button
106+
variant="contained"
107+
color="error"
108+
size="large"
109+
onClick={killRun}
110+
>
111+
Kill Run
112+
</Button>
113+
{kill ? (
114+
<Box sx={{ p: 1 }}>
115+
<CircularProgress size={20} color="inherit" />
116+
</Box>
117+
) : null}
118+
</div>
119+
<Snackbar autoHideDuration={3000} open={success} onClose={handleClose}>
120+
<Alert onClose={handleClose} severity="success" sx={{ width: "100%" }}>
121+
Run killed successfully
122+
</Alert>
123+
</Snackbar>
124+
<Snackbar autoHideDuration={3000} open={error} onClose={handleClose}>
125+
<Alert onClose={handleClose} severity="error" sx={{ width: "100%" }}>
126+
Unable to kill run
127+
</Alert>
128+
</Snackbar>
73129
<ButtonGroup style={{ display: "flex", justifyContent: "center" }}>
74130
<Button
75131
onClick={() => {

0 commit comments

Comments
 (0)