|
1 | 1 | import { useQueryParams, StringParam, NumberParam } from "use-query-params";
|
2 | 2 | import { styled, useTheme } from "@mui/material/styles";
|
3 | 3 | import { useParams } from "react-router-dom";
|
| 4 | +import { useState } from "react"; |
4 | 5 | import Typography from "@mui/material/Typography";
|
5 | 6 | import Button from "@mui/material/Button";
|
6 | 7 | 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"; |
7 | 12 | import { format } from "date-fns";
|
8 | 13 | import SourceBranch from "mdi-material-ui/SourceBranch";
|
9 | 14 | import { Helmet } from "react-helmet";
|
@@ -35,6 +40,28 @@ export default function Run() {
|
35 | 40 | page: NumberParam,
|
36 | 41 | pageSize: NumberParam,
|
37 | 42 | });
|
| 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 | + }; |
38 | 65 | const { name } = useParams<RunParams>();
|
39 | 66 | const query = useRun(name === undefined ? "" : name);
|
40 | 67 | if (query === null) return <Typography>404</Typography>;
|
@@ -70,6 +97,35 @@ export default function Run() {
|
70 | 97 | <Typography>scheduled on {date}</Typography>
|
71 | 98 | </Link>
|
72 | 99 | </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> |
73 | 129 | <ButtonGroup style={{ display: "flex", justifyContent: "center" }}>
|
74 | 130 | <Button
|
75 | 131 | onClick={() => {
|
|
0 commit comments