Files
Checkmate/client/src/Pages/Infrastructure/Details/index.jsx
T

142 lines
3.8 KiB
React
Raw Normal View History

2025-01-31 13:43:57 -08:00
// Components
2025-08-03 00:30:04 +05:30
import { Stack, Typography, Tab } from "@mui/material";
2025-09-27 14:54:55 -07:00
import Breadcrumbs from "@/Components/v1/Breadcrumbs/index.jsx";
import MonitorDetailsControlHeader from "@/Components/v1/MonitorDetailsControlHeader/index.jsx";
import MonitorTimeFrameHeader from "@/Components/v1/MonitorTimeFrameHeader/index.jsx";
2025-09-25 10:11:41 -07:00
import StatusBoxes from "./Components/StatusBoxes/index.jsx";
import GaugeBoxes from "./Components/GaugeBoxes/index.jsx";
import AreaChartBoxes from "./Components/AreaChartBoxes/index.jsx";
2025-09-27 14:54:55 -07:00
import GenericFallback from "@/Components/v1/GenericFallback/index.jsx";
2025-09-25 10:11:41 -07:00
import NetworkStats from "./Components/NetworkStats/index.jsx";
2025-09-27 14:54:55 -07:00
import CustomTabList from "@/Components/v1/Tab/index.jsx";
2025-08-03 00:30:04 +05:30
import TabContext from "@mui/lab/TabContext";
2025-01-31 13:43:57 -08:00
// Utils
2024-11-19 11:40:45 +08:00
import { useTheme } from "@emotion/react";
2026-01-12 23:57:39 +00:00
import { useIsAdmin } from "@/Hooks/useIsAdmin.js";
import { useFetchHardwareMonitorById } from "../../../Hooks/monitorHooks.js";
2025-01-31 13:43:57 -08:00
import { useState } from "react";
2025-03-12 00:56:28 +05:30
import { useTranslation } from "react-i18next";
2025-01-31 13:43:57 -08:00
import { useParams } from "react-router-dom";
2025-01-31 13:43:57 -08:00
// Constants
const BREADCRUMBS = [
{ name: "infrastructure monitors", path: "/infrastructure" },
{ name: "details", path: "" },
];
const InfrastructureDetails = () => {
// Local state
2025-03-05 11:23:45 -08:00
const [dateRange, setDateRange] = useState("recent");
2025-06-16 11:17:09 +08:00
const [trigger, setTrigger] = useState(false);
2025-08-03 00:30:04 +05:30
const [tab, setTab] = useState("details");
2025-01-31 13:43:57 -08:00
// Utils
2024-11-19 11:40:45 +08:00
const theme = useTheme();
const { monitorId } = useParams();
2025-03-12 00:56:28 +05:30
const { t } = useTranslation();
const isAdmin = useIsAdmin();
2025-06-12 12:44:46 +08:00
const [monitor, isLoading, networkError] = useFetchHardwareMonitorById({
2025-01-31 13:43:57 -08:00
monitorId,
dateRange,
2025-06-16 11:17:09 +08:00
updateTrigger: trigger,
2025-01-31 13:43:57 -08:00
});
2024-12-31 20:00:22 -08:00
2025-06-16 11:17:09 +08:00
const triggerUpdate = () => {
setTrigger(!trigger);
};
2025-01-31 13:43:57 -08:00
if (networkError === true) {
return (
<GenericFallback>
<Typography
variant="h1"
marginY={theme.spacing(4)}
color={theme.palette.primary.contrastTextTertiary}
2024-11-19 11:40:45 +08:00
>
2025-06-07 19:30:55 +02:00
{t("common.toasts.networkError")}
2025-01-31 13:43:57 -08:00
</Typography>
2025-06-07 19:30:55 +02:00
<Typography>{t("common.toasts.checkConnection")}</Typography>
2025-01-31 13:43:57 -08:00
</GenericFallback>
);
}
2024-12-31 20:00:22 -08:00
if (!isLoading && monitor?.stats?.checks?.length === 0) {
return (
<Stack gap={theme.spacing(10)}>
<Breadcrumbs list={BREADCRUMBS} />
2025-06-16 11:17:09 +08:00
<MonitorDetailsControlHeader
path={"infrastructure"}
2025-06-16 11:17:09 +08:00
isLoading={isLoading}
isAdmin={isAdmin}
monitor={monitor}
2025-06-16 11:17:09 +08:00
triggerUpdate={triggerUpdate}
/>
<GenericFallback>
2025-03-12 00:56:28 +05:30
<Typography>{t("distributedUptimeDetailsNoMonitorHistory")}</Typography>
</GenericFallback>
</Stack>
);
}
2024-12-31 20:00:22 -08:00
2025-01-31 13:43:57 -08:00
return (
<Stack gap={theme.spacing(10)}>
<Breadcrumbs list={BREADCRUMBS} />
2025-06-16 11:17:09 +08:00
<MonitorDetailsControlHeader
2025-01-31 13:43:57 -08:00
path={"infrastructure"}
2025-06-16 11:17:09 +08:00
isLoading={isLoading}
isAdmin={isAdmin}
2025-01-31 13:43:57 -08:00
monitor={monitor}
2025-06-16 11:17:09 +08:00
triggerUpdate={triggerUpdate}
2025-01-31 13:43:57 -08:00
/>
2025-08-03 00:30:04 +05:30
<TabContext value={tab}>
<CustomTabList
value={tab}
onChange={(e, v) => setTab(v)}
>
<Tab
label={t("details")}
2025-08-03 00:30:04 +05:30
value="details"
/>
<Tab
label={t("network")}
2025-08-03 00:30:04 +05:30
value="network"
/>
</CustomTabList>
{tab === "details" && (
<>
<StatusBoxes
shouldRender={!isLoading}
monitor={monitor}
/>
<GaugeBoxes
isLoading={isLoading}
monitor={monitor}
/>
<MonitorTimeFrameHeader
isLoading={isLoading}
dateRange={dateRange}
setDateRange={setDateRange}
/>
<AreaChartBoxes
shouldRender={!isLoading}
monitor={monitor}
dateRange={dateRange}
2025-08-03 00:30:04 +05:30
/>
</>
)}
{tab === "network" && (
<NetworkStats
net={monitor?.stats?.aggregateData?.latestCheck?.net || []}
isLoading={isLoading}
checks={monitor?.stats?.checks}
dateRange={dateRange}
setDateRange={setDateRange}
/>
)}
</TabContext>
2025-01-31 13:43:57 -08:00
</Stack>
2024-11-19 11:40:45 +08:00
);
};
export default InfrastructureDetails;