Files
Checkmate/Client/src/Pages/Monitors/Home/monitorData.jsx
T

93 lines
2.3 KiB
React
Raw Normal View History

2024-08-27 15:18:18 -07:00
import Host from "./host";
import ActionsMenu from "./actionsMenu";
import BarChart from "../../../Components/Charts/BarChart";
import ArrowDownwardRoundedIcon from "@mui/icons-material/ArrowDownwardRounded";
import { StatusLabel } from "../../../Components/Label";
import { Box } from "@mui/material";
2024-08-28 22:14:55 -04:00
import { useTheme } from "@emotion/react";
2024-08-27 15:18:18 -07:00
const data = {
cols: [
{ id: 1, name: "Host" },
{
id: 2,
name: (
<Box width="max-content">
Status
<span>
<ArrowDownwardRoundedIcon />
</span>
</Box>
),
},
{ id: 3, name: "Response Time" },
{ id: 4, name: "Type" },
{ id: 5, name: "Actions" },
],
rows: [],
};
export const buildData = (monitors, isAdmin, navigate) => {
2024-08-28 22:14:55 -04:00
const theme = useTheme();
2024-08-27 15:18:18 -07:00
data.rows = monitors.map((monitor, idx) => {
2024-08-31 17:59:25 -07:00
let uptimePercentage = "";
if (monitor.uptimePercentage !== undefined) {
uptimePercentage =
monitor.uptimePercentage === 0
2024-09-02 10:45:07 -07:00
? "0"
: (monitor.uptimePercentage * 100).toFixed(2);
2024-08-31 17:59:25 -07:00
}
2024-08-27 15:18:18 -07:00
const params = {
2024-08-28 10:28:02 -04:00
url: monitor.url,
2024-08-27 15:18:18 -07:00
title: monitor.name,
2024-08-31 17:59:25 -07:00
percentage: uptimePercentage,
2024-08-27 15:18:18 -07:00
percentageColor:
2024-08-28 22:14:55 -04:00
monitor.status === true
? theme.palette.success.main
: theme.palette.error.text,
2024-09-02 10:45:07 -07:00
status:
monitor.status === undefined
? "unknown"
: monitor.status === true
? "up"
: "down",
2024-08-27 15:18:18 -07:00
};
// Reverse checks so latest check is on the right
const reversedChecks = monitor.checks.slice().reverse();
return {
id: monitor._id,
handleClick: () => {
navigate(`/monitors/${monitor._id}`);
},
data: [
{ id: idx, data: <Host params={params} /> },
{
id: idx + 1,
data: (
<StatusLabel
status={params.status}
text={params.status}
customStyles={{ textTransform: "capitalize" }}
/>
),
},
{ id: idx + 2, data: <BarChart checks={reversedChecks} /> },
{
id: idx + 3,
data: (
<span style={{ textTransform: "uppercase" }}>{monitor.type}</span>
),
},
{
id: idx + 4,
data: <ActionsMenu monitor={monitor} isAdmin={isAdmin} />,
},
],
};
});
return data;
};