forked from zmc/pulpito-ng
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Move Alert and kill-run Button from Run Page to `Alert` and `KillButton` component respectively 2. lib/teuthologyAPI: add useRunKill (which uses `useMutation` to send POST req at /kill to t-api) Signed-off-by: Vallari Agrawal <val.agl002@gmail.com>
- Loading branch information
Showing
5 changed files
with
103 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import Snackbar from "@mui/material/Snackbar"; | ||
import Alert from "@mui/material/Alert"; | ||
import { useState } from "react"; | ||
|
||
type AlertProps = { | ||
severity: "success" | "error", | ||
message: string, | ||
}; | ||
|
||
export default function AlertComponent(props: AlertProps) { | ||
const [isOpen, setIsOpen] = useState(true); | ||
const handleClose = ( | ||
event?: React.SyntheticEvent | Event, | ||
reason?: string | ||
) => { | ||
if (reason === "clickaway") { | ||
return; | ||
} | ||
setIsOpen(false); | ||
}; | ||
|
||
return ( | ||
<Snackbar autoHideDuration={3000} open={isOpen} onClose={handleClose}> | ||
<Alert onClose={handleClose} severity={props.severity} sx={{ width: "100%" }}> | ||
{props.message} | ||
</Alert> | ||
</Snackbar> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import type { UseMutationResult } from "@tanstack/react-query"; | ||
import Button from "@mui/material/Button"; | ||
import Box from "@mui/material/Box"; | ||
import { CircularProgress } from "@mui/material"; | ||
|
||
import { Run } from "../../lib/paddles.d" | ||
import Alert from "../Alert"; | ||
|
||
|
||
type KillButtonProps = { | ||
mutation: UseMutationResult; | ||
text: string; | ||
runDetails?: Run; | ||
}; | ||
|
||
|
||
// TODO: make this generic for killing runs and job | ||
export default function KillButton(props: KillButtonProps) { | ||
const mutation: UseMutationResult = props.mutation; | ||
|
||
const killPayload = { | ||
"--run": props.runDetails?.name, | ||
"--owner": props.runDetails?.user, | ||
"--machine-type": props.runDetails?.machine_type, | ||
"--user": props.runDetails?.user, | ||
} | ||
|
||
return ( | ||
<div> | ||
<div style={{ display: "flex" }}> | ||
<Button | ||
variant="contained" | ||
color="error" | ||
size="large" | ||
onClick={() => mutation.mutate(killPayload)} | ||
disabled={(mutation.isLoading)} | ||
> | ||
{props.text} | ||
</Button> | ||
{(mutation.isLoading) ? ( | ||
<Box sx={{ p: 1 }}> | ||
<CircularProgress size={20} color="inherit" /> | ||
</Box> | ||
) : null} | ||
</div> | ||
{ (mutation.isError) ? <Alert severity="error" message="Unable to kill run" /> : null } | ||
{ (mutation.isSuccess) ? <Alert severity="success" message="Run killed successfully" /> : null } | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters