Skip to content

Commit

Permalink
Merge pull request #29 from ceph/revert-25-main
Browse files Browse the repository at this point in the history
Revert "Implement kill-run button"
Reviewed-by Kamoltat Sirivadhna <[email protected]>
Reviewed-by Devansh Singh <[email protected]>
  • Loading branch information
kamoltat authored Jul 17, 2023
2 parents c791641 + 08f8271 commit 9be0d4d
Showing 1 changed file with 9 additions and 63 deletions.
72 changes: 9 additions & 63 deletions src/pages/Run/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { useReducer, useState } from "react";
import { useReducer } from "react";
import { useParams } from "react-router-dom";
import { makeStyles, useTheme } from "@mui/styles";
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 All @@ -18,6 +14,7 @@ import { useRun } from "../../lib/paddles";
import JobList from "../../components/JobList";
import Link from "../../components/Link";


const useStyles = makeStyles(() => ({
root: {
"& .MuiButton-root": {
Expand All @@ -28,17 +25,17 @@ const useStyles = makeStyles(() => ({

type StatusFilterState = {
[key: string]: string;
};
}

type StatusFilterReducerAction = {
type: string;
payload: StatusFilterReducerPayload;
};
}

type StatusFilterReducerPayload = {
key: string;
value: string;
};
}

function reducer(state: StatusFilterState, action: StatusFilterReducerAction) {
let newState: StatusFilterState;
Expand All @@ -61,31 +58,9 @@ export default function Run() {
const theme = useTheme();
const { name } = useParams<RunParams>();
const [state, dispatch] = useReducer(reducer, {});
const [kill, setKill] = useState(false);
const [success, setSuccess] = useState(false);
const [error, setError] = useState(false);
const query = useRun(name === undefined ? "" : name);
if (query === null) return <Typography>404</Typography>;
const query = useRun(name === undefined? "" : name);
if ( query === null ) return (<Typography>404</Typography>);
if (!query.isSuccess) return null;
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 setFilter = (key: string, value: string) => {
dispatch({
type: "set",
Expand All @@ -102,7 +77,7 @@ export default function Run() {
return (
<div className={classes.root}>
<Helmet>
<title>{`${name} - Pulpito`}</title>
<title>{ `${name} - Pulpito` }</title>
</Helmet>
<Typography variant="h5" style={{ margin: "20px 0px" }}>
{name}
Expand All @@ -116,42 +91,13 @@ export default function Run() {
</Link>
<Link to={`/runs/?branch=${branch}`}>
<Typography>
<SourceBranch style={{ color: theme.palette.text.primary }} />
<SourceBranch style={{"color": theme.palette.text.primary}}/>
</Typography>
</Link>
<Link to={`/runs/?date=${date}`}>
<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 9be0d4d

Please sign in to comment.