From 7189c19d55057eb38f704d87e419198626d271ea Mon Sep 17 00:00:00 2001 From: Amol Date: Sat, 14 Jun 2025 16:16:49 +0530 Subject: [PATCH 1/5] feat: add search functionality to infrastructure moniter --- .../Components/LoadingSpinner/index.jsx | 46 +++++++++++++++++ .../Components/MonitorsTable/index.jsx | 40 ++++++++------- .../Components/SearchComponent/index.jsx | 49 +++++++++++++++++++ .../Monitors/Hooks/useDebounce.jsx | 18 +++++++ .../Monitors/Hooks/useMonitorFetch.jsx | 5 +- .../Pages/Infrastructure/Monitors/index.jsx | 11 +++++ client/src/Utils/NetworkService.js | 4 +- server/db/mongo/modules/monitorModule.js | 5 +- server/validation/joi.js | 1 + 9 files changed, 158 insertions(+), 21 deletions(-) create mode 100644 client/src/Pages/Infrastructure/Monitors/Components/LoadingSpinner/index.jsx create mode 100644 client/src/Pages/Infrastructure/Monitors/Components/SearchComponent/index.jsx create mode 100644 client/src/Pages/Infrastructure/Monitors/Hooks/useDebounce.jsx diff --git a/client/src/Pages/Infrastructure/Monitors/Components/LoadingSpinner/index.jsx b/client/src/Pages/Infrastructure/Monitors/Components/LoadingSpinner/index.jsx new file mode 100644 index 000000000..a649473af --- /dev/null +++ b/client/src/Pages/Infrastructure/Monitors/Components/LoadingSpinner/index.jsx @@ -0,0 +1,46 @@ +import { CircularProgress, Box } from "@mui/material"; +import { useTheme } from "@emotion/react"; +import PropTypes from "prop-types"; +const LoadingSpinner = ({ shouldRender }) => { + const theme = useTheme(); + if (shouldRender === false) { + return; + } + + return ( + <> + + + + + + ); +}; + +LoadingSpinner.propTypes = { + shouldRender: PropTypes.bool, +}; + +export default LoadingSpinner; diff --git a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTable/index.jsx b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTable/index.jsx index 0ec435c60..02c32cc8c 100644 --- a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTable/index.jsx +++ b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTable/index.jsx @@ -1,9 +1,11 @@ // Components +import { Box } from "@mui/material"; import DataTable from "../../../../../Components/Table"; import Host from "../../../../../Components/Host"; import { StatusLabel } from "../../../../../Components/Label"; import { Stack } from "@mui/material"; import { InfrastructureMenu } from "../MonitorsTableMenu"; +import LoadingSpinner from "../LoadingSpinner"; // Assets import CPUChipIcon from "../../../../../assets/icons/cpu-chip.svg?react"; import CustomGauge from "../../../../../Components/Charts/CustomGauge"; @@ -15,7 +17,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 = ({ shouldRender, monitors, isAdmin, handleActionMenuDelete, isSearching }) => { // Utils const theme = useTheme(); const { t } = useTranslation(); @@ -119,23 +121,26 @@ const MonitorsTable = ({ shouldRender, monitors, isAdmin, handleActionMenuDelete }); return ( - + + openDetails(row.id), - emptyView: "No monitors found", - }} - /> + onRowClick: (row) => openDetails(row.id), + emptyView: "No monitors found", + }} + /> + ); }; @@ -144,6 +149,7 @@ MonitorsTable.propTypes = { monitors: PropTypes.array, isAdmin: PropTypes.bool, handleActionMenuDelete: PropTypes.func, + isSearching: PropTypes.bool, }; export default MonitorsTable; diff --git a/client/src/Pages/Infrastructure/Monitors/Components/SearchComponent/index.jsx b/client/src/Pages/Infrastructure/Monitors/Components/SearchComponent/index.jsx new file mode 100644 index 000000000..0c6eec854 --- /dev/null +++ b/client/src/Pages/Infrastructure/Monitors/Components/SearchComponent/index.jsx @@ -0,0 +1,49 @@ +import { useState } from "react"; +import Search from "../../../../../Components/Inputs/Search"; +import { Box } from "@mui/material"; +import useDebounce from "../../Hooks/useDebounce"; +import { useEffect, useRef } from "react"; +import PropTypes from "prop-types"; + +const SearchComponent = ({ monitors = [], onSearchChange, setIsSearching }) => { + const isFirstRender = useRef(true); + const [localSearch, setLocalSearch] = useState(""); + const debouncedSearch = useDebounce(localSearch, 500); + useEffect(() => { + if (isFirstRender.current === true) { + isFirstRender.current = false; + return; + } + onSearchChange(debouncedSearch); + setIsSearching(false); + }, [debouncedSearch, onSearchChange, setIsSearching]); + + const handleSearch = (value) => { + setLocalSearch(value); + setIsSearching(true); + }; + + return ( + + + + ); +}; + +SearchComponent.propTypes = { + monitors: PropTypes.array, + onSearchChange: PropTypes.func, + setIsSearching: PropTypes.func, +}; + +export default SearchComponent; diff --git a/client/src/Pages/Infrastructure/Monitors/Hooks/useDebounce.jsx b/client/src/Pages/Infrastructure/Monitors/Hooks/useDebounce.jsx new file mode 100644 index 000000000..fad002e48 --- /dev/null +++ b/client/src/Pages/Infrastructure/Monitors/Hooks/useDebounce.jsx @@ -0,0 +1,18 @@ +import { useState, useEffect } from "react"; + +const useDebounce = (value, delay) => { + const [debouncedValue, setDebouncedValue] = useState(value); + + useEffect(() => { + const handler = setTimeout(() => { + setDebouncedValue(value); + }, delay); + + return () => { + clearTimeout(handler); + }; + }, [value, delay]); + return debouncedValue; +}; + +export default useDebounce; diff --git a/client/src/Pages/Infrastructure/Monitors/Hooks/useMonitorFetch.jsx b/client/src/Pages/Infrastructure/Monitors/Hooks/useMonitorFetch.jsx index 883205c77..2ef725ffd 100644 --- a/client/src/Pages/Infrastructure/Monitors/Hooks/useMonitorFetch.jsx +++ b/client/src/Pages/Infrastructure/Monitors/Hooks/useMonitorFetch.jsx @@ -3,7 +3,7 @@ import { useSelector } from "react-redux"; import { networkService } from "../../../../main"; import { createToast } from "../../../../Utils/toastUtils"; -const useMonitorFetch = ({ page, field, filter, rowsPerPage, updateTrigger }) => { +const useMonitorFetch = ({ page, field, filter, rowsPerPage, updateTrigger, search }) => { // Redux state const { user } = useSelector((state) => state.auth); @@ -24,6 +24,7 @@ const useMonitorFetch = ({ page, field, filter, rowsPerPage, updateTrigger }) => types: ["hardware"], page: page, rowsPerPage: rowsPerPage, + search: search }); setMonitors(response?.data?.data?.filteredMonitors ?? []); setSummary(response?.data?.data?.summary ?? {}); @@ -38,7 +39,7 @@ const useMonitorFetch = ({ page, field, filter, rowsPerPage, updateTrigger }) => }; fetchMonitors(); - }, [page, field, filter, rowsPerPage, user.teamId, updateTrigger]); + }, [page, field, filter, rowsPerPage, user.teamId, updateTrigger, search]); return { monitors, summary, isLoading, networkError }; }; diff --git a/client/src/Pages/Infrastructure/Monitors/index.jsx b/client/src/Pages/Infrastructure/Monitors/index.jsx index bfba843c0..7af0be373 100644 --- a/client/src/Pages/Infrastructure/Monitors/index.jsx +++ b/client/src/Pages/Infrastructure/Monitors/index.jsx @@ -8,6 +8,7 @@ import Pagination from "../../..//Components/Table/TablePagination"; import GenericFallback from "../../../Components/GenericFallback"; import Fallback from "../../../Components/Fallback"; import Filter from "./Components/Filters"; +import SearchComponent from "./Components/SearchComponent"; // Utils import { useTheme } from "@emotion/react"; import { useMonitorFetch } from "./Hooks/useMonitorFetch"; @@ -24,6 +25,8 @@ const InfrastructureMonitors = () => { const [updateTrigger, setUpdateTrigger] = useState(false); const [selectedStatus, setSelectedStatus] = useState(undefined); const [toFilterStatus, setToFilterStatus] = useState(undefined); + const [search, setSearch] = useState(undefined); + const [isSearching, setIsSearching] = useState(false); // Utils const theme = useTheme(); @@ -56,6 +59,7 @@ const InfrastructureMonitors = () => { filter: toFilterStatus, rowsPerPage, updateTrigger, + search }); if (networkError === true) { @@ -108,12 +112,19 @@ const InfrastructureMonitors = () => { setToFilterStatus={setToFilterStatus} handleReset={handleReset} /> + + } The response from the axios GET request. */ async getMonitorsByTeamId(config) { - const { teamId, limit, types, page, rowsPerPage, filter, field, order } = config; + const { teamId, limit, types, page, rowsPerPage, filter, field, order, search } = config; const params = new URLSearchParams(); if (limit) params.append("limit", limit); @@ -200,6 +201,7 @@ class NetworkService { if (filter) params.append("filter", filter); if (field) params.append("field", field); if (order) params.append("order", order); + if (search) params.append("search", search); return this.axiosInstance.get(`/monitors/team/${teamId}?${params.toString()}`, { headers: { diff --git a/server/db/mongo/modules/monitorModule.js b/server/db/mongo/modules/monitorModule.js index 3d9adab39..0e90c9c7f 100755 --- a/server/db/mongo/modules/monitorModule.js +++ b/server/db/mongo/modules/monitorModule.js @@ -510,7 +510,7 @@ const getMonitorById = async (monitorId) => { }; const getMonitorsByTeamId = async (req) => { - let { limit, type, page, rowsPerPage, filter, field, order } = req.query; + let { limit, type, page, rowsPerPage, filter, field, order, search } = req.query; limit = parseInt(limit); page = parseInt(page); rowsPerPage = parseInt(rowsPerPage); @@ -523,6 +523,9 @@ const getMonitorsByTeamId = async (req) => { if (type !== undefined) { matchStage.type = Array.isArray(type) ? { $in: type } : type; } + if (search) { + matchStage.name = { $regex: search, $options: "i" }; + } const summaryResult = await Monitor.aggregate( buildMonitorSummaryByTeamIdPipeline({ matchStage }) diff --git a/server/validation/joi.js b/server/validation/joi.js index 271cd2d21..40acc35c2 100755 --- a/server/validation/joi.js +++ b/server/validation/joi.js @@ -147,6 +147,7 @@ const getMonitorsByTeamIdQueryValidation = joi.object({ filter: joi.string(), field: joi.string(), order: joi.string().valid("asc", "desc"), + search: joi.string() }); const getMonitorStatsByIdParamValidation = joi.object({ From 800fd4792d1bbe1484b3e93d52e99eb56de69eeb Mon Sep 17 00:00:00 2001 From: Amol Date: Sat, 14 Jun 2025 16:23:05 +0530 Subject: [PATCH 2/5] fix: running formatting script on both client and server directories --- .../Components/MonitorsTable/index.jsx | 8 +++++++- .../Monitors/Hooks/useDebounce.jsx | 20 +++++++++---------- .../Monitors/Hooks/useMonitorFetch.jsx | 2 +- .../Pages/Infrastructure/Monitors/index.jsx | 2 +- client/src/Utils/NetworkService.js | 3 ++- server/validation/joi.js | 2 +- 6 files changed, 22 insertions(+), 15 deletions(-) diff --git a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTable/index.jsx b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTable/index.jsx index 02c32cc8c..b19853b1e 100644 --- a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTable/index.jsx +++ b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTable/index.jsx @@ -17,7 +17,13 @@ import { useNavigate } from "react-router-dom"; import PropTypes from "prop-types"; import { useTranslation } from "react-i18next"; -const MonitorsTable = ({ shouldRender, monitors, isAdmin, handleActionMenuDelete, isSearching }) => { +const MonitorsTable = ({ + shouldRender, + monitors, + isAdmin, + handleActionMenuDelete, + isSearching, +}) => { // Utils const theme = useTheme(); const { t } = useTranslation(); diff --git a/client/src/Pages/Infrastructure/Monitors/Hooks/useDebounce.jsx b/client/src/Pages/Infrastructure/Monitors/Hooks/useDebounce.jsx index fad002e48..11d639f14 100644 --- a/client/src/Pages/Infrastructure/Monitors/Hooks/useDebounce.jsx +++ b/client/src/Pages/Infrastructure/Monitors/Hooks/useDebounce.jsx @@ -1,18 +1,18 @@ import { useState, useEffect } from "react"; const useDebounce = (value, delay) => { - const [debouncedValue, setDebouncedValue] = useState(value); + const [debouncedValue, setDebouncedValue] = useState(value); - useEffect(() => { - const handler = setTimeout(() => { - setDebouncedValue(value); - }, delay); + useEffect(() => { + const handler = setTimeout(() => { + setDebouncedValue(value); + }, delay); - return () => { - clearTimeout(handler); - }; - }, [value, delay]); - return debouncedValue; + return () => { + clearTimeout(handler); + }; + }, [value, delay]); + return debouncedValue; }; export default useDebounce; diff --git a/client/src/Pages/Infrastructure/Monitors/Hooks/useMonitorFetch.jsx b/client/src/Pages/Infrastructure/Monitors/Hooks/useMonitorFetch.jsx index 2ef725ffd..3d091dc64 100644 --- a/client/src/Pages/Infrastructure/Monitors/Hooks/useMonitorFetch.jsx +++ b/client/src/Pages/Infrastructure/Monitors/Hooks/useMonitorFetch.jsx @@ -24,7 +24,7 @@ const useMonitorFetch = ({ page, field, filter, rowsPerPage, updateTrigger, sear types: ["hardware"], page: page, rowsPerPage: rowsPerPage, - search: search + search: search, }); setMonitors(response?.data?.data?.filteredMonitors ?? []); setSummary(response?.data?.data?.summary ?? {}); diff --git a/client/src/Pages/Infrastructure/Monitors/index.jsx b/client/src/Pages/Infrastructure/Monitors/index.jsx index 7af0be373..e9ac4c4eb 100644 --- a/client/src/Pages/Infrastructure/Monitors/index.jsx +++ b/client/src/Pages/Infrastructure/Monitors/index.jsx @@ -59,7 +59,7 @@ const InfrastructureMonitors = () => { filter: toFilterStatus, rowsPerPage, updateTrigger, - search + search, }); if (networkError === true) { diff --git a/client/src/Utils/NetworkService.js b/client/src/Utils/NetworkService.js index a8b7833da..1b4ffba0f 100644 --- a/client/src/Utils/NetworkService.js +++ b/client/src/Utils/NetworkService.js @@ -187,7 +187,8 @@ class NetworkService { */ async getMonitorsByTeamId(config) { - const { teamId, limit, types, page, rowsPerPage, filter, field, order, search } = config; + const { teamId, limit, types, page, rowsPerPage, filter, field, order, search } = + config; const params = new URLSearchParams(); if (limit) params.append("limit", limit); diff --git a/server/validation/joi.js b/server/validation/joi.js index 40acc35c2..6d8e97cf1 100755 --- a/server/validation/joi.js +++ b/server/validation/joi.js @@ -147,7 +147,7 @@ const getMonitorsByTeamIdQueryValidation = joi.object({ filter: joi.string(), field: joi.string(), order: joi.string().valid("asc", "desc"), - search: joi.string() + search: joi.string(), }); const getMonitorStatsByIdParamValidation = joi.object({ From e366741aa9ff3f37a2f0727c948316ad129c25a6 Mon Sep 17 00:00:00 2001 From: Amol Date: Sat, 14 Jun 2025 23:49:39 +0530 Subject: [PATCH 3/5] fix: updating code to the coding standards & changing the search param --- .../Components/LoadingSpinner/index.jsx | 46 ----------------- .../Components/MonitorsTable/index.jsx | 2 +- .../Components/SearchComponent/index.jsx | 49 ------------------- .../Monitors/Hooks/useDebounce.jsx | 18 ------- .../Monitors/Hooks/useMonitorFetch.jsx | 5 +- .../Pages/Infrastructure/Monitors/index.jsx | 5 +- client/src/Utils/NetworkService.js | 4 +- server/db/mongo/modules/monitorModule.js | 6 +-- server/validation/joi.js | 1 - 9 files changed, 9 insertions(+), 127 deletions(-) delete mode 100644 client/src/Pages/Infrastructure/Monitors/Components/LoadingSpinner/index.jsx delete mode 100644 client/src/Pages/Infrastructure/Monitors/Components/SearchComponent/index.jsx delete mode 100644 client/src/Pages/Infrastructure/Monitors/Hooks/useDebounce.jsx diff --git a/client/src/Pages/Infrastructure/Monitors/Components/LoadingSpinner/index.jsx b/client/src/Pages/Infrastructure/Monitors/Components/LoadingSpinner/index.jsx deleted file mode 100644 index a649473af..000000000 --- a/client/src/Pages/Infrastructure/Monitors/Components/LoadingSpinner/index.jsx +++ /dev/null @@ -1,46 +0,0 @@ -import { CircularProgress, Box } from "@mui/material"; -import { useTheme } from "@emotion/react"; -import PropTypes from "prop-types"; -const LoadingSpinner = ({ shouldRender }) => { - const theme = useTheme(); - if (shouldRender === false) { - return; - } - - return ( - <> - - - - - - ); -}; - -LoadingSpinner.propTypes = { - shouldRender: PropTypes.bool, -}; - -export default LoadingSpinner; diff --git a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTable/index.jsx b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTable/index.jsx index b19853b1e..9ab128c5e 100644 --- a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTable/index.jsx +++ b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTable/index.jsx @@ -5,7 +5,7 @@ import Host from "../../../../../Components/Host"; import { StatusLabel } from "../../../../../Components/Label"; import { Stack } from "@mui/material"; import { InfrastructureMenu } from "../MonitorsTableMenu"; -import LoadingSpinner from "../LoadingSpinner"; +import LoadingSpinner from "../../../../Uptime/Monitors/Components/LoadingSpinner"; // Assets import CPUChipIcon from "../../../../../assets/icons/cpu-chip.svg?react"; import CustomGauge from "../../../../../Components/Charts/CustomGauge"; diff --git a/client/src/Pages/Infrastructure/Monitors/Components/SearchComponent/index.jsx b/client/src/Pages/Infrastructure/Monitors/Components/SearchComponent/index.jsx deleted file mode 100644 index 0c6eec854..000000000 --- a/client/src/Pages/Infrastructure/Monitors/Components/SearchComponent/index.jsx +++ /dev/null @@ -1,49 +0,0 @@ -import { useState } from "react"; -import Search from "../../../../../Components/Inputs/Search"; -import { Box } from "@mui/material"; -import useDebounce from "../../Hooks/useDebounce"; -import { useEffect, useRef } from "react"; -import PropTypes from "prop-types"; - -const SearchComponent = ({ monitors = [], onSearchChange, setIsSearching }) => { - const isFirstRender = useRef(true); - const [localSearch, setLocalSearch] = useState(""); - const debouncedSearch = useDebounce(localSearch, 500); - useEffect(() => { - if (isFirstRender.current === true) { - isFirstRender.current = false; - return; - } - onSearchChange(debouncedSearch); - setIsSearching(false); - }, [debouncedSearch, onSearchChange, setIsSearching]); - - const handleSearch = (value) => { - setLocalSearch(value); - setIsSearching(true); - }; - - return ( - - - - ); -}; - -SearchComponent.propTypes = { - monitors: PropTypes.array, - onSearchChange: PropTypes.func, - setIsSearching: PropTypes.func, -}; - -export default SearchComponent; diff --git a/client/src/Pages/Infrastructure/Monitors/Hooks/useDebounce.jsx b/client/src/Pages/Infrastructure/Monitors/Hooks/useDebounce.jsx deleted file mode 100644 index 11d639f14..000000000 --- a/client/src/Pages/Infrastructure/Monitors/Hooks/useDebounce.jsx +++ /dev/null @@ -1,18 +0,0 @@ -import { useState, useEffect } from "react"; - -const useDebounce = (value, delay) => { - const [debouncedValue, setDebouncedValue] = useState(value); - - useEffect(() => { - const handler = setTimeout(() => { - setDebouncedValue(value); - }, delay); - - return () => { - clearTimeout(handler); - }; - }, [value, delay]); - return debouncedValue; -}; - -export default useDebounce; diff --git a/client/src/Pages/Infrastructure/Monitors/Hooks/useMonitorFetch.jsx b/client/src/Pages/Infrastructure/Monitors/Hooks/useMonitorFetch.jsx index 3d091dc64..883205c77 100644 --- a/client/src/Pages/Infrastructure/Monitors/Hooks/useMonitorFetch.jsx +++ b/client/src/Pages/Infrastructure/Monitors/Hooks/useMonitorFetch.jsx @@ -3,7 +3,7 @@ import { useSelector } from "react-redux"; import { networkService } from "../../../../main"; import { createToast } from "../../../../Utils/toastUtils"; -const useMonitorFetch = ({ page, field, filter, rowsPerPage, updateTrigger, search }) => { +const useMonitorFetch = ({ page, field, filter, rowsPerPage, updateTrigger }) => { // Redux state const { user } = useSelector((state) => state.auth); @@ -24,7 +24,6 @@ const useMonitorFetch = ({ page, field, filter, rowsPerPage, updateTrigger, sear types: ["hardware"], page: page, rowsPerPage: rowsPerPage, - search: search, }); setMonitors(response?.data?.data?.filteredMonitors ?? []); setSummary(response?.data?.data?.summary ?? {}); @@ -39,7 +38,7 @@ const useMonitorFetch = ({ page, field, filter, rowsPerPage, updateTrigger, sear }; fetchMonitors(); - }, [page, field, filter, rowsPerPage, user.teamId, updateTrigger, search]); + }, [page, field, filter, rowsPerPage, user.teamId, updateTrigger]); return { monitors, summary, isLoading, networkError }; }; diff --git a/client/src/Pages/Infrastructure/Monitors/index.jsx b/client/src/Pages/Infrastructure/Monitors/index.jsx index e9ac4c4eb..2f146f2de 100644 --- a/client/src/Pages/Infrastructure/Monitors/index.jsx +++ b/client/src/Pages/Infrastructure/Monitors/index.jsx @@ -8,7 +8,7 @@ import Pagination from "../../..//Components/Table/TablePagination"; import GenericFallback from "../../../Components/GenericFallback"; import Fallback from "../../../Components/Fallback"; import Filter from "./Components/Filters"; -import SearchComponent from "./Components/SearchComponent"; +import SearchComponent from "../../Uptime/Monitors/Components/SearchComponent"; // Utils import { useTheme } from "@emotion/react"; import { useMonitorFetch } from "./Hooks/useMonitorFetch"; @@ -56,10 +56,9 @@ const InfrastructureMonitors = () => { const { monitors, summary, isLoading, networkError } = useMonitorFetch({ page, field: field, - filter: toFilterStatus, + filter: toFilterStatus || search, rowsPerPage, updateTrigger, - search, }); if (networkError === true) { diff --git a/client/src/Utils/NetworkService.js b/client/src/Utils/NetworkService.js index 1b4ffba0f..27964a5ef 100644 --- a/client/src/Utils/NetworkService.js +++ b/client/src/Utils/NetworkService.js @@ -187,8 +187,7 @@ class NetworkService { */ async getMonitorsByTeamId(config) { - const { teamId, limit, types, page, rowsPerPage, filter, field, order, search } = - config; + const { teamId, limit, types, page, rowsPerPage, filter, field, order } = config; const params = new URLSearchParams(); if (limit) params.append("limit", limit); @@ -202,7 +201,6 @@ class NetworkService { if (filter) params.append("filter", filter); if (field) params.append("field", field); if (order) params.append("order", order); - if (search) params.append("search", search); return this.axiosInstance.get(`/monitors/team/${teamId}?${params.toString()}`, { headers: { diff --git a/server/db/mongo/modules/monitorModule.js b/server/db/mongo/modules/monitorModule.js index 0e90c9c7f..735cb6cc5 100755 --- a/server/db/mongo/modules/monitorModule.js +++ b/server/db/mongo/modules/monitorModule.js @@ -510,7 +510,7 @@ const getMonitorById = async (monitorId) => { }; const getMonitorsByTeamId = async (req) => { - let { limit, type, page, rowsPerPage, filter, field, order, search } = req.query; + let { limit, type, page, rowsPerPage, filter, field, order } = req.query; limit = parseInt(limit); page = parseInt(page); rowsPerPage = parseInt(rowsPerPage); @@ -523,8 +523,8 @@ const getMonitorsByTeamId = async (req) => { if (type !== undefined) { matchStage.type = Array.isArray(type) ? { $in: type } : type; } - if (search) { - matchStage.name = { $regex: search, $options: "i" }; + if (field === undefined) { + matchStage.name = { $regex: filter, $options: "i" }; } const summaryResult = await Monitor.aggregate( diff --git a/server/validation/joi.js b/server/validation/joi.js index 6d8e97cf1..271cd2d21 100755 --- a/server/validation/joi.js +++ b/server/validation/joi.js @@ -147,7 +147,6 @@ const getMonitorsByTeamIdQueryValidation = joi.object({ filter: joi.string(), field: joi.string(), order: joi.string().valid("asc", "desc"), - search: joi.string(), }); const getMonitorStatsByIdParamValidation = joi.object({ From 91741c2ae51341b3076b5144d3a70150ab664d48 Mon Sep 17 00:00:00 2001 From: Amol Date: Sun, 15 Jun 2025 03:17:22 +0530 Subject: [PATCH 4/5] fix: removing unused code blocks and better handling for filter param --- client/src/Pages/Infrastructure/Monitors/index.jsx | 2 +- client/src/Utils/NetworkService.js | 1 - server/db/mongo/modules/monitorModule.js | 3 --- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/client/src/Pages/Infrastructure/Monitors/index.jsx b/client/src/Pages/Infrastructure/Monitors/index.jsx index 2f146f2de..445ba8105 100644 --- a/client/src/Pages/Infrastructure/Monitors/index.jsx +++ b/client/src/Pages/Infrastructure/Monitors/index.jsx @@ -56,7 +56,7 @@ const InfrastructureMonitors = () => { const { monitors, summary, isLoading, networkError } = useMonitorFetch({ page, field: field, - filter: toFilterStatus || search, + filter: toFilterStatus ?? search, rowsPerPage, updateTrigger, }); diff --git a/client/src/Utils/NetworkService.js b/client/src/Utils/NetworkService.js index 27964a5ef..3d124a3e6 100644 --- a/client/src/Utils/NetworkService.js +++ b/client/src/Utils/NetworkService.js @@ -182,7 +182,6 @@ class NetworkService { * @param {string} [config.filter] - The filter to apply to the monitors. * @param {string} [config.field] - The field to sort by. * @param {string} [config.order] - The order in which to sort the field. - * @param {string} [config.search] - The search term to filter monitors by name. * @returns {Promise} The response from the axios GET request. */ diff --git a/server/db/mongo/modules/monitorModule.js b/server/db/mongo/modules/monitorModule.js index 735cb6cc5..3d9adab39 100755 --- a/server/db/mongo/modules/monitorModule.js +++ b/server/db/mongo/modules/monitorModule.js @@ -523,9 +523,6 @@ const getMonitorsByTeamId = async (req) => { if (type !== undefined) { matchStage.type = Array.isArray(type) ? { $in: type } : type; } - if (field === undefined) { - matchStage.name = { $regex: filter, $options: "i" }; - } const summaryResult = await Monitor.aggregate( buildMonitorSummaryByTeamIdPipeline({ matchStage }) From 738925d5ecdc3286f3cafd3736d105d167d3d361 Mon Sep 17 00:00:00 2001 From: Amol Date: Sun, 15 Jun 2025 15:29:48 +0530 Subject: [PATCH 5/5] fix: remove shouldRender prop as it is now managed by isLoading --- .../Monitors/Components/MonitorsTable/index.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTable/index.jsx b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTable/index.jsx index 639753638..7ee603ef7 100644 --- a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTable/index.jsx +++ b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTable/index.jsx @@ -18,7 +18,7 @@ import PropTypes from "prop-types"; import { useTranslation } from "react-i18next"; const MonitorsTable = ({ - shouldRender, + isLoading, monitors, isAdmin, handleActionMenuDelete, @@ -131,7 +131,7 @@ const MonitorsTable = ({