From af0c3bcd983a2cc2b20aebfec94b1981767ecd6c Mon Sep 17 00:00:00 2001 From: Rinsvent Date: Wed, 25 Jan 2023 23:10:01 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BB=D0=BE=D0=B0=D0=B4=D0=B5=D1=80=20=D0=9E=D1=82=D1=80=D0=B5?= =?UTF-8?q?=D1=84=D0=B0=D1=82=D0=BE=D1=80=D0=B8=D0=BB=20=D0=BC=D0=BE=D0=B4?= =?UTF-8?q?=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D0=B5=20=D0=BE=D0=BA=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/elements/processes/index.tsx | 80 +++++++++++++++---------- 1 file changed, 48 insertions(+), 32 deletions(-) diff --git a/components/elements/processes/index.tsx b/components/elements/processes/index.tsx index 7fa7459..ddba531 100644 --- a/components/elements/processes/index.tsx +++ b/components/elements/processes/index.tsx @@ -10,7 +10,7 @@ import ErrorOutline from "@mui/icons-material/ErrorOutline" import ReplayOutlined from "@mui/icons-material/ReplayOutlined" import RunCircleOutlined from "@mui/icons-material/RunCircleOutlined" import FactCheckOutlined from "@mui/icons-material/FactCheckOutlined" -import {IconButton, LinearProgress, TableContainer, Table, TableBody, TableCell, TableHead, TableRow, TablePagination} from "@mui/material" +import {Box, CircularProgress, IconButton, LinearProgress, TableContainer, Table, TableBody, TableCell, TableHead, TableRow, TablePagination} from "@mui/material" import ConfirmDialog from "../confirm-dialog"; import smClient from "../../../api/sm/sm-client"; import {ProcessesResponseInterface, Status} from "../../../api/sm/responses/processes"; @@ -29,8 +29,8 @@ export default function Processes() { const [processes, setProcesses] = useState([]); const [page, setPage] = useState(0); const [count, setCount] = useState(0); - const [open, setOpen] = useState(false); - const [modify, setModify] = useState(false); + const [loading, setLoading] = useState(true); + const [modalLoading, setModalLoading] = useState(true); const [action, setAction] = useState(null); const [command, setCommand] = useState(null); const [selectedProcess, setSelectedProcess] = useState(null); @@ -49,6 +49,7 @@ export default function Processes() { }) setProcesses(processes) setCount(Number(headers.get('X-Pagination-Count'))) + setLoading(false) refreshLock = false } let output = async (process: ProcessesResponseInterface) => { @@ -68,6 +69,13 @@ export default function Processes() { return () => clearInterval(timer); }, [page]); + useEffect(() => { + if (action === null) { + setSelectedProcess(null) + setCommand(null) + } + }, [action]); + let isFinished = (process: ProcessesResponseInterface) => process.cancelledAt || process.completedAt const handleChangePage = (event: any, page: number) => { @@ -76,7 +84,6 @@ export default function Processes() { const openDialog = (process: ProcessesResponseInterface, action: Action) => { setSelectedProcess(process) - setOpen(true) setAction(action) } @@ -106,25 +113,7 @@ export default function Processes() { }) } - if (action === Action.Stop) { - await smClient.stopProcess(selectedProcess.id) - } - - if (action === Action.Kill) { - await smClient.killProcess(selectedProcess.id) - } - - if (action === Action.Play) { - await smClient.playProcess(selectedProcess.id) - } - - if (action === Action.Pause) { - await smClient.pauseProcess(selectedProcess.id) - } - lock = false - setSelectedProcess(null) - setOpen(false) setAction(null) } @@ -133,6 +122,14 @@ export default function Processes() { setArgumentList(argumentList) } + if (loading) { + return ( + + + + ); + } + return ( <> @@ -212,26 +209,45 @@ export default function Processes() { /> {selectedProcess && { + setAction(Action.Run) + setModalLoading(true) let {data: command} = await smClient.getCommand(selectedProcess.name) setCommand(command) - setModify(true) - openDialog(selectedProcess, Action.Run) + setModalLoading(false) }} - closeCallback={() => { - setSelectedProcess(null) - setOpen(false) - setCommand(null) - }}> - {!modify && `Reply?`} - {command && {setAction(null)}}> + Reply? + } + {selectedProcess && {setAction(null)}}> + {modalLoading && + + } + {!modalLoading && !!command && (Action.Run === action) && } } + {selectedProcess && -1) } + agreeCallback={async () => { + Action.Play === action && await smClient.playProcess(selectedProcess.id) + Action.Pause === action && await smClient.pauseProcess(selectedProcess.id) + Action.Stop === action && await smClient.stopProcess(selectedProcess.id) + Action.Kill === action && await smClient.killProcess(selectedProcess.id) + setAction(null) + }} + closeCallback={() => {setAction(null)}}> + {selectedProcess.name} + } ) }