Skip to content

Commit

Permalink
pages/Run/index.tsx: Add kill run button
Browse files Browse the repository at this point in the history
Signed-off-by: Devansh3712 <[email protected]>
  • Loading branch information
Devansh3712 committed Aug 13, 2023
1 parent 3a30b59 commit d9510bf
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/pages/Run/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { useQueryParams, StringParam, NumberParam } from "use-query-params";
import { styled, useTheme } from "@mui/material/styles";
import { useParams } from "react-router-dom";
import { useState } from "react";
import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button";
import ButtonGroup from "@mui/material/ButtonGroup";
import Alert from "@mui/material/Alert";
import Box from "@mui/material/Box";
import CircularProgress from "@mui/material/CircularProgress";
import Snackbar from "@mui/material/Snackbar";
import { format } from "date-fns";
import SourceBranch from "mdi-material-ui/SourceBranch";
import { Helmet } from "react-helmet";
Expand Down Expand Up @@ -35,6 +40,28 @@ export default function Run() {
page: NumberParam,
pageSize: NumberParam,
});
const [kill, setKill] = useState(false);
const [success, setSuccess] = useState(false);
const [error, setError] = useState(false);
const killRun = async () => {
setKill(true);
// Using a mock API endpoint for testing
const response = await fetch("https://reqres.in/api/users/2?delay=3");
const status = response.status;
if (status === 200) setSuccess(true);
else setError(true);
setKill(false);
};
const handleClose = (
event?: React.SyntheticEvent | Event,
reason?: string
) => {
if (reason === "clickaway") {
return;
}
setSuccess(false);
setError(false);
};
const { name } = useParams<RunParams>();
const query = useRun(name === undefined ? "" : name);
if (query === null) return <Typography>404</Typography>;
Expand Down Expand Up @@ -70,6 +97,35 @@ export default function Run() {
<Typography>scheduled on {date}</Typography>
</Link>
</div>
<div
style={{
display: "flex",
}}
>
<Button
variant="contained"
color="error"
size="large"
onClick={killRun}
>
Kill Run
</Button>
{kill ? (
<Box sx={{ p: 1 }}>
<CircularProgress size={20} color="inherit" />
</Box>
) : null}
</div>
<Snackbar autoHideDuration={3000} open={success} onClose={handleClose}>
<Alert onClose={handleClose} severity="success" sx={{ width: "100%" }}>
Run killed successfully
</Alert>
</Snackbar>
<Snackbar autoHideDuration={3000} open={error} onClose={handleClose}>
<Alert onClose={handleClose} severity="error" sx={{ width: "100%" }}>
Unable to kill run
</Alert>
</Snackbar>
<ButtonGroup style={{ display: "flex", justifyContent: "center" }}>
<Button
onClick={() => {
Expand Down

0 comments on commit d9510bf

Please sign in to comment.