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

141 lines
3.9 KiB
React
Raw Normal View History

2025-01-30 14:27:11 -08:00
// Components
import { Stack, Typography } from "@mui/material";
import Breadcrumbs from "../../../Components/Breadcrumbs";
import MonitorCountHeader from "../../../Components/MonitorCountHeader";
import MonitorCreateHeader from "../../../Components/MonitorCreateHeader";
import MonitorsTable from "./Components/MonitorsTable";
import Pagination from "../../..//Components/Table/TablePagination";
import GenericFallback from "../../../Components/GenericFallback";
import Fallback from "../../../Components/Fallback";
2025-04-15 00:17:11 +05:30
import Filter from "./Components/Filters";
import SearchComponent from "./Components/SearchComponent";
2025-01-30 14:27:11 -08:00
// Utils
import { useTheme } from "@emotion/react";
import { useMonitorFetch } from "./Hooks/useMonitorFetch";
import { useState } from "react";
import { useIsAdmin } from "../../../Hooks/useIsAdmin";
2025-03-12 00:56:28 +05:30
import { useTranslation } from "react-i18next";
2025-01-30 14:27:11 -08:00
// Constants
const BREADCRUMBS = [{ name: `infrastructure`, path: "/infrastructure" }];
const InfrastructureMonitors = () => {
// Redux state
const [page, setPage] = useState(0);
const [rowsPerPage, setRowsPerPage] = useState(5);
const [updateTrigger, setUpdateTrigger] = useState(false);
2025-04-15 00:17:11 +05:30
const [selectedStatus, setSelectedStatus] = useState(undefined);
const [toFilterStatus, setToFilterStatus] = useState(undefined);
const [search, setSearch] = useState(undefined);
const [isSearching, setIsSearching] = useState(false);
2025-01-30 14:27:11 -08:00
// Utils
const theme = useTheme();
const isAdmin = useIsAdmin();
2025-03-12 00:56:28 +05:30
const { t } = useTranslation();
2025-01-30 14:27:11 -08:00
// Handlers
const handleActionMenuDelete = () => {
setUpdateTrigger(!updateTrigger);
};
const handleChangePage = (event, newPage) => {
setPage(newPage);
};
const handleChangeRowsPerPage = (event) => {
setRowsPerPage(event.target.value);
};
2025-04-15 00:17:11 +05:30
const handleReset = () => {
setSelectedStatus(undefined);
setToFilterStatus(undefined);
};
const field = toFilterStatus !== undefined ? "status" : undefined;
2025-01-30 14:27:11 -08:00
const { monitors, summary, isLoading, networkError } = useMonitorFetch({
page,
2025-04-15 00:17:11 +05:30
field: field,
filter: toFilterStatus,
2025-01-30 14:27:11 -08:00
rowsPerPage,
updateTrigger,
search
2025-01-30 14:27:11 -08:00
});
if (networkError === true) {
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-01-30 14:27:11 -08:00
</Typography>
2025-06-07 19:30:55 +02:00
<Typography>{t("common.toasts.checkConnection")}</Typography>
2025-01-30 14:27:11 -08:00
</GenericFallback>
);
}
2025-05-27 09:10:32 -07:00
if (!isLoading && typeof summary?.totalMonitors === "undefined") {
2025-01-30 14:27:11 -08:00
return (
<Fallback
vowelStart={true}
title="infrastructure monitor"
checks={[
"Track the performance of your servers",
"Identify bottlenecks and optimize usage",
"Ensure reliability with real-time monitoring",
]}
link="/infrastructure/create"
isAdmin={isAdmin}
/>
);
}
return (
<Stack gap={theme.spacing(10)}>
<Breadcrumbs list={BREADCRUMBS} />
<MonitorCreateHeader
isAdmin={isAdmin}
2025-05-06 22:52:56 +05:30
isLoading={isLoading}
2025-01-30 14:27:11 -08:00
path="/infrastructure/create"
/>
2025-04-27 12:46:54 +05:30
<Stack direction={"row"}>
<MonitorCountHeader
shouldRender={!isLoading}
monitorCount={summary?.totalMonitors ?? 0}
/>
<Filter
selectedStatus={selectedStatus}
setSelectedStatus={setSelectedStatus}
setToFilterStatus={setToFilterStatus}
handleReset={handleReset}
/>
<SearchComponent
monitors={monitors}
onSearchChange={setSearch}
setIsSearching={setIsSearching}
/>
2025-04-27 12:46:54 +05:30
</Stack>
2025-01-30 14:27:11 -08:00
<MonitorsTable
shouldRender={!isLoading}
monitors={monitors}
isAdmin={isAdmin}
handleActionMenuDelete={handleActionMenuDelete}
isSearching={isSearching}
2025-01-30 14:27:11 -08:00
/>
<Pagination
itemCount={summary?.totalMonitors}
2025-03-12 00:56:28 +05:30
paginationLabel={t("monitors")}
2025-01-30 14:27:11 -08:00
page={page}
rowsPerPage={rowsPerPage}
handleChangePage={handleChangePage}
handleChangeRowsPerPage={handleChangeRowsPerPage}
/>
</Stack>
);
};
export default InfrastructureMonitors;