Files
Checkmate/src/Pages/DistributedUptime/Monitors/index.jsx
T

98 lines
2.7 KiB
React
Raw Normal View History

2025-02-05 13:31:41 -08:00
// Components
2025-02-06 14:57:28 -08:00
import { Stack, Typography } from "@mui/material";
2025-02-05 13:59:56 -08:00
import Breadcrumbs from "../../../Components/Breadcrumbs";
2025-02-06 14:57:28 -08:00
import CreateMonitorHeader from "../../../Components/MonitorCreateHeader";
import MonitorTable from "./Components/MonitorTable";
2025-02-28 14:31:58 -08:00
import Pagination from "../../../Components/Table/TablePagination";
2025-02-06 14:57:28 -08:00
import Fallback from "../../../Components/Fallback";
import GenericFallback from "../../../Components/GenericFallback";
2025-02-05 13:31:41 -08:00
// Utils
2025-02-28 14:31:58 -08:00
import { useState } from "react";
2025-02-05 13:31:41 -08:00
import { useTheme } from "@mui/material/styles";
2025-02-06 14:57:28 -08:00
import { useIsAdmin } from "../../../Hooks/useIsAdmin";
import { useSubscribeToMonitors } from "./Hooks/useSubscribeToMonitors";
import SkeletonLayout from "./Components/Skeleton";
2025-02-05 13:31:41 -08:00
// Constants
const BREADCRUMBS = [{ name: `Distributed Uptime`, path: "/distributed-uptime" }];
const DistributedUptimeMonitors = () => {
// Local state
2025-02-28 14:31:58 -08:00
const [page, setPage] = useState(0);
const [rowsPerPage, setRowsPerPage] = useState(10);
2025-02-05 13:31:41 -08:00
// Utils
const theme = useTheme();
2025-02-06 14:57:28 -08:00
const isAdmin = useIsAdmin();
const [isLoading, networkError, monitors, monitorsSummary, filteredMonitors] =
2025-02-28 14:31:58 -08:00
useSubscribeToMonitors(page, rowsPerPage);
// Handlers
const handleChangePage = (event, newPage) => {
setPage(newPage);
};
const handleChangeRowsPerPage = (event) => {
setRowsPerPage(event.target.value);
setPage(0);
};
2025-02-05 13:31:41 -08:00
if (isLoading) {
return <SkeletonLayout />;
}
2025-02-06 14:57:28 -08:00
if (networkError) {
return (
<GenericFallback>
<Typography
variant="h1"
marginY={theme.spacing(4)}
color={theme.palette.primary.contrastTextTertiary}
>
Network error
</Typography>
<Typography>Please check your connection</Typography>
</GenericFallback>
);
}
2025-02-05 13:31:41 -08:00
if (typeof monitorsSummary === "undefined" || monitorsSummary.totalMonitors === 0) {
2025-02-06 14:57:28 -08:00
return (
<Fallback
vowelStart={false}
title="distributed uptime monitor"
checks={[
2025-02-06 16:08:26 -08:00
"Check if a server is online from multiple locations",
"Detect outages and performance issues in real time",
"Reduce false alarms by verifying downtime from different networks",
"Provide insights on regional availability and latency",
2025-02-06 14:57:28 -08:00
]}
link="/distributed-uptime/create"
isAdmin={isAdmin}
/>
);
}
2025-02-05 13:31:41 -08:00
return (
2025-02-06 14:57:28 -08:00
<Stack gap={theme.spacing(10)}>
2025-02-05 13:31:41 -08:00
<Breadcrumbs list={BREADCRUMBS} />
2025-02-06 14:57:28 -08:00
<CreateMonitorHeader
isAdmin={isAdmin}
shouldRender={!isLoading}
path="/distributed-uptime/create"
/>
<MonitorTable
isLoading={isLoading}
monitors={filteredMonitors}
/>
2025-02-28 14:31:58 -08:00
<Pagination
itemCount={monitorsSummary?.totalMonitors ?? 0}
paginationLabel="monitors"
page={page}
rowsPerPage={rowsPerPage}
handleChangePage={handleChangePage}
handleChangeRowsPerPage={handleChangeRowsPerPage}
/>
2025-02-05 13:31:41 -08:00
</Stack>
);
};
export default DistributedUptimeMonitors;