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

175 lines
4.7 KiB
React
Raw Normal View History

2025-01-27 14:55:55 -08:00
// Components
2024-08-17 17:26:48 -04:00
import Breadcrumbs from "../../../Components/Breadcrumbs";
2025-05-15 10:51:06 -07:00
import MonitorDetailsControlHeader from "../../../Components/MonitorDetailsControlHeader";
import MonitorTimeFrameHeader from "../../../Components/MonitorTimeFrameHeader";
2025-01-27 14:55:55 -08:00
import ChartBoxes from "./Components/ChartBoxes";
import ResponseTimeChart from "./Components/Charts/ResponseTimeChart";
import ResponseTable from "./Components/ResponseTable";
import UptimeStatusBoxes from "./Components/UptimeStatusBoxes";
2025-01-31 07:32:49 -08:00
import GenericFallback from "../../../Components/GenericFallback";
2025-06-12 12:44:46 +08:00
import Stack from "@mui/material/Stack";
import Typography from "@mui/material/Typography";
2025-01-27 14:55:55 -08:00
// Utils
import { useState } from "react";
import { useParams } from "react-router-dom";
import { useSelector } from "react-redux";
import { useTheme } from "@emotion/react";
import { useIsAdmin } from "../../../Hooks/useIsAdmin";
2025-06-12 12:44:46 +08:00
import { useFetchUptimeMonitorById } from "../../../Hooks/monitorHooks";
2025-01-27 14:55:55 -08:00
import useCertificateFetch from "./Hooks/useCertificateFetch";
2025-06-12 12:44:46 +08:00
import { useFetchChecks } from "../../../Hooks/checkHooks";
2025-03-17 01:16:42 +05:30
import { useTranslation } from "react-i18next";
2025-01-27 14:55:55 -08:00
// Constants
const BREADCRUMBS = [
{ name: "uptime", path: "/uptime" },
{ name: "details", path: "" },
// { name: "details", path: `/uptime/${monitorId}` }, Is this needed? We can't click on this anywy
];
const certificateDateFormat = "MMM D, YYYY h A";
const UptimeDetails = () => {
// Redux state
const uiTimezone = useSelector((state) => state.ui.timezone);
// Local state
2025-03-05 11:24:02 -08:00
const [dateRange, setDateRange] = useState("recent");
2025-01-27 14:55:55 -08:00
const [page, setPage] = useState(0);
const [rowsPerPage, setRowsPerPage] = useState(5);
2025-05-15 10:51:06 -07:00
const [trigger, setTrigger] = useState(false);
2024-09-12 12:17:31 +08:00
2025-01-27 14:55:55 -08:00
// Utils
2025-03-05 11:24:02 -08:00
const dateFormat =
dateRange === "day" || dateRange === "recent" ? "MMM D, h A" : "MMM D";
2025-01-27 14:55:55 -08:00
const { monitorId } = useParams();
const theme = useTheme();
const isAdmin = useIsAdmin();
2025-03-17 01:16:42 +05:30
const { t } = useTranslation();
2024-07-10 10:10:02 -07:00
2025-03-19 12:15:04 -07:00
const [monitorData, monitorStats, monitorIsLoading, monitorNetworkError] =
2025-06-12 12:44:46 +08:00
useFetchUptimeMonitorById({
2025-03-19 12:15:04 -07:00
monitorId,
dateRange,
2025-05-15 10:51:06 -07:00
trigger,
2025-03-19 12:15:04 -07:00
});
const monitor = monitorData?.monitor;
2024-09-02 17:10:42 -04:00
2025-02-01 08:13:21 -08:00
const [certificateExpiry, certificateIsLoading] = useCertificateFetch({
2025-01-27 14:55:55 -08:00
monitor,
monitorId,
certificateDateFormat,
uiTimezone,
});
2024-09-02 17:10:42 -04:00
2025-03-11 03:23:04 +05:30
const monitorType = monitor?.type;
2025-06-12 15:47:59 +08:00
2025-06-12 12:44:46 +08:00
const [checks, checksCount, checksAreLoading, checksNetworkError] = useFetchChecks({
2025-01-27 14:55:55 -08:00
monitorId,
2025-06-12 15:47:59 +08:00
type: monitorType,
sortOrder: "desc",
limit: null,
2025-01-27 14:55:55 -08:00
dateRange,
2025-06-12 15:47:59 +08:00
filter: null,
2025-01-27 14:55:55 -08:00
page,
rowsPerPage,
});
2025-01-27 14:55:55 -08:00
// Handlers
2025-05-15 10:51:06 -07:00
const triggerUpdate = () => {
setTrigger(!trigger);
};
2025-01-27 14:55:55 -08:00
const handlePageChange = (_, newPage) => {
setPage(newPage);
2024-10-16 11:45:05 +08:00
};
2025-01-27 14:55:55 -08:00
const handleChangeRowsPerPage = (event) => {
setRowsPerPage(event.target.value);
};
2024-09-04 12:57:08 -04:00
2025-02-01 08:13:21 -08:00
if (monitorNetworkError || checksNetworkError) {
return (
<GenericFallback>
<Typography
variant="h1"
marginY={theme.spacing(4)}
color={theme.palette.primary.contrastTextTertiary}
>
2025-06-07 19:30:55 +02:00
{t("common.toasts.networkError")}
2025-02-01 08:13:21 -08:00
</Typography>
2025-06-07 19:30:55 +02:00
<Typography>{t("common.toasts.checkConnection")}</Typography>
2025-02-01 08:13:21 -08:00
</GenericFallback>
);
}
2025-01-31 10:12:06 -08:00
// Empty view, displayed when loading is complete and there are no checks
2025-01-31 07:32:49 -08:00
if (!monitorIsLoading && !checksAreLoading && checksCount === 0) {
return (
2025-01-31 10:12:06 -08:00
<Stack gap={theme.spacing(10)}>
<Breadcrumbs list={BREADCRUMBS} />
2025-05-15 10:51:06 -07:00
<MonitorDetailsControlHeader
2025-01-31 10:12:06 -08:00
path={"uptime"}
isAdmin={isAdmin}
2025-05-15 10:51:06 -07:00
isLoading={monitorIsLoading}
2025-01-31 10:12:06 -08:00
monitor={monitor}
2025-05-15 10:51:06 -07:00
triggerUpdate={triggerUpdate}
2025-01-31 10:12:06 -08:00
/>
<GenericFallback>
2025-03-17 01:16:42 +05:30
<Typography>{t("distributedUptimeDetailsNoMonitorHistory")}</Typography>
2025-01-31 10:12:06 -08:00
</GenericFallback>
</Stack>
2025-01-31 07:32:49 -08:00
);
}
2024-10-16 11:45:05 +08:00
return (
2025-01-27 14:55:55 -08:00
<Stack gap={theme.spacing(10)}>
<Breadcrumbs list={BREADCRUMBS} />
2025-05-15 10:51:06 -07:00
<MonitorDetailsControlHeader
2025-01-31 10:12:06 -08:00
path={"uptime"}
2025-01-27 14:55:55 -08:00
isAdmin={isAdmin}
2025-03-19 12:15:04 -07:00
isLoading={monitorIsLoading}
2025-01-27 14:55:55 -08:00
monitor={monitor}
2025-05-15 10:51:06 -07:00
triggerUpdate={triggerUpdate}
2025-01-27 14:55:55 -08:00
/>
<UptimeStatusBoxes
2025-03-19 12:15:04 -07:00
isLoading={monitorIsLoading}
2025-01-27 14:55:55 -08:00
monitor={monitor}
2025-03-19 12:15:04 -07:00
monitorStats={monitorStats}
2025-01-27 14:55:55 -08:00
certificateExpiry={certificateExpiry}
/>
<MonitorTimeFrameHeader
2025-03-19 12:15:04 -07:00
isLoading={monitorIsLoading}
hasDateRange={true}
2025-01-27 14:55:55 -08:00
dateRange={dateRange}
setDateRange={setDateRange}
/>
<ChartBoxes
2025-03-19 12:15:04 -07:00
isLoading={monitorIsLoading}
monitorData={monitorData}
2025-01-27 14:55:55 -08:00
uiTimezone={uiTimezone}
dateRange={dateRange}
dateFormat={dateFormat}
/>
<ResponseTimeChart
2025-03-19 12:15:04 -07:00
isLoading={monitorIsLoading}
groupedChecks={monitorData?.groupedChecks}
2025-01-27 14:55:55 -08:00
dateRange={dateRange}
/>
<ResponseTable
2025-03-19 12:15:04 -07:00
isLoading={checksAreLoading}
2025-01-27 14:55:55 -08:00
checks={checks}
uiTimezone={uiTimezone}
page={page}
setPage={handlePageChange}
rowsPerPage={rowsPerPage}
setRowsPerPage={handleChangeRowsPerPage}
checksCount={checksCount}
/>
</Stack>
2024-10-16 11:45:05 +08:00
);
2024-07-05 19:51:07 -07:00
};
2025-01-27 14:55:55 -08:00
export default UptimeDetails;