From d9c2f31f4eb4f6fb9b92f09ab93289a8239cab51 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 13 Jun 2025 10:38:52 +0800 Subject: [PATCH] remove teamId from uptime monitor requests --- client/src/Hooks/monitorHooks.js | 11 +--- .../Maintenance/CreateMaintenance/index.jsx | 1 - .../Create/Hooks/useMonitorsFetch.jsx | 1 - client/src/Pages/Uptime/Monitors/index.jsx | 5 -- client/src/Utils/NetworkService.js | 64 ++++--------------- 5 files changed, 16 insertions(+), 66 deletions(-) diff --git a/client/src/Hooks/monitorHooks.js b/client/src/Hooks/monitorHooks.js index e5c405ac1..5072b5594 100644 --- a/client/src/Hooks/monitorHooks.js +++ b/client/src/Hooks/monitorHooks.js @@ -6,7 +6,7 @@ import { useMonitorUtils } from "./useMonitorUtils"; import { useNavigate } from "react-router-dom"; import { useTranslation } from "react-i18next"; -const useFetchMonitorsWithSummary = ({ teamId, types, monitorUpdateTrigger }) => { +const useFetchMonitorsWithSummary = ({ types, monitorUpdateTrigger }) => { const [isLoading, setIsLoading] = useState(false); const [monitors, setMonitors] = useState(undefined); const [monitorsSummary, setMonitorsSummary] = useState(undefined); @@ -17,7 +17,6 @@ const useFetchMonitorsWithSummary = ({ teamId, types, monitorUpdateTrigger }) => try { setIsLoading(true); const res = await networkService.getMonitorsWithSummaryByTeamId({ - teamId, types, }); const { monitors, summary } = res?.data?.data ?? {}; @@ -34,12 +33,11 @@ const useFetchMonitorsWithSummary = ({ teamId, types, monitorUpdateTrigger }) => } }; fetchMonitors(); - }, [teamId, types, monitorUpdateTrigger]); + }, [types, monitorUpdateTrigger]); return [monitors, monitorsSummary, isLoading, networkError]; }; const useFetchMonitorsWithChecks = ({ - teamId, types, limit, page, @@ -61,7 +59,6 @@ const useFetchMonitorsWithChecks = ({ try { setIsLoading(true); const res = await networkService.getMonitorsWithChecksByTeamId({ - teamId, limit, types, page, @@ -95,7 +92,6 @@ const useFetchMonitorsWithChecks = ({ order, page, rowsPerPage, - teamId, theme, types, monitorUpdateTrigger, @@ -104,7 +100,6 @@ const useFetchMonitorsWithChecks = ({ }; const useFetchMonitorsByTeamId = ({ - teamId, types, limit, page, @@ -127,7 +122,6 @@ const useFetchMonitorsByTeamId = ({ try { setIsLoading(true); const res = await networkService.getMonitorsByTeamId({ - teamId, limit, types, page, @@ -154,7 +148,6 @@ const useFetchMonitorsByTeamId = ({ }; fetchMonitors(); }, [ - teamId, types, limit, page, diff --git a/client/src/Pages/Maintenance/CreateMaintenance/index.jsx b/client/src/Pages/Maintenance/CreateMaintenance/index.jsx index f3754c6b0..e71c7112c 100644 --- a/client/src/Pages/Maintenance/CreateMaintenance/index.jsx +++ b/client/src/Pages/Maintenance/CreateMaintenance/index.jsx @@ -135,7 +135,6 @@ const CreateMaintenance = () => { setIsLoading(true); try { const response = await networkService.getMonitorsByTeamId({ - teamId: user.teamId, limit: null, types: ["http", "ping", "pagespeed", "port"], }); diff --git a/client/src/Pages/StatusPage/Create/Hooks/useMonitorsFetch.jsx b/client/src/Pages/StatusPage/Create/Hooks/useMonitorsFetch.jsx index 5c523b635..f380bed9a 100644 --- a/client/src/Pages/StatusPage/Create/Hooks/useMonitorsFetch.jsx +++ b/client/src/Pages/StatusPage/Create/Hooks/useMonitorsFetch.jsx @@ -13,7 +13,6 @@ const useMonitorsFetch = () => { const fetchMonitors = async () => { try { const response = await networkService.getMonitorsByTeamId({ - teamId: user.teamId, limit: null, // donot return any checks for the monitors types: ["http", "ping", "port"], // status page is available for uptime, ping, and port monitors }); diff --git a/client/src/Pages/Uptime/Monitors/index.jsx b/client/src/Pages/Uptime/Monitors/index.jsx index e313d7deb..030ce922c 100644 --- a/client/src/Pages/Uptime/Monitors/index.jsx +++ b/client/src/Pages/Uptime/Monitors/index.jsx @@ -64,7 +64,6 @@ CreateMonitorButton.propTypes = { const UptimeMonitors = () => { // Redux state - const { user } = useSelector((state) => state.auth); const rowsPerPage = useSelector((state) => state.ui.monitors.rowsPerPage); // Local state @@ -106,11 +105,8 @@ const UptimeMonitors = () => { setMonitorUpdateTrigger((prev) => !prev); }, []); - const teamId = user.teamId; - const [monitors, monitorsSummary, monitorsWithSummaryIsLoading, networkError] = useFetchMonitorsWithSummary({ - teamId, types: TYPES, monitorUpdateTrigger, }); @@ -140,7 +136,6 @@ const UptimeMonitors = () => { monitorsWithChecksIsLoading, monitorsWithChecksNetworkError, ] = useFetchMonitorsWithChecks({ - teamId, types: effectiveTypes, limit: 25, page: page, diff --git a/client/src/Utils/NetworkService.js b/client/src/Utils/NetworkService.js index f25828c66..e84596b97 100644 --- a/client/src/Utils/NetworkService.js +++ b/client/src/Utils/NetworkService.js @@ -135,36 +135,6 @@ class NetworkService { }); } - /** - * - * ************************************ - * Gets monitors and summary of stats by TeamID - * ************************************ - * - * @async - * @param {Object} config - The configuration object. - * @param {string} config.teamId - Team ID - * @param {Array} config.types - Array of monitor types - * @returns {Promise} The response from the axios POST request. - */ - async getMonitorsSummaryByTeamId(config) { - const params = new URLSearchParams(); - - if (config.types) { - config.types.forEach((type) => { - params.append("type", type); - }); - } - return this.axiosInstance.get( - `/monitors/team/summary/${config.teamId}?${params.toString()}`, - { - headers: { - "Content-Type": "application/json", - }, - } - ); - } - /** * ************************************ * Get all uptime monitors for a Team @@ -184,7 +154,7 @@ class NetworkService { */ async getMonitorsByTeamId(config) { - const { teamId, limit, types, page, rowsPerPage, filter, field, order } = config; + const { limit, types, page, rowsPerPage, filter, field, order } = config; const params = new URLSearchParams(); if (limit) params.append("limit", limit); @@ -199,7 +169,7 @@ class NetworkService { if (field) params.append("field", field); if (order) params.append("order", order); - return this.axiosInstance.get(`/monitors/team/${teamId}?${params.toString()}`, { + return this.axiosInstance.get(`/monitors/team?${params.toString()}`, { headers: { "Content-Type": "application/json", }, @@ -949,7 +919,7 @@ class NetworkService { // Fetch monitors with summary by TeamID // ************************************ async getMonitorsWithSummaryByTeamId(config) { - const { teamId, types } = config; + const { types } = config; const params = new URLSearchParams(); if (types) { @@ -958,21 +928,18 @@ class NetworkService { }); } - return this.axiosInstance.get( - `/monitors/summary/team/${teamId}?${params.toString()}`, - { - headers: { - "Content-Type": "application/json", - }, - } - ); + return this.axiosInstance.get(`/monitors/summary/team?${params.toString()}`, { + headers: { + "Content-Type": "application/json", + }, + }); } // ************************************ // Fetch monitors with checks by TeamID // ************************************ async getMonitorsWithChecksByTeamId(config) { - const { teamId, limit, types, page, rowsPerPage, filter, field, order } = config; + const { limit, types, page, rowsPerPage, filter, field, order } = config; const params = new URLSearchParams(); if (limit) params.append("limit", limit); @@ -987,14 +954,11 @@ class NetworkService { if (field) params.append("field", field); if (order) params.append("order", order); - return this.axiosInstance.get( - `/monitors/team/${teamId}/with-checks?${params.toString()}`, - { - headers: { - "Content-Type": "application/json", - }, - } - ); + return this.axiosInstance.get(`/monitors/team/with-checks?${params.toString()}`, { + headers: { + "Content-Type": "application/json", + }, + }); } // ************************************