Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement kill-run button #31

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
@@ -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);
const response = await fetch("https://reqres.in/api/users/2?delay=3"); // success response
// const response = await fetch("https://reqres.in/api/users/23?delay=3"); // error response
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>;
@@ -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={() => {