Files
Checkmate/src/Pages/DistributedUptime/Monitors/Components/MonitorTable/index.jsx
T

93 lines
2.0 KiB
React
Raw Normal View History

2025-02-06 15:06:37 -08:00
// Components
2025-02-06 14:57:28 -08:00
import DataTable from "../../../../../Components/Table";
import BarChart from "../../../../../Components/Charts/BarChart";
import { Box } from "@mui/material";
import { StatusLabel } from "../../../../../Components/Label";
2025-02-06 15:06:37 -08:00
import Host from "../../../../../Components/Host";
2025-02-06 14:57:28 -08:00
2025-02-06 15:06:37 -08:00
// Utils
2025-02-06 14:57:28 -08:00
import { useTheme } from "@mui/material/styles";
import { useNavigate } from "react-router-dom";
import { useMonitorUtils } from "../../../../../Hooks/useMonitorUtils";
2025-02-06 15:06:37 -08:00
import PropTypes from "prop-types";
// Constants
2025-02-06 14:57:28 -08:00
const TYPE_MAP = {
distributed_http: "Distributed HTTP",
};
const MonitorTable = ({ isLoading, monitors }) => {
const theme = useTheme();
const navigate = useNavigate();
const { determineState } = useMonitorUtils();
const headers = [
{
id: "name",
content: <Box>Host</Box>,
render: (row) => (
<Host
key={row._id}
url={row.url}
title={row.name}
2025-02-06 14:57:28 -08:00
percentageColor={row.percentageColor}
percentage={row.percentage}
/>
),
},
{
id: "status",
content: <Box width="max-content"> Status</Box>,
render: (row) => {
const status = determineState(row?.monitor);
return (
<StatusLabel
status={status}
text={status}
customStyles={{ textTransform: "capitalize" }}
/>
);
},
},
{
id: "responseTime",
content: "Response Time",
render: (row) => <BarChart checks={row?.monitor?.checks.slice().reverse()} />,
},
{
id: "type",
content: "Type",
render: (row) => <span>{TYPE_MAP[row.monitor.type]}</span>,
},
{
id: "actions",
content: "Actions",
2025-02-06 15:06:37 -08:00
render: (row) => <span>{"TODO"}</span>,
2025-02-06 14:57:28 -08:00
},
];
return (
<DataTable
shouldRender={!isLoading}
headers={headers}
data={monitors}
config={{
rowSX: {
cursor: "pointer",
"&:hover": {
backgroundColor: theme.palette.background.accent,
},
},
onRowClick: (row) => {
2025-02-07 14:51:29 -08:00
navigate(`/distributed-uptime/${row._id}`);
2025-02-06 14:57:28 -08:00
},
}}
/>
);
};
2025-02-06 15:06:37 -08:00
MonitorTable.propTypes = {
isLoading: PropTypes.bool,
monitors: PropTypes.array,
};
2025-02-06 14:57:28 -08:00
export default MonitorTable;