From ec1563bba2a5a2e7d4ebb98d674a3c35ef009b17 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 22 Nov 2024 09:49:32 +0800 Subject: [PATCH 1/5] Add parameter for date ranges to return all checks --- Server/db/mongo/modules/monitorModule.js | 3 ++- Server/validation/joi.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Server/db/mongo/modules/monitorModule.js b/Server/db/mongo/modules/monitorModule.js index 4d355141d..fa72aad21 100644 --- a/Server/db/mongo/modules/monitorModule.js +++ b/Server/db/mongo/modules/monitorModule.js @@ -198,7 +198,7 @@ const getIncidents = (checks) => { /** * Get date range parameters - * @param {string} dateRange - 'day' | 'week' | 'month' + * @param {string} dateRange - 'day' | 'week' | 'month' | 'all' * @returns {Object} Start and end dates */ const getDateRange = (dateRange) => { @@ -206,6 +206,7 @@ const getDateRange = (dateRange) => { day: new Date(new Date().setDate(new Date().getDate() - 1)), week: new Date(new Date().setDate(new Date().getDate() - 7)), month: new Date(new Date().setMonth(new Date().getMonth() - 1)), + all: new Date(0), }; return { start: startDates[dateRange], diff --git a/Server/validation/joi.js b/Server/validation/joi.js index 82a732686..bc3967657 100644 --- a/Server/validation/joi.js +++ b/Server/validation/joi.js @@ -178,7 +178,7 @@ const getMonitorStatsByIdQueryValidation = joi.object({ status: joi.string(), limit: joi.number(), sortOrder: joi.string().valid("asc", "desc"), - dateRange: joi.string().valid("day", "week", "month"), + dateRange: joi.string().valid("day", "week", "month", "all"), numToDisplay: joi.number(), normalize: joi.boolean(), }); From 69281eb3f1f41d7fbae55c25efdca6338e22606a Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 22 Nov 2024 09:50:02 +0800 Subject: [PATCH 2/5] update network request with correct params --- Client/src/Pages/Infrastructure/Details/index.jsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Client/src/Pages/Infrastructure/Details/index.jsx b/Client/src/Pages/Infrastructure/Details/index.jsx index 5f3ec7f77..5f08d71e1 100644 --- a/Client/src/Pages/Infrastructure/Details/index.jsx +++ b/Client/src/Pages/Infrastructure/Details/index.jsx @@ -169,7 +169,7 @@ const InfrastructureDetails = () => { ]; const [monitor, setMonitor] = useState(null); const { authToken } = useSelector((state) => state.auth); - const [dateRange, setDateRange] = useState("day"); + const [dateRange, setDateRange] = useState("all"); const { statusColor, determineState } = useUtils(); // These calculations are needed because ResponsiveContainer // doesn't take padding of parent/siblings into account @@ -189,11 +189,11 @@ const InfrastructureDetails = () => { const response = await networkService.getStatsByMonitorId({ authToken: authToken, monitorId: monitorId, - sortOrder: null, + sortOrder: "asc", limit: null, dateRange: dateRange, - numToDisplay: 50, - normalize: true, + numToDisplay: null, + normalize: false, }); setMonitor(response.data.data); } catch (error) { From 6363fa72e278ae18fad4b6f0349c927ba489cb25 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Mon, 25 Nov 2024 09:54:17 +0800 Subject: [PATCH 3/5] add back 50 checks to display for sanity --- Client/src/Pages/Infrastructure/Details/index.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/src/Pages/Infrastructure/Details/index.jsx b/Client/src/Pages/Infrastructure/Details/index.jsx index 5f08d71e1..179712c1f 100644 --- a/Client/src/Pages/Infrastructure/Details/index.jsx +++ b/Client/src/Pages/Infrastructure/Details/index.jsx @@ -192,7 +192,7 @@ const InfrastructureDetails = () => { sortOrder: "asc", limit: null, dateRange: dateRange, - numToDisplay: null, + numToDisplay: 50, normalize: false, }); setMonitor(response.data.data); From f90208bc0fa4e44c5244866b2d34a69e5005e11f Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Mon, 25 Nov 2024 09:55:01 +0800 Subject: [PATCH 4/5] Add dependencies to useEffect --- Client/src/Pages/Infrastructure/Details/index.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/src/Pages/Infrastructure/Details/index.jsx b/Client/src/Pages/Infrastructure/Details/index.jsx index 179712c1f..d32e94d50 100644 --- a/Client/src/Pages/Infrastructure/Details/index.jsx +++ b/Client/src/Pages/Infrastructure/Details/index.jsx @@ -201,7 +201,7 @@ const InfrastructureDetails = () => { } }; fetchData(); - }, []); + }, [dateRange, monitorId, authToken]); const statBoxConfigs = [ { From 6dab90f5184abfe9839b7d12bfb1cfd42a8051ef Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Mon, 25 Nov 2024 10:06:40 +0800 Subject: [PATCH 5/5] fix logger missing debug level, replace console.error with logger.error --- Client/src/Pages/Infrastructure/Details/index.jsx | 3 ++- Client/src/Utils/Logger.js | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Client/src/Pages/Infrastructure/Details/index.jsx b/Client/src/Pages/Infrastructure/Details/index.jsx index d32e94d50..bdb43123c 100644 --- a/Client/src/Pages/Infrastructure/Details/index.jsx +++ b/Client/src/Pages/Infrastructure/Details/index.jsx @@ -9,6 +9,7 @@ import { useSelector } from "react-redux"; import { networkService } from "../../../main"; import PulseDot from "../../../Components/Animated/PulseDot"; import useUtils from "../../Monitors/utils"; +import { logger } from "../../../Utils/Logger"; import { formatDurationRounded, formatDurationSplit } from "../../../Utils/timeUtils"; import { TzTick, @@ -197,7 +198,7 @@ const InfrastructureDetails = () => { }); setMonitor(response.data.data); } catch (error) { - console.error(error); + logger.error(error); } }; fetchData(); diff --git a/Client/src/Utils/Logger.js b/Client/src/Utils/Logger.js index 177391b99..b22cc0a22 100644 --- a/Client/src/Utils/Logger.js +++ b/Client/src/Utils/Logger.js @@ -44,6 +44,14 @@ class Logger { this.log = NO_OP; return; } + + if (logLevel === "debug") { + this.error = console.error.bind(console); + this.warn = console.warn.bind(console); + this.info = console.info.bind(console); + this.log = console.log.bind(console); + return; + } } cleanup() {