Files
Checkmate/client/src/Pages/v2/Uptime/MonitorTable.tsx
T

131 lines
2.6 KiB
TypeScript
Raw Normal View History

2025-10-03 15:40:53 -07:00
import Stack from "@mui/material/Stack";
import { HistogramResponseTime } from "@/Components/v2/Monitors/HistogramResponseTime";
import type { Header } from "@/Components/v2/DesignElements/Table";
import type { IMonitor } from "@/Types/Monitor";
import { Table } from "@/Components/v2/DesignElements";
import { useTranslation } from "react-i18next";
import { useMediaQuery } from "@mui/material";
import { useTheme } from "@mui/material/styles";
2025-10-06 11:34:29 -07:00
import { ActionsMenu } from "@/Components/v2/ActionsMenu";
import type { ActionMenuItem } from "@/Components/v2/ActionsMenu";
2025-10-06 11:40:08 -07:00
import Typography from "@mui/material/Typography";
2025-10-06 11:34:29 -07:00
2025-10-06 11:43:13 -07:00
const getActions = (theme: any): ActionMenuItem[] => {
2025-10-06 11:34:29 -07:00
return [
{
id: 1,
label: "Open site",
action: () => {
console.log("Open site");
},
closeMenu: true,
},
{
id: 2,
label: "Details",
action: () => {
console.log("Open details");
},
},
{
id: 3,
label: "Incidents",
action: () => {
console.log("Open incidents");
},
},
{
id: 4,
label: "Configure",
action: () => {
console.log("Open configure");
},
},
{
id: 5,
label: "Clone",
action: () => {
console.log("Open clone");
},
},
{
id: 6,
label: "Pause",
action: () => {
console.log("Open pause");
},
closeMenu: true,
},
{
id: 7,
2025-10-06 11:40:08 -07:00
label: <Typography color={theme.palette.error.main}>Remove</Typography>,
2025-10-06 11:34:29 -07:00
action: () => {
console.log("Open delete");
},
closeMenu: true,
},
];
};
2025-10-06 11:40:08 -07:00
const getHeaders = (theme: any, t: Function) => {
2025-10-03 15:40:53 -07:00
const headers: Header<IMonitor>[] = [
{
id: "name",
content: t("host"),
render: (row) => {
return row.name;
},
},
{
id: "status",
content: t("status"),
render: (row) => {
return row.status;
},
},
{
id: "histogram",
content: t("responseTime"),
render: (row) => {
return (
<Stack alignItems={"center"}>
<HistogramResponseTime checks={row.latestChecks} />
</Stack>
);
},
},
{
id: "type",
content: t("type"),
render: (row) => {
return row.type;
},
},
2025-10-06 11:34:29 -07:00
{
id: "actions",
content: t("actions"),
2025-10-06 11:43:13 -07:00
render: () => {
return <ActionsMenu items={getActions(theme)} />;
2025-10-06 11:34:29 -07:00
},
},
2025-10-03 15:40:53 -07:00
];
return headers;
};
export const MonitorTable = ({ monitors }: { monitors: IMonitor[] }) => {
const { t } = useTranslation();
const theme = useTheme();
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
2025-10-06 11:40:08 -07:00
let headers = getHeaders(theme, t);
2025-10-03 15:40:53 -07:00
if (isSmall) {
headers = headers.filter((h) => h.id !== "histogram");
}
return (
<Table
headers={headers}
data={monitors}
/>
);
};