From f6be4317cd4fb3ed669afadc27f47a6733dd9543 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Mon, 16 Jun 2025 10:36:20 +0800 Subject: [PATCH 01/42] remove user and teamid from validation --- server/validation/joi.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/server/validation/joi.js b/server/validation/joi.js index 5eb24e758..725fcf218 100755 --- a/server/validation/joi.js +++ b/server/validation/joi.js @@ -558,14 +558,6 @@ const triggerNotificationBodyValidation = joi.object({ }); const createNotificationBodyValidation = joi.object({ - userId: joi.string().required().messages({ - "number.empty": "User ID is required", - "any.required": "User ID is required", - }), - teamId: joi.string().required().messages({ - "string.empty": "Team ID is required", - "any.required": "Team ID is required", - }), notificationName: joi.string().required().messages({ "string.empty": "Notification name is required", "any.required": "Notification name is required", From 22f8a37f1f93927a2d60c10e5808fedf2297d45f Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Mon, 16 Jun 2025 10:36:34 +0800 Subject: [PATCH 02/42] add discord type --- server/db/models/Notification.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/db/models/Notification.js b/server/db/models/Notification.js index 34afa1f31..751324131 100755 --- a/server/db/models/Notification.js +++ b/server/db/models/Notification.js @@ -7,7 +7,7 @@ const configSchema = mongoose.Schema( chatId: { type: String }, platform: { type: String, - enum: ["slack", "pager_duty", "webhook"], + enum: ["slack", "pager_duty", "webhook", "discord"], }, routingKey: { type: String }, }, From bfae00b69b56e369c250d35c75158174a69ecbf8 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Mon, 16 Jun 2025 10:36:45 +0800 Subject: [PATCH 03/42] add strings --- client/src/locales/en.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/client/src/locales/en.json b/client/src/locales/en.json index 2791dd3e7..31db9325b 100644 --- a/client/src/locales/en.json +++ b/client/src/locales/en.json @@ -298,6 +298,12 @@ "description": "Configure your webhook here", "webhookLabel": "Webhook URL", "webhookPlaceholder": "https://your-server.com/webhook" + }, + "discordSettings": { + "title": "Discord", + "description": "Configure your Discord webhook here", + "webhookLabel": "Discord Webhook URL", + "webhookPlaceholder": "https://your-server.com/webhook" } }, From 5aae16486560bdccba425adc77f8eb8bf551bb90 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Mon, 16 Jun 2025 10:37:04 +0800 Subject: [PATCH 04/42] extrat userId and teamId from req.uesr --- server/controllers/notificationController.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server/controllers/notificationController.js b/server/controllers/notificationController.js index a9c399901..82e2a23ab 100755 --- a/server/controllers/notificationController.js +++ b/server/controllers/notificationController.js @@ -102,6 +102,7 @@ class NotificationController { success = await this.notificationService.sendTestPagerDutyNotification(notification); } + if (!success) { return res.error({ msg: "Sending notification failed", @@ -128,7 +129,11 @@ class NotificationController { } try { - const notification = await this.db.createNotification(req.body); + const body = req.body; + const { _id, teamId } = req.user; + body.userId = _id; + body.teamId = teamId; + const notification = await this.db.createNotification(body); return res.success({ msg: "Notification created successfully", data: notification, From bea23a94bb6a042faaea8ee3b6ce1b883f5a17ce Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Mon, 16 Jun 2025 10:38:05 +0800 Subject: [PATCH 05/42] handle discord webhooks --- .../src/Pages/Notifications/create/index.jsx | 72 ++++++++++++++----- client/src/Pages/Notifications/utils.js | 3 +- 2 files changed, 58 insertions(+), 17 deletions(-) diff --git a/client/src/Pages/Notifications/create/index.jsx b/client/src/Pages/Notifications/create/index.jsx index 3c17c113c..8b5512ca8 100644 --- a/client/src/Pages/Notifications/create/index.jsx +++ b/client/src/Pages/Notifications/create/index.jsx @@ -10,7 +10,6 @@ import TextInput from "../../../Components/Inputs/TextInput"; // Utils import { useState } from "react"; -import { useSelector } from "react-redux"; import { useTheme } from "@emotion/react"; import { useCreateNotification, @@ -44,7 +43,6 @@ const CreateNotifications = () => { ]; // Redux state - const { user } = useSelector((state) => state.auth); // local state const [notification, setNotification] = useState({ @@ -73,7 +71,7 @@ const CreateNotifications = () => { type: NOTIFICATION_TYPES.find((type) => type._id === notification.type).value, }; - if (notification.type === 2) { + if (form.type === "slack" || form.type === "discord") { form.type = "webhook"; } @@ -128,27 +126,33 @@ const CreateNotifications = () => { // Handle config/platform initialization if type is webhook - if (newNotification.type === 1) { + const type = NOTIFICATION_TYPES.find( + (type) => type._id === newNotification.type + ).value; + + if (newNotification.type === "email") { newNotification.config = null; - } else if (newNotification.type === 2) { + } else if (type === "slack" || type === "webhook" || type === "discord") { newNotification.address = ""; newNotification.config = newNotification.config || {}; if (name === "config") { newNotification.config = value; } - newNotification.config.platform = "slack"; - } else if (newNotification.type === 3) { + if (type === "webhook") { + newNotification.config.platform = "webhook"; + } + if (type === "slack") { + newNotification.config.platform = "slack"; + } + if (type === "discord") { + newNotification.config.platform = "discord"; + } + } else if (type === "pager_duty") { newNotification.config = newNotification.config || {}; if (name === "config") { newNotification.config = value; } newNotification.config.platform = "pager_duty"; - } else if (newNotification.type === 4) { - newNotification.config = newNotification.config || {}; - if (name === "config") { - newNotification.config = value; - } - newNotification.config.platform = "webhook"; } // Field-level validation @@ -159,12 +163,15 @@ const CreateNotifications = () => { fieldError = error?.message; } - if (newNotification.type === 1 && name === "address") { + if (type === "email" && name === "address") { const { error } = notificationEmailValidation.extract(name).validate(value); fieldError = error?.message; } - if (newNotification.type === 2 && name === "config") { + if ( + (type === "slack" || type === "webhook" || type === "discord") && + name === "config" + ) { // Validate only webhookUrl inside config const { error } = notificationWebhookValidation.extract("config").validate(value); fieldError = error?.message; @@ -185,7 +192,7 @@ const CreateNotifications = () => { type: NOTIFICATION_TYPES.find((type) => type._id === notification.type).value, }; - if (notification.type === 2) { + if (form.type === "slack" || form.type === "discord") { form.type = "webhook"; } @@ -405,6 +412,39 @@ const CreateNotifications = () => { )} + {notification.type === 5 && ( + + + + {t("createNotifications.discordSettings.title")} + + + {t("createNotifications.discordSettings.description")} + + + + { + const updatedConfig = { + ...notification.config, + webhookUrl: e.target.value, + }; + + onChange({ + target: { + name: "config", + value: updatedConfig, + }, + }); + }} + /> + + + )} Date: Mon, 16 Jun 2025 13:30:27 +0800 Subject: [PATCH 06/42] fix email type --- client/src/Pages/Notifications/create/index.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/Pages/Notifications/create/index.jsx b/client/src/Pages/Notifications/create/index.jsx index 8b5512ca8..2fd83e4e1 100644 --- a/client/src/Pages/Notifications/create/index.jsx +++ b/client/src/Pages/Notifications/create/index.jsx @@ -130,7 +130,7 @@ const CreateNotifications = () => { (type) => type._id === newNotification.type ).value; - if (newNotification.type === "email") { + if (type === "email") { newNotification.config = null; } else if (type === "slack" || type === "webhook" || type === "discord") { newNotification.address = ""; From 3df6b451e7074e8ed05ba183eb35c0613a8e8943 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Mon, 16 Jun 2025 13:53:08 +0800 Subject: [PATCH 07/42] fix hardware notifications --- server/service/notificationService.js | 88 ++++++++++++++++++++------- 1 file changed, 65 insertions(+), 23 deletions(-) diff --git a/server/service/notificationService.js b/server/service/notificationService.js index 6e12722c2..a8dfa4729 100755 --- a/server/service/notificationService.js +++ b/server/service/notificationService.js @@ -95,6 +95,19 @@ class NotificationService { return MESSAGE_FORMATTERS[platform](messageText, chatId); } + formatHardwareNotificationMessage = ( + monitor, + status, + platform, + chatId, + code, + timestamp, + alerts + ) => { + const messageText = alerts.map((alert) => alert).join("\n"); + return MESSAGE_FORMATTERS[platform](messageText, chatId); + }; + sendTestWebhookNotification = async (notification) => { const config = notification.config; const response = await this.networkService.requestWebhook( @@ -121,7 +134,7 @@ class NotificationService { * @returns {Promise} A promise that resolves to true if the notification was sent successfully, otherwise false. */ - async sendWebhookNotification(networkResponse, notification) { + async sendWebhookNotification(networkResponse, notification, alerts = []) { const { monitor, status, code } = networkResponse; const { webhookUrl, platform, botToken, chatId } = notification.config; @@ -152,14 +165,27 @@ class NotificationService { url = `${TELEGRAM_API_BASE_URL}${botToken}/sendMessage`; } - const message = this.formatNotificationMessage( - monitor, - status, - platform, - chatId, - code, // Pass the code field directly - networkResponse.timestamp - ); + let message; + if (monitor.type === "hardware") { + message = this.formatHardwareNotificationMessage( + monitor, + status, + platform, + chatId, + code, + networkResponse.timestamp, + alerts + ); + } else { + message = this.formatNotificationMessage( + monitor, + status, + platform, + chatId, + code, // Pass the code field directly + networkResponse.timestamp + ); + } try { const response = await this.networkService.requestWebhook(platform, url, message); @@ -247,19 +273,31 @@ class NotificationService { return response; } - async sendPagerDutyNotification(networkResponse, notification) { + async sendPagerDutyNotification(networkResponse, notification, alerts = []) { const { monitor, status, code } = networkResponse; const { routingKey, platform } = notification.config; - const message = this.formatNotificationMessage( - monitor, - status, - platform, - null, - code, // Pass the code field directly - networkResponse.timestamp - ); - + let message; + if (monitor.type === "hardware") { + message = this.formatHardwareNotificationMessage( + monitor, + status, + platform, + null, + code, + networkResponse.timestamp, + alerts + ); + } else { + message = this.formatNotificationMessage( + monitor, + status, + platform, + null, + code, // Pass the code field directly + networkResponse.timestamp + ); + } try { const response = await this.networkService.requestPagerDuty({ message, @@ -350,9 +388,9 @@ class NotificationService { ) ?? false, }; - const notifications = await this.db.getNotificationsByMonitorId( - networkResponse.monitorId - ); + const notificationIDs = networkResponse.monitor?.notifications ?? []; + const notifications = await this.db.getNotificationsByIds(notificationIDs); + for (const notification of notifications) { const alertsToSend = []; const alertTypes = ["cpu", "memory", "disk"]; @@ -388,7 +426,11 @@ class NotificationService { if (alertsToSend.length === 0) continue; // No alerts to send, we're done if (notification.type === "email") { - this.sendHardwareEmail(networkResponse, notification.address, alertsToSend); + await this.sendHardwareEmail(networkResponse, notification.address, alertsToSend); + } else if (notification.type === "webhook") { + await this.sendWebhookNotification(networkResponse, notification, alertsToSend); + } else if (notification.type === "pager_duty") { + await this.sendPagerDutyNotification(networkResponse, notification, alertsToSend); } } return true; From f47d3c2cd6acabad48b414ad2750f97f8812a144 Mon Sep 17 00:00:00 2001 From: Br0wnHammer Date: Mon, 16 Jun 2025 12:56:08 +0530 Subject: [PATCH 08/42] Feat: useFetchChecksByMonitor --- client/src/Hooks/checkHooksMonitor.js | 58 +++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 client/src/Hooks/checkHooksMonitor.js diff --git a/client/src/Hooks/checkHooksMonitor.js b/client/src/Hooks/checkHooksMonitor.js new file mode 100644 index 000000000..00f1c9671 --- /dev/null +++ b/client/src/Hooks/checkHooksMonitor.js @@ -0,0 +1,58 @@ +import { useState, useEffect } from "react"; +import { networkService } from "../main"; +import { createToast } from "../Utils/toastUtils"; + +const useFetchChecksByMonitor = ({ + monitorId, + type, + status, + sortOrder, + limit, + dateRange, + filter, + page, + rowsPerPage, +}) => { + const [checks, setChecks] = useState(undefined); + const [checksCount, setChecksCount] = useState(undefined); + const [isLoading, setIsLoading] = useState(false); + const [networkError, setNetworkError] = useState(false); + + useEffect(() => { + const fetchChecks = async () => { + if (!type) { + return; + } + + const config = { + monitorId, + type, + status, + sortOrder, + limit, + dateRange, + filter, + page, + rowsPerPage, + } + + try { + setIsLoading(true); + const res = await networkService.getChecksByMonitor(config); + setChecks(res.data.data.checks); + setChecksCount(res.data.data.checksCount); + } catch (error) { + setNetworkError(true); + createToast({ body: error.message }); + } finally { + setIsLoading(false); + } + }; + + fetchChecks(); + }, [monitorId, type, status, sortOrder, limit, dateRange, filter, page, rowsPerPage]); + + return [checks, checksCount, isLoading, networkError]; +}; + +export { useFetchChecksByMonitor }; \ No newline at end of file From bebbe5896d395cb91090be5de5e991b059d8fd43 Mon Sep 17 00:00:00 2001 From: Br0wnHammer Date: Mon, 16 Jun 2025 12:57:00 +0530 Subject: [PATCH 09/42] Uptime useFetchChecksByMonitor Integration --- client/src/Pages/Uptime/Details/index.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/Pages/Uptime/Details/index.jsx b/client/src/Pages/Uptime/Details/index.jsx index 79762e0c3..8c1dbe562 100644 --- a/client/src/Pages/Uptime/Details/index.jsx +++ b/client/src/Pages/Uptime/Details/index.jsx @@ -18,7 +18,7 @@ import { useTheme } from "@emotion/react"; import { useIsAdmin } from "../../../Hooks/useIsAdmin"; import { useFetchUptimeMonitorById } from "../../../Hooks/monitorHooks"; import useCertificateFetch from "./Hooks/useCertificateFetch"; -import { useFetchChecks } from "../../../Hooks/checkHooks"; +import { useFetchChecksByMonitor } from "../../../Hooks/checkHooksMonitor"; import { useTranslation } from "react-i18next"; // Constants @@ -66,7 +66,7 @@ const UptimeDetails = () => { const monitorType = monitor?.type; - const [checks, checksCount, checksAreLoading, checksNetworkError] = useFetchChecks({ + const [checks, checksCount, checksAreLoading, checksNetworkError] = useFetchChecksByMonitor({ monitorId, type: monitorType, sortOrder: "desc", From 37406484fcb86419a6496fc4a95049cee742c43a Mon Sep 17 00:00:00 2001 From: Br0wnHammer Date: Mon, 16 Jun 2025 13:00:23 +0530 Subject: [PATCH 10/42] useFetchChecksTeam Hook --- .../{checkHooks.js => checkHooksTeam.js} | 48 ++++++------------- .../Components/IncidentTable/index.jsx | 4 +- 2 files changed, 16 insertions(+), 36 deletions(-) rename client/src/Hooks/{checkHooks.js => checkHooksTeam.js} (62%) diff --git a/client/src/Hooks/checkHooks.js b/client/src/Hooks/checkHooksTeam.js similarity index 62% rename from client/src/Hooks/checkHooks.js rename to client/src/Hooks/checkHooksTeam.js index dac2be671..fedd88d52 100644 --- a/client/src/Hooks/checkHooks.js +++ b/client/src/Hooks/checkHooksTeam.js @@ -2,10 +2,8 @@ import { useState, useEffect } from "react"; import { networkService } from "../main"; import { createToast } from "../Utils/toastUtils"; -const useFetchChecks = ({ +const useFetchChecksTeam = ({ teamId, - monitorId, - type, status, sortOrder, limit, @@ -21,40 +19,24 @@ const useFetchChecks = ({ useEffect(() => { const fetchChecks = async () => { - if (!type && !teamId) { + if (!teamId) { return; } - const method = monitorId - ? networkService.getChecksByMonitor - : networkService.getChecksByTeam; - - const config = monitorId - ? { - monitorId, - type, - status, - sortOrder, - limit, - dateRange, - filter, - page, - rowsPerPage, - } - : { - status, - teamId, - sortOrder, - limit, - dateRange, - filter, - page, - rowsPerPage, - }; + const config = { + status, + teamId, + sortOrder, + limit, + dateRange, + filter, + page, + rowsPerPage, + }; try { setIsLoading(true); - const res = await method(config); + const res = await networkService.getChecksByTeam(config); setChecks(res.data.data.checks); setChecksCount(res.data.data.checksCount); } catch (error) { @@ -67,9 +49,7 @@ const useFetchChecks = ({ fetchChecks(); }, [ - monitorId, teamId, - type, status, sortOrder, limit, @@ -82,4 +62,4 @@ const useFetchChecks = ({ return [checks, checksCount, isLoading, networkError]; }; -export { useFetchChecks }; +export { useFetchChecksTeam }; diff --git a/client/src/Pages/Incidents/Components/IncidentTable/index.jsx b/client/src/Pages/Incidents/Components/IncidentTable/index.jsx index cf6fbb49d..98f0c3d8f 100644 --- a/client/src/Pages/Incidents/Components/IncidentTable/index.jsx +++ b/client/src/Pages/Incidents/Components/IncidentTable/index.jsx @@ -13,7 +13,7 @@ import { useSelector } from "react-redux"; import { useState, useEffect } from "react"; import PropTypes from "prop-types"; import { useTranslation } from "react-i18next"; -import { useFetchChecks } from "../../../../Hooks/checkHooks"; +import { useFetchChecksTeam } from "../../../../Hooks/checkHooksTeam"; const IncidentTable = ({ shouldRender, @@ -34,7 +34,7 @@ const IncidentTable = ({ const selectedMonitorDetails = monitors?.[selectedMonitor]; const selectedMonitorType = selectedMonitorDetails?.type; - const [checks, checksCount, isLoading, networkError] = useFetchChecks({ + const [checks, checksCount, isLoading, networkError] = useFetchChecksTeam({ status: false, monitorId, teamId, From 638fcb3b9bc43351f7e250f27656ddf3868026a5 Mon Sep 17 00:00:00 2001 From: Br0wnHammer Date: Mon, 16 Jun 2025 13:08:39 +0530 Subject: [PATCH 11/42] Incidents useFetchChecksMonitor Integration --- .../Pages/Incidents/Components/IncidentTable/index.jsx | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/client/src/Pages/Incidents/Components/IncidentTable/index.jsx b/client/src/Pages/Incidents/Components/IncidentTable/index.jsx index 98f0c3d8f..05c776367 100644 --- a/client/src/Pages/Incidents/Components/IncidentTable/index.jsx +++ b/client/src/Pages/Incidents/Components/IncidentTable/index.jsx @@ -13,7 +13,7 @@ import { useSelector } from "react-redux"; import { useState, useEffect } from "react"; import PropTypes from "prop-types"; import { useTranslation } from "react-i18next"; -import { useFetchChecksTeam } from "../../../../Hooks/checkHooksTeam"; +import { useFetchChecksByMonitor } from "../../../../Hooks/checkHooksMonitor"; const IncidentTable = ({ shouldRender, @@ -26,7 +26,6 @@ const IncidentTable = ({ const uiTimezone = useSelector((state) => state.ui.timezone); //Local state - const [teamId, setTeamId] = useState(undefined); const [monitorId, setMonitorId] = useState(undefined); const [page, setPage] = useState(0); @@ -34,10 +33,9 @@ const IncidentTable = ({ const selectedMonitorDetails = monitors?.[selectedMonitor]; const selectedMonitorType = selectedMonitorDetails?.type; - const [checks, checksCount, isLoading, networkError] = useFetchChecksTeam({ + const [checks, checksCount, isLoading, networkError] = useFetchChecksByMonitor({ status: false, monitorId, - teamId, type: selectedMonitorType, sortOrder: "desc", limit: null, @@ -60,11 +58,9 @@ const IncidentTable = ({ useEffect(() => { if (selectedMonitor === "0") { - setTeamId("placeholder"); // TODO this isn't needed any longer, fix hook setMonitorId(undefined); } else { setMonitorId(selectedMonitor); - setTeamId(undefined); } }, [selectedMonitor]); From c981b25ef91da0c418eb9ef456d67197ba157e10 Mon Sep 17 00:00:00 2001 From: Br0wnHammer Date: Mon, 16 Jun 2025 13:51:15 +0530 Subject: [PATCH 12/42] Hooks integration in Incidents Table --- client/src/Hooks/checkHooksMonitor.js | 66 +++++++++---------- client/src/Hooks/checkHooksTeam.js | 11 +--- .../Components/IncidentTable/index.jsx | 53 ++++++++------- client/src/Pages/Uptime/Details/index.jsx | 21 +++--- 4 files changed, 76 insertions(+), 75 deletions(-) diff --git a/client/src/Hooks/checkHooksMonitor.js b/client/src/Hooks/checkHooksMonitor.js index 00f1c9671..e46adfa98 100644 --- a/client/src/Hooks/checkHooksMonitor.js +++ b/client/src/Hooks/checkHooksMonitor.js @@ -13,46 +13,46 @@ const useFetchChecksByMonitor = ({ page, rowsPerPage, }) => { - const [checks, setChecks] = useState(undefined); + const [checks, setChecks] = useState(undefined); const [checksCount, setChecksCount] = useState(undefined); const [isLoading, setIsLoading] = useState(false); const [networkError, setNetworkError] = useState(false); - useEffect(() => { - const fetchChecks = async () => { - if (!type) { - return; - } + useEffect(() => { + const fetchChecks = async () => { + if (!type) { + return; + } - const config = { - monitorId, - type, - status, - sortOrder, - limit, - dateRange, - filter, - page, - rowsPerPage, - } + const config = { + monitorId, + type, + status, + sortOrder, + limit, + dateRange, + filter, + page, + rowsPerPage, + }; - try { - setIsLoading(true); - const res = await networkService.getChecksByMonitor(config); - setChecks(res.data.data.checks); - setChecksCount(res.data.data.checksCount); - } catch (error) { - setNetworkError(true); - createToast({ body: error.message }); - } finally { - setIsLoading(false); - } - }; + try { + setIsLoading(true); + const res = await networkService.getChecksByMonitor(config); + setChecks(res.data.data.checks); + setChecksCount(res.data.data.checksCount); + } catch (error) { + setNetworkError(true); + createToast({ body: error.message }); + } finally { + setIsLoading(false); + } + }; - fetchChecks(); - }, [monitorId, type, status, sortOrder, limit, dateRange, filter, page, rowsPerPage]); + fetchChecks(); + }, [monitorId, type, status, sortOrder, limit, dateRange, filter, page, rowsPerPage]); - return [checks, checksCount, isLoading, networkError]; + return [checks, checksCount, isLoading, networkError]; }; -export { useFetchChecksByMonitor }; \ No newline at end of file +export { useFetchChecksByMonitor }; diff --git a/client/src/Hooks/checkHooksTeam.js b/client/src/Hooks/checkHooksTeam.js index fedd88d52..05f8b67e5 100644 --- a/client/src/Hooks/checkHooksTeam.js +++ b/client/src/Hooks/checkHooksTeam.js @@ -48,16 +48,7 @@ const useFetchChecksTeam = ({ }; fetchChecks(); - }, [ - teamId, - status, - sortOrder, - limit, - dateRange, - filter, - page, - rowsPerPage, - ]); + }, [teamId, status, sortOrder, limit, dateRange, filter, page, rowsPerPage]); return [checks, checksCount, isLoading, networkError]; }; diff --git a/client/src/Pages/Incidents/Components/IncidentTable/index.jsx b/client/src/Pages/Incidents/Components/IncidentTable/index.jsx index 05c776367..97a006884 100644 --- a/client/src/Pages/Incidents/Components/IncidentTable/index.jsx +++ b/client/src/Pages/Incidents/Components/IncidentTable/index.jsx @@ -10,9 +10,10 @@ import NetworkError from "../../../../Components/GenericFallback/NetworkError"; //Utils import { formatDateWithTz } from "../../../../Utils/timeUtils"; import { useSelector } from "react-redux"; -import { useState, useEffect } from "react"; +import { useState } from "react"; import PropTypes from "prop-types"; import { useTranslation } from "react-i18next"; +import { useFetchChecksTeam } from "../../../../Hooks/checkHooksTeam"; import { useFetchChecksByMonitor } from "../../../../Hooks/checkHooksMonitor"; const IncidentTable = ({ @@ -26,24 +27,40 @@ const IncidentTable = ({ const uiTimezone = useSelector((state) => state.ui.timezone); //Local state - const [monitorId, setMonitorId] = useState(undefined); - const [page, setPage] = useState(0); const [rowsPerPage, setRowsPerPage] = useState(10); const selectedMonitorDetails = monitors?.[selectedMonitor]; const selectedMonitorType = selectedMonitorDetails?.type; - const [checks, checksCount, isLoading, networkError] = useFetchChecksByMonitor({ - status: false, - monitorId, - type: selectedMonitorType, - sortOrder: "desc", - limit: null, - dateRange, - filter: filter, - page: page, - rowsPerPage: rowsPerPage, - }); + const [checksMonitor, checksCountMonitor, isLoadingMonitor, networkErrorMonitor] = + useFetchChecksByMonitor({ + monitorId: selectedMonitor === "0" ? undefined : selectedMonitor, + type: selectedMonitorType, + status: false, + sortOrder: "desc", + limit: null, + dateRange, + filter: filter, + page: page, + rowsPerPage: rowsPerPage, + }); + + const [checksTeam, checksCountTeam, isLoadingTeam, networkErrorTeam] = + useFetchChecksTeam({ + teamId: "placeholder", + status: false, + sortOrder: "desc", + limit: null, + dateRange, + filter: filter, + page: page, + rowsPerPage: rowsPerPage, + }); + + const checks = selectedMonitor === "0" ? checksTeam : checksMonitor; + const checksCount = selectedMonitor === "0" ? checksCountTeam : checksCountMonitor; + const isLoading = selectedMonitor === "0" ? isLoadingTeam : isLoadingMonitor; + const networkError = selectedMonitor === "0" ? networkErrorTeam : networkErrorMonitor; const { t } = useTranslation(); @@ -56,14 +73,6 @@ const IncidentTable = ({ setRowsPerPage(event.target.value); }; - useEffect(() => { - if (selectedMonitor === "0") { - setMonitorId(undefined); - } else { - setMonitorId(selectedMonitor); - } - }, [selectedMonitor]); - const headers = [ { id: "monitorName", diff --git a/client/src/Pages/Uptime/Details/index.jsx b/client/src/Pages/Uptime/Details/index.jsx index 8c1dbe562..1d6b9c392 100644 --- a/client/src/Pages/Uptime/Details/index.jsx +++ b/client/src/Pages/Uptime/Details/index.jsx @@ -66,16 +66,17 @@ const UptimeDetails = () => { const monitorType = monitor?.type; - const [checks, checksCount, checksAreLoading, checksNetworkError] = useFetchChecksByMonitor({ - monitorId, - type: monitorType, - sortOrder: "desc", - limit: null, - dateRange, - filter: null, - page, - rowsPerPage, - }); + const [checks, checksCount, checksAreLoading, checksNetworkError] = + useFetchChecksByMonitor({ + monitorId, + type: monitorType, + sortOrder: "desc", + limit: null, + dateRange, + filter: null, + page, + rowsPerPage, + }); // Handlers const triggerUpdate = () => { From df42932e0cf1683e81e93e59ab91b676efb0cf07 Mon Sep 17 00:00:00 2001 From: Deepanshu Date: Mon, 16 Jun 2025 20:40:19 +0530 Subject: [PATCH 13/42] fix(ui): shorten URL label and resize notification button (#2470) --- .../MonitorDetailsControlHeader/index.jsx | 83 ++++++++++--------- .../MonitorDetailsControlHeader/status.jsx | 42 +++++----- 2 files changed, 66 insertions(+), 59 deletions(-) diff --git a/client/src/Components/MonitorDetailsControlHeader/index.jsx b/client/src/Components/MonitorDetailsControlHeader/index.jsx index d569ec840..9db38c0cf 100644 --- a/client/src/Components/MonitorDetailsControlHeader/index.jsx +++ b/client/src/Components/MonitorDetailsControlHeader/index.jsx @@ -56,46 +56,49 @@ const MonitorDetailsControlHeader = ({ > - - - - + + + + {isAdmin && ( - - + + + + {isAdmin && (