2021-08-27 21:26:12 +02:00
|
|
|
import React, { useState } from "react";
|
|
|
|
import { WorkerScript } from "../../Netscript/WorkerScript";
|
|
|
|
import { WorkerScriptAccordion } from "./WorkerScriptAccordion";
|
2021-09-18 06:16:02 +02:00
|
|
|
import List from "@mui/material/List";
|
|
|
|
import TablePagination from "@mui/material/TablePagination";
|
|
|
|
import { TablePaginationActionsAll } from "../React/TablePaginationActionsAll";
|
2021-09-22 02:30:00 +02:00
|
|
|
import { Settings } from "../../Settings/Settings";
|
2021-08-27 21:26:12 +02:00
|
|
|
|
|
|
|
interface IProps {
|
2021-09-05 01:09:30 +02:00
|
|
|
workerScripts: WorkerScript[];
|
2021-08-27 21:26:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function ServerAccordionContent(props: IProps): React.ReactElement {
|
2021-09-05 01:09:30 +02:00
|
|
|
const [page, setPage] = useState(0);
|
2021-09-22 02:30:00 +02:00
|
|
|
const [rowsPerPage, setRowsPerPage] = useState(Settings.ActiveScriptsScriptPageSize);
|
2021-09-20 05:29:02 +02:00
|
|
|
const handleChangePage = (event: unknown, newPage: number): void => {
|
2021-09-18 06:16:02 +02:00
|
|
|
setPage(newPage);
|
|
|
|
};
|
2021-08-27 21:26:12 +02:00
|
|
|
|
2021-09-20 05:29:02 +02:00
|
|
|
const handleChangeRowsPerPage = (event: React.ChangeEvent<HTMLInputElement>): void => {
|
2021-09-22 02:30:00 +02:00
|
|
|
Settings.ActiveScriptsScriptPageSize = parseInt(event.target.value, 10);
|
2021-09-18 06:16:02 +02:00
|
|
|
setRowsPerPage(parseInt(event.target.value, 10));
|
|
|
|
setPage(0);
|
|
|
|
};
|
2021-08-27 21:26:12 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
return (
|
|
|
|
<>
|
2021-09-18 06:31:14 +02:00
|
|
|
<List dense disablePadding>
|
2021-09-21 17:50:48 +02:00
|
|
|
{props.workerScripts.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage).map((ws) => (
|
2021-09-18 06:16:02 +02:00
|
|
|
<WorkerScriptAccordion key={`${ws.name}_${ws.args}`} workerScript={ws} />
|
|
|
|
))}
|
|
|
|
</List>
|
|
|
|
<TablePagination
|
2021-09-21 17:50:48 +02:00
|
|
|
rowsPerPageOptions={[10, 15, 20, 100]}
|
2021-09-18 06:16:02 +02:00
|
|
|
component="div"
|
|
|
|
count={props.workerScripts.length}
|
|
|
|
rowsPerPage={rowsPerPage}
|
2021-09-21 17:50:48 +02:00
|
|
|
page={page}
|
2021-09-18 06:16:02 +02:00
|
|
|
onPageChange={handleChangePage}
|
|
|
|
onRowsPerPageChange={handleChangeRowsPerPage}
|
|
|
|
ActionsComponent={TablePaginationActionsAll}
|
|
|
|
/>
|
2021-09-05 01:09:30 +02:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|