use reusable table in infrastructure page
This commit is contained in:
1 parent
c69389db2c
commit
c504fbbad6
1 file changed
+92
-145
@@ -8,23 +8,12 @@ import SkeletonLayout from "./skeleton";
|
|||||||
import Fallback from "../../Components/Fallback";
|
import Fallback from "../../Components/Fallback";
|
||||||
// import GearIcon from "../../Assets/icons/settings-bold.svg?react";
|
// import GearIcon from "../../Assets/icons/settings-bold.svg?react";
|
||||||
import CPUChipIcon from "../../assets/icons/cpu-chip.svg?react";
|
import CPUChipIcon from "../../assets/icons/cpu-chip.svg?react";
|
||||||
import {
|
import DataTable from "../../Components/Table";
|
||||||
Box,
|
import { Box, Button, IconButton, Stack } from "@mui/material";
|
||||||
Button,
|
|
||||||
IconButton,
|
|
||||||
Paper,
|
|
||||||
Stack,
|
|
||||||
Table,
|
|
||||||
TableBody,
|
|
||||||
TableCell,
|
|
||||||
TableContainer,
|
|
||||||
TableHead,
|
|
||||||
TableRow,
|
|
||||||
} from "@mui/material";
|
|
||||||
import Breadcrumbs from "../../Components/Breadcrumbs";
|
import Breadcrumbs from "../../Components/Breadcrumbs";
|
||||||
import { StatusLabel } from "../../Components/Label";
|
import { StatusLabel } from "../../Components/Label";
|
||||||
import { Heading } from "../../Components/Heading";
|
import { Heading } from "../../Components/Heading";
|
||||||
import { Pagination } from "./components/TablePagination";
|
import { Pagination } from "../../Components/Table/TablePagination/index.jsx";
|
||||||
// import { getInfrastructureMonitorsByTeamId } from "../../Features/InfrastructureMonitors/infrastructureMonitorsSlice";
|
// import { getInfrastructureMonitorsByTeamId } from "../../Features/InfrastructureMonitors/infrastructureMonitorsSlice";
|
||||||
import { networkService } from "../../Utils/NetworkService.js";
|
import { networkService } from "../../Utils/NetworkService.js";
|
||||||
import CustomGauge from "../../Components/Charts/CustomGauge/index.jsx";
|
import CustomGauge from "../../Components/Charts/CustomGauge/index.jsx";
|
||||||
@@ -32,42 +21,8 @@ import Host from "../Uptime/Home/host.jsx";
|
|||||||
import { useIsAdmin } from "../../Hooks/useIsAdmin.js";
|
import { useIsAdmin } from "../../Hooks/useIsAdmin.js";
|
||||||
import { InfrastructureMenu } from "./components/Menu";
|
import { InfrastructureMenu } from "./components/Menu";
|
||||||
|
|
||||||
const columns = [
|
|
||||||
{ label: "Host" },
|
|
||||||
{ label: "Status" },
|
|
||||||
{ label: "Frequency" },
|
|
||||||
{ label: "CPU" },
|
|
||||||
{ label: "Mem" },
|
|
||||||
{ label: "Disk" },
|
|
||||||
{ label: "Actions" },
|
|
||||||
];
|
|
||||||
|
|
||||||
const BREADCRUMBS = [{ name: `infrastructure`, path: "/infrastructure" }];
|
const BREADCRUMBS = [{ name: `infrastructure`, path: "/infrastructure" }];
|
||||||
|
|
||||||
/* TODO
|
|
||||||
Create reusable table component.
|
|
||||||
It should receive as a parameter the following object:
|
|
||||||
tableData = [
|
|
||||||
columns = [
|
|
||||||
{
|
|
||||||
id: example,
|
|
||||||
label: Example Extendable,
|
|
||||||
align: "center" | "left" (default)
|
|
||||||
}
|
|
||||||
],
|
|
||||||
rows: [
|
|
||||||
{
|
|
||||||
**Number of keys will be equal to number of columns**
|
|
||||||
key1: string,
|
|
||||||
key2: number,
|
|
||||||
key3: Component
|
|
||||||
}
|
|
||||||
]
|
|
||||||
]
|
|
||||||
Apply to Monitor Table, and Account/Team.
|
|
||||||
Analyze existing BasicTable
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the Infrastructure monitoring page. This is a work in progress
|
* This is the Infrastructure monitoring page. This is a work in progress
|
||||||
*
|
*
|
||||||
@@ -139,6 +94,81 @@ function Infrastructure() {
|
|||||||
fetchMonitors();
|
fetchMonitors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
{ label: "Host" },
|
||||||
|
{ label: "Status" },
|
||||||
|
{ label: "Frequency" },
|
||||||
|
{ label: "CPU" },
|
||||||
|
{ label: "Mem" },
|
||||||
|
{ label: "Disk" },
|
||||||
|
{ label: "Actions" },
|
||||||
|
];
|
||||||
|
|
||||||
|
const headers = [
|
||||||
|
{
|
||||||
|
id: "host",
|
||||||
|
content: "Host",
|
||||||
|
render: (row) => (
|
||||||
|
<Host
|
||||||
|
title={row.name}
|
||||||
|
url={row.url}
|
||||||
|
percentage={row.uptimePercentage}
|
||||||
|
percentageColor={row.percentageColor}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "status",
|
||||||
|
content: "Status",
|
||||||
|
render: (row) => (
|
||||||
|
<StatusLabel
|
||||||
|
status={row.status}
|
||||||
|
text={row.status}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "frequency",
|
||||||
|
content: "Frequency",
|
||||||
|
render: (row) => (
|
||||||
|
<Stack
|
||||||
|
direction={"row"}
|
||||||
|
justifyContent={"center"}
|
||||||
|
alignItems={"center"}
|
||||||
|
gap=".25rem"
|
||||||
|
>
|
||||||
|
<CPUChipIcon
|
||||||
|
width={20}
|
||||||
|
height={20}
|
||||||
|
/>
|
||||||
|
{row.processor}
|
||||||
|
</Stack>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{ id: "cpu", content: "CPU", render: (row) => <CustomGauge progress={row.cpu} /> },
|
||||||
|
{ id: "mem", content: "Mem", render: (row) => <CustomGauge progress={row.mem} /> },
|
||||||
|
{ id: "disk", content: "Disk", render: (row) => <CustomGauge progress={row.disk} /> },
|
||||||
|
{
|
||||||
|
id: "actions",
|
||||||
|
content: "Actions",
|
||||||
|
render: (row) => (
|
||||||
|
<IconButton
|
||||||
|
sx={{
|
||||||
|
"& svg path": {
|
||||||
|
stroke: theme.palette.other.icon,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<InfrastructureMenu
|
||||||
|
monitor={row}
|
||||||
|
isAdmin={isAdmin}
|
||||||
|
updateCallback={handleActionMenuDelete}
|
||||||
|
/>
|
||||||
|
</IconButton>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
const monitorsAsRows = monitors.map((monitor) => {
|
const monitorsAsRows = monitors.map((monitor) => {
|
||||||
const processor =
|
const processor =
|
||||||
((monitor.checks[0]?.cpu?.usage_frequency ?? 0) / 1000).toFixed(2) + " GHz";
|
((monitor.checks[0]?.cpu?.usage_frequency ?? 0) / 1000).toFixed(2) + " GHz";
|
||||||
@@ -237,103 +267,20 @@ function Infrastructure() {
|
|||||||
{totalMonitors}
|
{totalMonitors}
|
||||||
</Box>
|
</Box>
|
||||||
</Stack>
|
</Stack>
|
||||||
<TableContainer component={Paper}>
|
|
||||||
<Table stickyHeader>
|
<DataTable
|
||||||
<TableHead sx={{ backgroundColor: theme.palette.background.accent }}>
|
config={{
|
||||||
<TableRow>
|
rowSX: {
|
||||||
{columns.map((column, index) => (
|
cursor: "pointer",
|
||||||
<TableCell
|
"&:hover": {
|
||||||
key={index}
|
backgroundColor: theme.palette.background.accent,
|
||||||
align={index === 0 ? "left" : "center"}
|
},
|
||||||
sx={{
|
},
|
||||||
backgroundColor: theme.palette.background.accent,
|
onRowClick: (row) => openDetails(row.id),
|
||||||
}}
|
}}
|
||||||
>
|
headers={headers}
|
||||||
{column.label}
|
data={monitorsAsRows}
|
||||||
</TableCell>
|
/>
|
||||||
))}
|
|
||||||
</TableRow>
|
|
||||||
</TableHead>
|
|
||||||
<TableBody>
|
|
||||||
{monitorsAsRows.map((row) => {
|
|
||||||
return (
|
|
||||||
<TableRow
|
|
||||||
key={row.id}
|
|
||||||
onClick={() => openDetails(row.id)}
|
|
||||||
sx={{
|
|
||||||
cursor: "pointer",
|
|
||||||
"&:hover": {
|
|
||||||
backgroundColor: theme.palette.background.accent,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{/* TODO iterate over column and get column id, applying row[column.id] */}
|
|
||||||
<TableCell>
|
|
||||||
<Host
|
|
||||||
title={row.name}
|
|
||||||
url={row.url}
|
|
||||||
percentage={row.uptimePercentage}
|
|
||||||
percentageColor={row.percentageColor}
|
|
||||||
/>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell align="center">
|
|
||||||
<StatusLabel
|
|
||||||
status={row.status}
|
|
||||||
text={row.status}
|
|
||||||
/* Use capitalize inside of Status Label */
|
|
||||||
/* Update component so we don't need to pass text and status separately*/
|
|
||||||
customStyles={{ textTransform: "capitalize" }}
|
|
||||||
/>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell align="center">
|
|
||||||
<Stack
|
|
||||||
direction={"row"}
|
|
||||||
justifyContent={"center"}
|
|
||||||
alignItems={"center"}
|
|
||||||
gap=".25rem"
|
|
||||||
>
|
|
||||||
<CPUChipIcon
|
|
||||||
width={20}
|
|
||||||
height={20}
|
|
||||||
/>
|
|
||||||
{row.processor}
|
|
||||||
</Stack>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell align="center">
|
|
||||||
<CustomGauge progress={row.cpu} />
|
|
||||||
</TableCell>
|
|
||||||
<TableCell align="center">
|
|
||||||
<CustomGauge progress={row.mem} />
|
|
||||||
</TableCell>
|
|
||||||
<TableCell align="center">
|
|
||||||
<CustomGauge progress={row.disk} />
|
|
||||||
</TableCell>
|
|
||||||
<TableCell align="center">
|
|
||||||
{/* Get ActionsMenu from Monitor Table and create a component */}
|
|
||||||
<IconButton
|
|
||||||
sx={{
|
|
||||||
"& svg path": {
|
|
||||||
stroke: theme.palette.other.icon,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<InfrastructureMenu
|
|
||||||
monitor={row}
|
|
||||||
isAdmin={isAdmin}
|
|
||||||
updateCallback={handleActionMenuDelete}
|
|
||||||
/>
|
|
||||||
{/* <GearIcon
|
|
||||||
width={20}
|
|
||||||
height={20}
|
|
||||||
/> */}
|
|
||||||
</IconButton>
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</TableBody>
|
|
||||||
</Table>
|
|
||||||
</TableContainer>
|
|
||||||
<Pagination
|
<Pagination
|
||||||
monitorCount={totalMonitors}
|
monitorCount={totalMonitors}
|
||||||
page={page}
|
page={page}
|
||||||
|
|||||||
Reference in new issue
Block a user