use new hooks
This commit is contained in:
1 parent
acd3e87330
commit
176ced29df
1 file changed
+37
-25
@@ -1,3 +1,8 @@
|
|||||||
|
// Required Data
|
||||||
|
// 1. Monitor summary
|
||||||
|
// 2. List of monitors filtered by search term with 25 checks each
|
||||||
|
// 2a.List of monitors must have the total number of monitors that match.
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
import Breadcrumbs from "../../../Components/Breadcrumbs";
|
import Breadcrumbs from "../../../Components/Breadcrumbs";
|
||||||
import Greeting from "../../../Utils/greeting";
|
import Greeting from "../../../Utils/greeting";
|
||||||
@@ -23,9 +28,11 @@ import useMonitorsFetch from "./Hooks/useMonitorsFetch";
|
|||||||
import { useSelector, useDispatch } from "react-redux";
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
import { setRowsPerPage } from "../../../Features/UI/uiSlice";
|
import { setRowsPerPage } from "../../../Features/UI/uiSlice";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
|
import useFetchMonitorsWithSummary from "../../../Hooks/useFetchMonitorsWithSummary";
|
||||||
|
import useFetchMonitorsWithChecks from "../../../Hooks/useFetchMonitorsWithChecks";
|
||||||
|
|
||||||
const BREADCRUMBS = [{ name: `Uptime`, path: "/uptime" }];
|
const BREADCRUMBS = [{ name: `Uptime`, path: "/uptime" }];
|
||||||
|
const TYPES = ["http", "ping", "docker", "port"];
|
||||||
const CreateMonitorButton = ({ shouldRender }) => {
|
const CreateMonitorButton = ({ shouldRender }) => {
|
||||||
// Utils
|
// Utils
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -89,23 +96,32 @@ const UptimeMonitors = () => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const teamId = user.teamId;
|
const teamId = user.teamId;
|
||||||
const {
|
|
||||||
monitorsAreLoading,
|
const [monitors, monitorsSummary, monitorsWithSummaryIsLoading, networkError] =
|
||||||
monitors,
|
useFetchMonitorsWithSummary({
|
||||||
filteredMonitors,
|
teamId,
|
||||||
monitorsSummary,
|
types: TYPES,
|
||||||
networkError,
|
});
|
||||||
} = useMonitorsFetch({
|
|
||||||
|
const [
|
||||||
|
monitorsWithChecks,
|
||||||
|
monitorsWithChecksCount,
|
||||||
|
monitorsWithChecksIsLoading,
|
||||||
|
monitorsWithChecksNetworkError,
|
||||||
|
] = useFetchMonitorsWithChecks({
|
||||||
teamId,
|
teamId,
|
||||||
|
types: TYPES,
|
||||||
limit: 25,
|
limit: 25,
|
||||||
page: page,
|
page: page,
|
||||||
rowsPerPage: rowsPerPage,
|
rowsPerPage: rowsPerPage,
|
||||||
filter: search,
|
filter: search,
|
||||||
field: sort?.field,
|
field: sort?.field,
|
||||||
order: sort?.order,
|
order: sort?.order,
|
||||||
triggerUpdate: monitorUpdateTrigger,
|
triggerUpdate,
|
||||||
});
|
});
|
||||||
const totalMonitors = monitorsSummary?.totalMonitors;
|
|
||||||
|
const isLoading = monitorsWithSummaryIsLoading || monitorsWithChecksIsLoading;
|
||||||
|
|
||||||
if (networkError) {
|
if (networkError) {
|
||||||
return (
|
return (
|
||||||
<GenericFallback>
|
<GenericFallback>
|
||||||
@@ -121,8 +137,9 @@ const UptimeMonitors = () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
!monitorsAreLoading &&
|
!isLoading &&
|
||||||
(totalMonitors === 0 || typeof totalMonitors === "undefined")
|
(monitorsSummary?.totalMonitors === 0 ||
|
||||||
|
typeof monitorsSummary?.totalMonitors === "undefined")
|
||||||
) {
|
) {
|
||||||
return (
|
return (
|
||||||
<Fallback
|
<Fallback
|
||||||
@@ -147,19 +164,19 @@ const UptimeMonitors = () => {
|
|||||||
<Breadcrumbs list={BREADCRUMBS} />
|
<Breadcrumbs list={BREADCRUMBS} />
|
||||||
<CreateMonitorHeader
|
<CreateMonitorHeader
|
||||||
isAdmin={isAdmin}
|
isAdmin={isAdmin}
|
||||||
shouldRender={!monitorsAreLoading}
|
shouldRender={!isLoading}
|
||||||
path="/uptime/create"
|
path="/uptime/create"
|
||||||
/>
|
/>
|
||||||
<Greeting type="uptime" />
|
<Greeting type="uptime" />
|
||||||
<StatusBoxes
|
<StatusBoxes
|
||||||
monitorsSummary={monitorsSummary}
|
monitorsSummary={monitorsSummary}
|
||||||
shouldRender={!monitorsAreLoading}
|
shouldRender={!monitorsWithSummaryIsLoading}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Stack direction={"row"}>
|
<Stack direction={"row"}>
|
||||||
<MonitorCountHeader
|
<MonitorCountHeader
|
||||||
shouldRender={monitors?.length > 0 && !monitorsAreLoading}
|
shouldRender={monitors?.length > 0 && !monitorsWithSummaryIsLoading}
|
||||||
monitorCount={totalMonitors}
|
monitorCount={monitorsSummary?.totalMonitors}
|
||||||
heading={"Uptime monitors"}
|
heading={"Uptime monitors"}
|
||||||
></MonitorCountHeader>
|
></MonitorCountHeader>
|
||||||
<SearchComponent
|
<SearchComponent
|
||||||
@@ -170,19 +187,14 @@ const UptimeMonitors = () => {
|
|||||||
</Stack>
|
</Stack>
|
||||||
<UptimeDataTable
|
<UptimeDataTable
|
||||||
isAdmin={isAdmin}
|
isAdmin={isAdmin}
|
||||||
isLoading={monitorsAreLoading}
|
isSearching={isSearching}
|
||||||
filteredMonitors={filteredMonitors}
|
filteredMonitors={monitorsWithChecks}
|
||||||
monitors={monitors}
|
|
||||||
monitorCount={totalMonitors}
|
|
||||||
sort={sort}
|
sort={sort}
|
||||||
setSort={setSort}
|
setSort={setSort}
|
||||||
setSearch={setSearch}
|
monitorsAreLoading={monitorsWithChecksIsLoading}
|
||||||
isSearching={isSearching}
|
|
||||||
monitorsAreLoading={monitorsAreLoading}
|
|
||||||
triggerUpdate={triggerUpdate}
|
|
||||||
/>
|
/>
|
||||||
<Pagination
|
<Pagination
|
||||||
itemCount={totalMonitors}
|
itemCount={monitorsWithChecksCount}
|
||||||
paginationLabel="monitors"
|
paginationLabel="monitors"
|
||||||
page={page}
|
page={page}
|
||||||
rowsPerPage={rowsPerPage}
|
rowsPerPage={rowsPerPage}
|
||||||
|
|||||||
Reference in new issue
Block a user