diff --git a/components/elements/processes/index.tsx b/components/elements/processes/index.tsx index bedbbb7..8704897 100644 --- a/components/elements/processes/index.tsx +++ b/components/elements/processes/index.tsx @@ -9,7 +9,7 @@ import CheckCircleOutline from "@mui/icons-material/CheckCircleOutline"; import ErrorOutline from "@mui/icons-material/ErrorOutline"; import Replay from "@mui/icons-material/Replay"; import RunCircle from "@mui/icons-material/RunCircle"; -import {IconButton, LinearProgress, Table, TableBody, TableCell, TableHead, TableRow} from "@mui/material"; +import {IconButton, LinearProgress, TableContainer, Table, TableBody, TableCell, TableHead, TableRow, TablePagination} from "@mui/material"; export interface ProcessExceptionInterface { message: string, @@ -53,22 +53,30 @@ enum Status { export default function Processes() { const [processes, setProcesses] = useState([]); + const [page, setPage] = useState(0); + const [count, setCount] = useState(0); let refreshProcesses = async () => { - let response = await fetch('http://fmw.sipachev.sv/system-monitoring/processes', { - method: 'GET', - headers: { - 'X-Plugin-Token': 'passw0rd' - }, - }); + let response = await fetch('http://fmw.sipachev.sv/system-monitoring/processes?' + new URLSearchParams({ + page: page + 1, + limit: 20, + }), + { + method: 'GET', + headers: { + 'X-Plugin-Token': 'passw0rd', + 'X-Pagination-Count': '0', + }, + }); const processes: ProcessInterface[] = await response.json() setProcesses(processes) + setCount(Number(response.headers.get('X-Pagination-Count'))) setTimeout(() => refreshProcesses, 1000) } useEffect(() => { refreshProcesses() - }, []) + }, [page]) let isFinished = (process: ProcessInterface) => process.cancelledAt || process.completedAt let canPlay = (process: ProcessInterface) => !isFinished(process) && process.progress && process.pausedAt @@ -94,64 +102,80 @@ export default function Processes() { return Status.Wait } + const handleChangePage = (event: any, page: number) => { + setPage(page); + } + return ( - - - - Name - Progress - Action - Status - - - - {processes.map((process: ProcessInterface, index: number) => ( - - {process.name} - - {!process.progress && } - {process.progress && } - {process.progress && - {`${process.progress.progress}`} / {`${process.progress.total}`} - 50% [53Mb] / 20 sec - } - {canPlay(process) && - - } - {canPause(process) && - - } - {canStop(process) && - - } - - - {canRepeat(process) && - - } - {canKill(process) && - - } - - - {Status.Error === status(process) && - - } - {Status.Success === status(process) && - - } - {Status.Running === status(process) && - - } - {Status.Cancelled === status(process) && - - } - {Status.Wait === status(process) && - - } - - - ))} - -
+ <> + + + + + Name + Progress + Action + Status + + + + {processes.map((process: ProcessInterface, index: number) => ( + + {process.name} + + {!process.progress && !isFinished(process) && } + {!process.progress && isFinished(process) && } + {process.progress && } + {process.progress && + {`${process.progress.progress}`} / {`${process.progress.total}`} - 50% [53Mb] / 20 sec + } + {canPlay(process) && + + } + {canPause(process) && + + } + {canStop(process) && + + } + + + {canRepeat(process) && + + } + {canKill(process) && + + } + + + {Status.Error === status(process) && + + } + {Status.Success === status(process) && + + } + {Status.Running === status(process) && + + } + {Status.Cancelled === status(process) && + + } + {Status.Wait === status(process) && + + } + + + ))} + +
+
+ + ) }