diff --git a/src/components/KillButton/index.tsx b/src/components/KillButton/index.tsx index 9ca5526..0febf82 100644 --- a/src/components/KillButton/index.tsx +++ b/src/components/KillButton/index.tsx @@ -1,7 +1,13 @@ +import { useState } from "react"; 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 CircularProgress from "@mui/material/CircularProgress"; +import DialogTitle from '@mui/material/DialogTitle'; +import DialogContent from '@mui/material/DialogContent'; +import Dialog from '@mui/material/Dialog'; +import Paper from "@mui/material/Paper"; +import Typography from "@mui/material/Typography"; import { KillRunPayload } from "../../lib/teuthologyAPI.d"; import { useSession } from "../../lib/teuthologyAPI"; @@ -15,17 +21,29 @@ type KillButtonProps = { disabled?: boolean; }; +type KillButtonDialogProps = { + mutation: UseMutationResult; + payload: KillRunPayload; + open: boolean; + handleClose: () => void; +}; export default function KillButton(props: KillButtonProps) { + const [open, setOpen] = useState(false); const mutation: UseMutationResult = props.mutation; const sessionQuery = useSession(); const loggedUser = sessionQuery.data?.session.username; - if (loggedUser?.toLowerCase() != props.payload["--user"].toLowerCase()) { + if (loggedUser?.toLowerCase() != props.payload["--owner"].toLowerCase()) { // logged user and owner of the job should be equal (case insensitive) return null } + const toggleDialog = () => { + setOpen(!open); + }; + + return (
@@ -33,19 +51,65 @@ export default function KillButton(props: KillButtonProps) { variant="contained" color="error" size="large" - onClick={() => mutation.mutate(props.payload)} + onClick={toggleDialog} disabled={(props.disabled || mutation.isLoading)} > {props.text} - {(mutation.isLoading) ? ( - - - - ) : null} +
{ (mutation.isError) ? : null } - { (mutation.isSuccess) ? : null } + { (mutation.isSuccess) ? : null }
); }; + +function KillButtonDialog({mutation, open, handleClose, payload}: KillButtonDialogProps) { + return ( +
+ + Kill confirmation + + { (mutation.data && mutation.data.data ) ? +
+ + {mutation.isSuccess ? "Successful!": "Failed!"} + + + + {mutation.data.data.logs} + + +
: + (mutation.isLoading) ? ( + + + + Killing run... + + + ) : +
+ + Are you sure you want to kill this run/job? + + +
+ } +
+
+
+ ) +} diff --git a/src/lib/teuthologyAPI.d.ts b/src/lib/teuthologyAPI.d.ts index 3a8aa35..9404c2e 100644 --- a/src/lib/teuthologyAPI.d.ts +++ b/src/lib/teuthologyAPI.d.ts @@ -9,6 +9,5 @@ export type Session = { export type KillRunPayload = { "--run": string, "--owner": string, - "--machine-type": string, - "--user": string, + "--machine-type": string, } diff --git a/src/pages/Run/index.tsx b/src/pages/Run/index.tsx index 0922ff5..c4a4912 100644 --- a/src/pages/Run/index.tsx +++ b/src/pages/Run/index.tsx @@ -61,7 +61,6 @@ export default function Run() { "--run": data?.name || "", "--owner": run_owner, "--machine-type": data?.machine_type || "", - "--user": data?.user || "", } return (