Files
Checkmate/src/Pages/DistributedUptimeStatus/Status/index.jsx
T

260 lines
7.2 KiB
React
Raw Normal View History

2025-02-07 14:51:29 -08:00
//Components
2025-02-10 13:44:43 -08:00
import DistributedUptimeMap from "../../DistributedUptime/Details/Components/DistributedUptimeMap";
2025-02-07 14:51:29 -08:00
import Breadcrumbs from "../../../Components/Breadcrumbs";
import { Stack, Typography } from "@mui/material";
2025-02-10 13:44:43 -08:00
import DeviceTicker from "../../DistributedUptime/Details/Components/DeviceTicker";
import DistributedUptimeResponseChart from "../../DistributedUptime/Details/Components/DistributedUptimeResponseChart";
import NextExpectedCheck from "../../DistributedUptime/Details/Components/NextExpectedCheck";
import Footer from "../../DistributedUptime/Details/Components/Footer";
import StatBoxes from "../../DistributedUptime/Details/Components/StatBoxes";
2025-02-07 14:51:29 -08:00
import ControlsHeader from "../../StatusPage/Status/Components/ControlsHeader";
import MonitorTimeFrameHeader from "../../../Components/MonitorTimeFrameHeader";
import GenericFallback from "../../../Components/GenericFallback";
import Dialog from "../../../Components/Dialog";
import SkeletonLayout from "./Components/Skeleton";
2025-02-20 19:02:33 -08:00
import UptLogo from "../../../assets/icons/upt_logo.png";
import PeopleAltOutlinedIcon from "@mui/icons-material/PeopleAltOutlined";
import InfoBox from "../../../Components/InfoBox";
import StatusHeader from "../../DistributedUptime/Details/Components/StatusHeader";
2025-02-21 15:06:11 -08:00
import MonitorsList from "./Components/MonitorsList";
2025-02-20 19:02:33 -08:00
2025-02-07 14:51:29 -08:00
//Utils
import { useTheme } from "@mui/material/styles";
2025-02-20 19:02:33 -08:00
import { useState, useRef } from "react";
2025-02-07 14:51:29 -08:00
import { useParams } from "react-router-dom";
2025-02-10 13:44:43 -08:00
import { useSubscribeToDetails } from "../../DistributedUptime/Details/Hooks/useSubscribeToDetails";
2025-02-07 14:51:29 -08:00
import { useStatusPageFetchByUrl } from "./Hooks/useStatusPageFetchByUrl";
import { useStatusPageDelete } from "../../StatusPage/Status/Hooks/useStatusPageDelete";
2025-02-21 15:06:11 -08:00
import TimeFrameHeader from "./Components/TimeframeHeader";
import SubHeader from "../../../Components/Subheader";
import { useNavigate, useLocation } from "react-router-dom";
import { useTranslation } from "react-i18next";
2025-02-21 11:23:38 -08:00
2025-02-07 14:51:29 -08:00
const DistributedUptimeStatus = () => {
const { url } = useParams();
const location = useLocation();
const { t } = useTranslation();
2025-02-10 13:44:43 -08:00
const isPublic = location.pathname.startsWith("/status/distributed/public");
2025-02-20 19:02:33 -08:00
const elementToCapture = useRef(null);
2025-02-07 14:51:29 -08:00
// Local State
const [dateRange, setDateRange] = useState("day");
const [isDeleteOpen, setIsDeleteOpen] = useState(false);
2025-02-21 15:06:11 -08:00
const [timeFrame, setTimeFrame] = useState(30);
2025-02-07 14:51:29 -08:00
// Utils
const theme = useTheme();
const navigate = useNavigate();
2025-02-21 11:23:38 -08:00
2025-02-08 08:05:16 -08:00
const [
statusPageIsLoading,
statusPageNetworkError,
statusPage,
monitorId,
isPublished,
] = useStatusPageFetchByUrl({
url,
2025-02-21 15:06:11 -08:00
timeFrame,
2025-02-08 08:05:16 -08:00
});
2025-02-07 14:51:29 -08:00
const [isLoading, networkError, connectionStatus, monitor, lastUpdateTrigger] =
2025-02-08 08:05:16 -08:00
useSubscribeToDetails({ monitorId, dateRange, isPublic, isPublished });
2025-02-07 14:51:29 -08:00
const [deleteStatusPage, isDeleting] = useStatusPageDelete(() => {
navigate("/distributed-uptime");
}, url);
// Constants
const BREADCRUMBS = [
{ name: "Distributed Uptime", path: "/distributed-uptime" },
{ name: "details", path: `/distributed-uptime/${monitorId}` },
2025-02-07 14:51:29 -08:00
{ name: "status", path: `` },
];
let sx = {};
if (isPublic) {
sx = {
paddingTop: "10vh",
paddingRight: "10vw",
paddingBottom: "10vh",
paddingLeft: "10vw",
};
}
2025-02-08 08:05:16 -08:00
// Done loading, a status page doesn't exist
if (!statusPageIsLoading && typeof statusPage === "undefined") {
return (
<Stack sx={sx}>
<GenericFallback>
<Typography
variant="h1"
marginY={theme.spacing(4)}
color={theme.palette.primary.contrastTextTertiary}
>
2025-02-11 22:25:58 -08:00
A status page is not set up.
2025-02-08 08:05:16 -08:00
</Typography>
2025-02-11 22:25:58 -08:00
<Typography>Please contact your administrator</Typography>
2025-02-08 08:05:16 -08:00
</GenericFallback>
</Stack>
);
}
// Done loading, a status page exists but is not public
2025-02-10 13:44:43 -08:00
if (!statusPageIsLoading && isPublic && statusPage.isPublished === false) {
2025-02-08 08:05:16 -08:00
return (
<Stack sx={sx}>
<GenericFallback>
<Typography>This status page is not public.</Typography>
</GenericFallback>
</Stack>
);
}
if (isLoading || statusPageIsLoading) {
return <SkeletonLayout />;
}
if (networkError || statusPageNetworkError) {
2025-02-07 14:51:29 -08:00
return (
<GenericFallback>
<Typography
variant="h1"
marginY={theme.spacing(4)}
color={theme.palette.primary.contrastTextTertiary}
>
Network error
</Typography>
<Typography>Please check your connection</Typography>
</GenericFallback>
);
}
if (
typeof statusPage === "undefined" ||
typeof monitor === "undefined" ||
monitor.totalChecks === 0
) {
2025-02-07 14:51:29 -08:00
return (
<Stack gap={theme.spacing(10)}>
<Breadcrumbs list={BREADCRUMBS} />
<GenericFallback>
<Typography>There is no check history for this monitor yet.</Typography>
</GenericFallback>
</Stack>
);
}
return (
<Stack
2025-02-20 19:02:33 -08:00
ref={elementToCapture}
2025-02-07 14:51:29 -08:00
direction="column"
gap={theme.spacing(10)}
2025-02-20 19:02:33 -08:00
sx={{
...sx,
}}
2025-02-07 14:51:29 -08:00
>
{!isPublic && <Breadcrumbs list={BREADCRUMBS} />}
2025-02-07 14:51:29 -08:00
<ControlsHeader
shouldShow={!isPublic}
2025-02-07 14:51:29 -08:00
statusPage={statusPage}
isDeleting={isDeleting}
isDeleteOpen={isDeleteOpen}
setIsDeleteOpen={setIsDeleteOpen}
2025-02-10 13:44:43 -08:00
url={url}
type="distributed"
2025-02-07 14:51:29 -08:00
/>
2025-02-20 19:02:33 -08:00
<StatusHeader
2025-02-07 14:51:29 -08:00
monitor={monitor}
2025-02-20 19:02:33 -08:00
connectionStatus={connectionStatus}
elementToCapture={elementToCapture}
2025-02-07 14:51:29 -08:00
/>
<SubHeader
headerText={t("distributedStatusHeaderText")}
subHeaderText={t("distributedStatusSubHeaderText")}
rightCatagoryTitle={t("distributedRightCatagoryTitle")}
rightDescription = {t("distributedRightCatagoryDescription")}
/>
2025-02-20 19:02:33 -08:00
2025-02-07 14:51:29 -08:00
<NextExpectedCheck
lastUpdateTime={monitor?.timeSinceLastCheck ?? 0}
interval={monitor?.interval ?? 0}
trigger={lastUpdateTrigger}
/>
<MonitorTimeFrameHeader
dateRange={dateRange}
setDateRange={setDateRange}
/>
<Stack
direction="row"
gap={theme.spacing(8)}
>
<DistributedUptimeMap
checks={monitor?.groupedMapChecks ?? []}
height={"100%"}
2025-02-20 19:02:33 -08:00
width={"50%"}
2025-02-07 14:51:29 -08:00
/>
2025-02-20 19:02:33 -08:00
<Stack
width={"50%"}
gap={theme.spacing(8)}
>
<Stack
direction="row"
gap={theme.spacing(8)}
>
<InfoBox
heading="Devices"
subHeading={monitor?.totalChecks ?? 0}
icon={PeopleAltOutlinedIcon}
alt="Upt Logo"
sx={{ width: "50%" }}
/>
<InfoBox
heading="UPT Burned"
subHeading={monitor?.totalUptBurnt ?? 0}
img={UptLogo}
alt="Upt Logo"
sx={{ width: "50%" }}
/>
</Stack>
<DeviceTicker
data={monitor?.latestChecks ?? []}
connectionStatus={connectionStatus}
/>
</Stack>
2025-02-07 14:51:29 -08:00
</Stack>
2025-02-20 19:02:33 -08:00
<DistributedUptimeResponseChart checks={monitor?.groupedChecks ?? []} />
<StatBoxes
monitor={monitor}
lastUpdateTrigger={lastUpdateTrigger}
/>
2025-02-21 15:06:11 -08:00
<TimeFrameHeader
timeFrame={timeFrame}
setTimeFrame={setTimeFrame}
/>
<MonitorsList
monitors={statusPage?.subMonitors}
timeFrame={timeFrame}
/>
2025-02-07 14:51:29 -08:00
<Footer />
<Dialog
// open={isOpen.deleteStats}
title="Do you want to delete this status page?"
onConfirm={() => {
deleteStatusPage();
setIsDeleteOpen(false);
}}
onCancel={() => {
setIsDeleteOpen(false);
}}
open={isDeleteOpen}
confirmationButtonLabel="Yes, delete status page"
description="Once deleted, your status page cannot be retrieved."
isLoading={isDeleting || isLoading}
/>
</Stack>
);
};
export default DistributedUptimeStatus;