diff --git a/client/src/Components/Dialog/index.jsx b/client/src/Components/Dialog/index.jsx index e07597df4..678eb8721 100644 --- a/client/src/Components/Dialog/index.jsx +++ b/client/src/Components/Dialog/index.jsx @@ -57,7 +57,7 @@ Dialog.propTypes = { onCancel: PropTypes.func.isRequired, confirmationButtonLabel: PropTypes.string.isRequired, onConfirm: PropTypes.func.isRequired, - isLoading: PropTypes.bool.isRequired, + isLoading: PropTypes.bool, }; export default Dialog; diff --git a/client/src/Components/StatBox/index.jsx b/client/src/Components/StatBox/index.jsx index 93fa46c2b..7d093de60 100644 --- a/client/src/Components/StatBox/index.jsx +++ b/client/src/Components/StatBox/index.jsx @@ -136,8 +136,8 @@ const StatBox = ({ }; StatBox.propTypes = { - heading: PropTypes.string.isRequired, - subHeading: PropTypes.node.isRequired, + heading: PropTypes.string, + subHeading: PropTypes.node, gradient: PropTypes.bool, status: PropTypes.string, sx: PropTypes.object, 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/Infrastructure/Monitors/Components/MonitorsTable/index.jsx b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTable/index.jsx index 761ecaa0e..7a5db231f 100644 --- a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTable/index.jsx +++ b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTable/index.jsx @@ -15,7 +15,7 @@ import { useNavigate } from "react-router-dom"; import PropTypes from "prop-types"; import { useTranslation } from "react-i18next"; -const MonitorsTable = ({ shouldRender, monitors, isAdmin, handleActionMenuDelete }) => { +const MonitorsTable = ({ isLoading, monitors, isAdmin, handleActionMenuDelete }) => { // Utils const theme = useTheme(); const { t } = useTranslation(); @@ -86,6 +86,7 @@ const MonitorsTable = ({ shouldRender, monitors, isAdmin, handleActionMenuDelete monitor={row} isAdmin={isAdmin} updateCallback={handleActionMenuDelete} + isLoading={isLoading} /> ), }, @@ -120,7 +121,7 @@ const MonitorsTable = ({ shouldRender, monitors, isAdmin, handleActionMenuDelete return ( { const [isOpen, setIsOpen] = useState(false); const [isDialogOpen, setIsDialogOpen] = useState(false); const theme = useTheme(); - const { isLoading } = useSelector((state) => state.uptimeMonitors); const openMenu = (e) => { e.stopPropagation(); @@ -117,7 +115,6 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { onCancel={cancelRemove} confirmationButtonLabel="Delete" onConfirm={handleRemove} - isLoading={isLoading} modelTitle="modal-delete-monitor" modelDescription="delete-monitor-confirmation" /> diff --git a/client/src/Pages/Infrastructure/Monitors/index.jsx b/client/src/Pages/Infrastructure/Monitors/index.jsx index 6d49f64a7..6b726309c 100644 --- a/client/src/Pages/Infrastructure/Monitors/index.jsx +++ b/client/src/Pages/Infrastructure/Monitors/index.jsx @@ -11,7 +11,6 @@ import Filter from "./Components/Filters"; // Utils import { useTheme } from "@emotion/react"; import { useState } from "react"; -import { useSelector } from "react-redux"; import { useIsAdmin } from "../../../Hooks/useIsAdmin"; import { useTranslation } from "react-i18next"; import { useFetchMonitorsByTeamId } from "../../../Hooks/monitorHooks"; @@ -21,7 +20,6 @@ const BREADCRUMBS = [{ name: `infrastructure`, path: "/infrastructure" }]; const InfrastructureMonitors = () => { // Redux state - const { user } = useSelector((state) => state.auth); // Local state const [page, setPage] = useState(0); @@ -56,7 +54,6 @@ const InfrastructureMonitors = () => { const field = toFilterStatus !== undefined ? "status" : undefined; const [monitors, summary, isLoading, networkError] = useFetchMonitorsByTeamId({ - teamId: user.teamId, limit: 1, types: TYPES, page, @@ -118,7 +115,7 @@ const InfrastructureMonitors = () => { /> { setIsLoading(true); try { const response = await networkService.getMonitorsByTeamId({ - teamId: user.teamId, limit: null, types: ["http", "ping", "pagespeed", "port"], }); diff --git a/client/src/Pages/PageSpeed/Monitors/index.jsx b/client/src/Pages/PageSpeed/Monitors/index.jsx index dc1772227..65e43f2ec 100644 --- a/client/src/Pages/PageSpeed/Monitors/index.jsx +++ b/client/src/Pages/PageSpeed/Monitors/index.jsx @@ -9,7 +9,6 @@ import GenericFallback from "../../../Components/GenericFallback"; // Utils import { useTheme } from "@emotion/react"; -import { useSelector } from "react-redux"; import { useIsAdmin } from "../../../Hooks/useIsAdmin"; import { useTranslation } from "react-i18next"; import { useFetchMonitorsByTeamId } from "../../../Hooks/monitorHooks"; @@ -20,10 +19,8 @@ const PageSpeed = () => { const theme = useTheme(); const { t } = useTranslation(); const isAdmin = useIsAdmin(); - const { user } = useSelector((state) => state.auth); const [monitors, monitorsSummary, isLoading, networkError] = useFetchMonitorsByTeamId({ - teamId: user.teamId, limit: 10, types: TYPES, page: null, 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/Create/index.jsx b/client/src/Pages/Uptime/Create/index.jsx index f481e81ac..184beffe5 100644 --- a/client/src/Pages/Uptime/Create/index.jsx +++ b/client/src/Pages/Uptime/Create/index.jsx @@ -28,7 +28,6 @@ import { useCreateMonitor } from "../../../Hooks/monitorHooks"; const CreateMonitor = () => { // Redux state const { user } = useSelector((state) => state.auth); - const { isLoading } = useSelector((state) => state.uptimeMonitors); // Local state const [errors, setErrors] = useState({}); @@ -467,7 +466,7 @@ const CreateMonitor = () => { variant="contained" color="accent" disabled={!Object.values(errors).every((value) => value === undefined)} - loading={isLoading || isCreating} + loading={isCreating} > {t("createMonitor")} 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", + }, + }); } // ************************************ diff --git a/server/db/mongo/modules/monitorModule.js b/server/db/mongo/modules/monitorModule.js index 3d9adab39..b6044f2c9 100755 --- a/server/db/mongo/modules/monitorModule.js +++ b/server/db/mongo/modules/monitorModule.js @@ -519,7 +519,8 @@ const getMonitorsByTeamId = async (req) => { order = "asc"; } // Build match stage - const matchStage = { teamId: ObjectId.createFromHexString(req.params.teamId) }; + const teamId = req.user.teamId; + const matchStage = { teamId: ObjectId.createFromHexString(teamId) }; if (type !== undefined) { matchStage.type = Array.isArray(type) ? { $in: type } : type; } @@ -560,7 +561,7 @@ const getMonitorsByTeamId = async (req) => { const getMonitorsAndSummaryByTeamId = async (req) => { try { const { type } = req.query; - const teamId = ObjectId.createFromHexString(req.params.teamId); + const teamId = ObjectId.createFromHexString(req.user.teamId); const matchStage = { teamId }; if (type !== undefined) { matchStage.type = Array.isArray(type) ? { $in: type } : type; @@ -594,7 +595,7 @@ const getMonitorsWithChecksByTeamId = async (req) => { field = "name"; order = "asc"; } - const teamId = ObjectId.createFromHexString(req.params.teamId); + const teamId = ObjectId.createFromHexString(req.user.teamId); // Build match stage const matchStage = { teamId }; if (type !== undefined) { diff --git a/server/routes/monitorRoute.js b/server/routes/monitorRoute.js index 6d1db90ad..0dabab407 100755 --- a/server/routes/monitorRoute.js +++ b/server/routes/monitorRoute.js @@ -35,17 +35,17 @@ class MonitorRoutes { fetchMonitorCertificate ); }); + this.router.get("/team", this.monitorController.getMonitorsByTeamId); + this.router.get("/:monitorId", this.monitorController.getMonitorById); - this.router.get("/team/:teamId", this.monitorController.getMonitorsByTeamId); - this.router.get( - "/summary/team/:teamId", + "/summary/team", this.monitorController.getMonitorsAndSummaryByTeamId ); this.router.get( - "/team/:teamId/with-checks", + "/team/with-checks", this.monitorController.getMonitorsWithChecksByTeamId ); diff --git a/server/validation/joi.js b/server/validation/joi.js index 271cd2d21..aba7118d1 100755 --- a/server/validation/joi.js +++ b/server/validation/joi.js @@ -126,9 +126,7 @@ const getMonitorByIdQueryValidation = joi.object({ normalize: joi.boolean(), }); -const getMonitorsByTeamIdParamValidation = joi.object({ - teamId: joi.string().required(), -}); +const getMonitorsByTeamIdParamValidation = joi.object({}); const getMonitorsByTeamIdQueryValidation = joi.object({ limit: joi.number(),