2026-09-19 14:57:30 -06:00
|
|
|
import { useMemo, useState } from "react";
|
2026-09-10 18:00:12 -06:00
|
|
|
import Box from "@mui/material/Box";
|
2026-09-19 14:57:30 -06:00
|
|
|
import Stack from "@mui/material/Stack";
|
2026-09-10 18:00:12 -06:00
|
|
|
import { useTheme } from "@mui/material/styles";
|
2026-09-19 14:57:30 -06:00
|
|
|
import { useTranslation } from "react-i18next";
|
2026-09-10 18:00:12 -06:00
|
|
|
|
|
|
|
|
import { BasePage } from "@/Components/design-elements/BasePage";
|
2026-09-19 14:57:30 -06:00
|
|
|
import { Button } from "@/Components/inputs";
|
2026-09-10 18:00:12 -06:00
|
|
|
import { LAYOUT } from "@/Utils/Theme/constants";
|
2026-09-16 13:26:41 -06:00
|
|
|
import { useMonitorListController } from "@/Hooks/useMonitorListController";
|
|
|
|
|
import { MonitorTypes, type MonitorTypeCount } from "@/Types/Monitor";
|
2026-09-10 18:00:12 -06:00
|
|
|
|
|
|
|
|
import { MonitorStatusCard } from "@/Pages/Dashboard/components/cards/MonitorStatusCard";
|
|
|
|
|
import { MonitorsByTypeCard } from "@/Pages/Dashboard/components/cards/MonitorsByTypeCard";
|
2026-09-19 14:57:30 -06:00
|
|
|
import {
|
|
|
|
|
EditCardsModal,
|
|
|
|
|
type DashboardCardKey,
|
|
|
|
|
} from "@/Pages/Dashboard/components/EditCardsModal";
|
|
|
|
|
|
|
|
|
|
const allCards = new Set<DashboardCardKey>(["monitorStatus", "monitorsByType"]);
|
2026-09-10 18:00:12 -06:00
|
|
|
|
|
|
|
|
const Dashboard = () => {
|
|
|
|
|
const theme = useTheme();
|
2026-09-19 14:57:30 -06:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
const [editOpen, setEditOpen] = useState(false);
|
|
|
|
|
const [visibleCards, setVisibleCards] = useState<Set<DashboardCardKey>>(allCards);
|
|
|
|
|
|
2026-09-16 13:26:41 -06:00
|
|
|
const { monitors, summary } = useMonitorListController({
|
|
|
|
|
types: [...MonitorTypes],
|
|
|
|
|
checksLimit: 1,
|
|
|
|
|
refreshInterval: 30000,
|
|
|
|
|
rowsPerPageTable: "monitors",
|
|
|
|
|
rowsPerPageDefault: 100,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const monitorsByType = useMemo<MonitorTypeCount[]>(() => {
|
|
|
|
|
const countMap = new Map<MonitorTypeCount["type"], number>();
|
|
|
|
|
(monitors ?? []).forEach((m) =>
|
|
|
|
|
countMap.set(m.type, (countMap.get(m.type) ?? 0) + 1)
|
|
|
|
|
);
|
|
|
|
|
return [...countMap.entries()]
|
|
|
|
|
.map(([type, count]) => ({ type, count }))
|
|
|
|
|
.sort((a, b) => b.count - a.count);
|
|
|
|
|
}, [monitors]);
|
2026-09-10 18:00:12 -06:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<BasePage headerKey="dashboard">
|
2026-09-19 14:57:30 -06:00
|
|
|
<Stack gap={theme.spacing(LAYOUT.SM)}>
|
|
|
|
|
<Stack
|
|
|
|
|
direction="row"
|
|
|
|
|
justifyContent="flex-end"
|
|
|
|
|
>
|
|
|
|
|
<Button
|
|
|
|
|
variant="outlined"
|
|
|
|
|
size="small"
|
|
|
|
|
onClick={() => setEditOpen(true)}
|
|
|
|
|
>
|
|
|
|
|
{t("pages.dashboard.editCards")}
|
|
|
|
|
</Button>
|
|
|
|
|
</Stack>
|
|
|
|
|
|
|
|
|
|
<Box
|
|
|
|
|
display="grid"
|
|
|
|
|
gridTemplateColumns={{ xs: "1fr", md: "1fr 1fr" }}
|
|
|
|
|
gap={theme.spacing(LAYOUT.MD)}
|
|
|
|
|
>
|
|
|
|
|
{visibleCards.has("monitorStatus") && <MonitorStatusCard summary={summary} />}
|
|
|
|
|
{visibleCards.has("monitorsByType") && (
|
|
|
|
|
<MonitorsByTypeCard monitorsByType={monitorsByType} />
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
</Stack>
|
|
|
|
|
|
|
|
|
|
<EditCardsModal
|
|
|
|
|
open={editOpen}
|
|
|
|
|
visibleCards={visibleCards}
|
|
|
|
|
onClose={() => setEditOpen(false)}
|
|
|
|
|
onSave={(next) => {
|
|
|
|
|
setVisibleCards(next);
|
|
|
|
|
setEditOpen(false);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2026-09-10 18:00:12 -06:00
|
|
|
</BasePage>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default Dashboard;
|