From 367d3602c8edfee84c5bb44fa99667e21ebb6dc5 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 10 Jan 2025 13:23:19 -0800 Subject: [PATCH 1/2] add array of all monitors to response for search --- Server/db/mongo/modules/monitorModule.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Server/db/mongo/modules/monitorModule.js b/Server/db/mongo/modules/monitorModule.js index b191bd1bc..df80855bd 100644 --- a/Server/db/mongo/modules/monitorModule.js +++ b/Server/db/mongo/modules/monitorModule.js @@ -545,6 +545,15 @@ const getMonitorsByTeamId = async (req) => { }, ], monitors: [ + { $sort: sort }, + { + $project: { + _id: 1, + name: 1, + }, + }, + ], + filteredMonitors: [ ...(filter !== undefined ? [ { @@ -657,20 +666,21 @@ const getMonitorsByTeamId = async (req) => { { $project: { summary: { $arrayElemAt: ["$summary", 0] }, + filteredMonitors: 1, monitors: 1, }, }, ]); - let { monitors, summary } = results[0]; - monitors = monitors.map((monitor) => { + let { monitors, filteredMonitors, summary } = results[0]; + filteredMonitors = filteredMonitors.map((monitor) => { if (!monitor.checks) { return monitor; } monitor.checks = NormalizeData(monitor.checks, 10, 100); return monitor; }); - return { monitors, summary }; + return { monitors, filteredMonitors, summary }; }; /** From cd14659a59a9f2865e7713da91a953aa45a5c0f6 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 10 Jan 2025 13:23:32 -0800 Subject: [PATCH 2/2] Use all monitors for search component instead of filtered monitors --- Client/src/Components/Inputs/Search/index.jsx | 1 - Client/src/Pages/Infrastructure/index.jsx | 2 +- Client/src/Pages/PageSpeed/index.jsx | 4 ++-- .../src/Pages/Uptime/Home/UptimeDataTable/index.jsx | 4 +++- Client/src/Pages/Uptime/Home/index.jsx | 11 +++++++---- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Client/src/Components/Inputs/Search/index.jsx b/Client/src/Components/Inputs/Search/index.jsx index 2491020f0..46c46de3e 100644 --- a/Client/src/Components/Inputs/Search/index.jsx +++ b/Client/src/Components/Inputs/Search/index.jsx @@ -56,7 +56,6 @@ const Search = ({ disabled, }) => { const theme = useTheme(); - return ( { field: null, order: null, }); - if (res?.data?.data?.monitors) { - setMonitors(res.data.data.monitors); + if (res?.data?.data?.filteredMonitors) { + setMonitors(res.data.data.filteredMonitors); setSummary(res.data.data.summary); } } catch (error) { diff --git a/Client/src/Pages/Uptime/Home/UptimeDataTable/index.jsx b/Client/src/Pages/Uptime/Home/UptimeDataTable/index.jsx index 31b6182fc..a184eb09f 100644 --- a/Client/src/Pages/Uptime/Home/UptimeDataTable/index.jsx +++ b/Client/src/Pages/Uptime/Home/UptimeDataTable/index.jsx @@ -88,6 +88,7 @@ const UptimeDataTable = ({ isAdmin, isLoading, monitors, + filteredMonitors, monitorCount, sort, setSort, @@ -274,7 +275,7 @@ const UptimeDataTable = ({ )} { // Redux state const rowsPerPage = useSelector((state) => state.ui.monitors.rowsPerPage); // Local state - const [monitors, setMonitors] = useState([]); const [sort, setSort] = useState({}); const [search, setSearch] = useState(""); const [page, setPage] = useState(0); const [isSearching, setIsSearching] = useState(false); const [isLoading, setIsLoading] = useState(false); const [monitorUpdateTrigger, setMonitorUpdateTrigger] = useState(false); + const [monitors, setMonitors] = useState([]); + const [filteredMonitors, setFilteredMonitors] = useState([]); const [monitorsSummary, setMonitorsSummary] = useState({}); // Utils @@ -100,11 +101,12 @@ const UptimeMonitors = () => { field: config.sort.field, order: config.sort.order, }); - const { monitors, summary } = res.data.data; - const mappedMonitors = monitors.map((monitor) => + const { monitors, filteredMonitors, summary } = res.data.data; + const mappedMonitors = filteredMonitors.map((monitor) => getMonitorWithPercentage(monitor, theme) ); - setMonitors(mappedMonitors); + setMonitors(monitors); + setFilteredMonitors(mappedMonitors); setMonitorsSummary(summary); } catch (error) { createToast({ @@ -199,6 +201,7 @@ const UptimeMonitors = () => {