From 176ced29dfe4052af2db4adf224424ad0e23f8f2 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 14 Mar 2025 11:05:33 -0700 Subject: [PATCH] use new hooks --- src/Pages/Uptime/Monitors/index.jsx | 62 +++++++++++++++++------------ 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/src/Pages/Uptime/Monitors/index.jsx b/src/Pages/Uptime/Monitors/index.jsx index 625b1920a..0187d0d34 100644 --- a/src/Pages/Uptime/Monitors/index.jsx +++ b/src/Pages/Uptime/Monitors/index.jsx @@ -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 import Breadcrumbs from "../../../Components/Breadcrumbs"; import Greeting from "../../../Utils/greeting"; @@ -23,9 +28,11 @@ import useMonitorsFetch from "./Hooks/useMonitorsFetch"; import { useSelector, useDispatch } from "react-redux"; import { setRowsPerPage } from "../../../Features/UI/uiSlice"; import PropTypes from "prop-types"; +import useFetchMonitorsWithSummary from "../../../Hooks/useFetchMonitorsWithSummary"; +import useFetchMonitorsWithChecks from "../../../Hooks/useFetchMonitorsWithChecks"; const BREADCRUMBS = [{ name: `Uptime`, path: "/uptime" }]; - +const TYPES = ["http", "ping", "docker", "port"]; const CreateMonitorButton = ({ shouldRender }) => { // Utils const navigate = useNavigate(); @@ -89,23 +96,32 @@ const UptimeMonitors = () => { }, []); const teamId = user.teamId; - const { - monitorsAreLoading, - monitors, - filteredMonitors, - monitorsSummary, - networkError, - } = useMonitorsFetch({ + + const [monitors, monitorsSummary, monitorsWithSummaryIsLoading, networkError] = + useFetchMonitorsWithSummary({ + teamId, + types: TYPES, + }); + + const [ + monitorsWithChecks, + monitorsWithChecksCount, + monitorsWithChecksIsLoading, + monitorsWithChecksNetworkError, + ] = useFetchMonitorsWithChecks({ teamId, + types: TYPES, limit: 25, page: page, rowsPerPage: rowsPerPage, filter: search, field: sort?.field, order: sort?.order, - triggerUpdate: monitorUpdateTrigger, + triggerUpdate, }); - const totalMonitors = monitorsSummary?.totalMonitors; + + const isLoading = monitorsWithSummaryIsLoading || monitorsWithChecksIsLoading; + if (networkError) { return ( @@ -121,8 +137,9 @@ const UptimeMonitors = () => { ); } if ( - !monitorsAreLoading && - (totalMonitors === 0 || typeof totalMonitors === "undefined") + !isLoading && + (monitorsSummary?.totalMonitors === 0 || + typeof monitorsSummary?.totalMonitors === "undefined") ) { return ( { 0 && !monitorsAreLoading} - monitorCount={totalMonitors} + shouldRender={monitors?.length > 0 && !monitorsWithSummaryIsLoading} + monitorCount={monitorsSummary?.totalMonitors} heading={"Uptime monitors"} > {