From 74cef5adb1ac64cea835871e797422cf57d922c5 Mon Sep 17 00:00:00 2001 From: mohadeseh safari Date: Fri, 20 Jun 2025 20:39:18 -0400 Subject: [PATCH 01/12] Fix #2471: Add Details, Configure, and Pause options to infrastructure action menu --- .../Components/MonitorsTableMenu/index.jsx | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx index 15193da3e..9875e0697 100644 --- a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx +++ b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx @@ -9,6 +9,7 @@ import Settings from "../../../../../assets/icons/settings-bold.svg?react"; import PropTypes from "prop-types"; import Dialog from "../../../../../Components/Dialog"; import { networkService } from "../../../../../Utils/NetworkService.js"; +import { usePauseMonitor } from "../../../../../Hooks/monitorHooks"; /** * InfrastructureMenu Component @@ -29,6 +30,7 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { const [isOpen, setIsOpen] = useState(false); const [isDialogOpen, setIsDialogOpen] = useState(false); const theme = useTheme(); + const [pauseMonitor] = usePauseMonitor(); const openMenu = (e) => { e.stopPropagation(); @@ -54,6 +56,20 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { navigate(`/infrastructure/${id}`); } + const openConfigure = (id) => { + navigate(`/infrastructure/configure/${id}`); + } + + const handlePause = async () => { + try { + await pauseMonitor({ monitorId: monitor.id }); + createToast({ body: `Monitor ${monitor.isActive ? "paused" : "resumed"} successfully.` }); + updateCallback(); + } catch (error) { + createToast({ body: `Failed to ${monitor.isActive ? "pause" : "resume"} monitor.` }); + } + } + const handleRemove = async () => { try { await networkService.deleteMonitorById({ @@ -105,7 +121,14 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { }, }} > - {isAdmin && Remove} + openDetails(monitor.id)}>Details + {isAdmin && openConfigure(monitor.id)}>Configure} + {isAdmin && ( + + {monitor.isActive ? "Pause" : "Resume"} + + )} + {isAdmin && Remove} Date: Fri, 20 Jun 2025 20:58:36 -0400 Subject: [PATCH 02/12] Format code with prettier --- .../Components/MonitorsTableMenu/index.jsx | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx index 9875e0697..76440f02d 100644 --- a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx +++ b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx @@ -58,17 +58,21 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { const openConfigure = (id) => { navigate(`/infrastructure/configure/${id}`); - } + }; const handlePause = async () => { try { await pauseMonitor({ monitorId: monitor.id }); - createToast({ body: `Monitor ${monitor.isActive ? "paused" : "resumed"} successfully.` }); + createToast({ + body: `Monitor ${monitor.isActive ? "paused" : "resumed"} successfully.`, + }); updateCallback(); } catch (error) { - createToast({ body: `Failed to ${monitor.isActive ? "pause" : "resume"} monitor.` }); + createToast({ + body: `Failed to ${monitor.isActive ? "pause" : "resume"} monitor.`, + }); } - } + }; const handleRemove = async () => { try { @@ -122,13 +126,22 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { }} > openDetails(monitor.id)}>Details - {isAdmin && openConfigure(monitor.id)}>Configure} + {isAdmin && ( + openConfigure(monitor.id)}>Configure + )} {isAdmin && ( {monitor.isActive ? "Pause" : "Resume"} )} - {isAdmin && Remove} + {isAdmin && ( + + Remove + + )} Date: Tue, 24 Jun 2025 15:30:52 -0400 Subject: [PATCH 03/12] translation fix --- .../Components/MonitorsTableMenu/index.jsx | 28 +++++++++++-------- client/src/locales/en.json | 9 ++++++ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx index 76440f02d..87a870d09 100644 --- a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx +++ b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx @@ -10,6 +10,7 @@ import PropTypes from "prop-types"; import Dialog from "../../../../../Components/Dialog"; import { networkService } from "../../../../../Utils/NetworkService.js"; import { usePauseMonitor } from "../../../../../Hooks/monitorHooks"; +import { useTranslation } from "react-i18next"; /** * InfrastructureMenu Component @@ -31,6 +32,7 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { const [isDialogOpen, setIsDialogOpen] = useState(false); const theme = useTheme(); const [pauseMonitor] = usePauseMonitor(); + const { t } = useTranslation(); const openMenu = (e) => { e.stopPropagation(); @@ -64,12 +66,16 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { try { await pauseMonitor({ monitorId: monitor.id }); createToast({ - body: `Monitor ${monitor.isActive ? "paused" : "resumed"} successfully.`, + body: t("monitorActions.pauseResumeSuccess", "Monitor {{action}} successfully", { + action: monitor.isActive ? t("monitorActions.paused", "paused") : t("monitorActions.resumed", "resumed") + }), }); updateCallback(); } catch (error) { createToast({ - body: `Failed to ${monitor.isActive ? "pause" : "resume"} monitor.`, + body: t("monitorActions.pauseResumeFailed", "Failed to {{action}} monitor", { + action: monitor.isActive ? t("pause", "pause") : t("resume", "resume") + }), }); } }; @@ -79,9 +85,9 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { await networkService.deleteMonitorById({ monitorId: monitor.id, }); - createToast({ body: "Monitor deleted successfully." }); + createToast({ body: t("monitorActions.deleteSuccess", "Monitor deleted successfully") }); } catch (error) { - createToast({ body: "Failed to delete monitor." }); + createToast({ body: t("monitorActions.deleteFailed", "Failed to delete monitor") }); } finally { setIsDialogOpen(false); updateCallback(); @@ -125,13 +131,13 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { }, }} > - openDetails(monitor.id)}>Details + openDetails(monitor.id)}>{t("monitorActions.details", "Details")} {isAdmin && ( - openConfigure(monitor.id)}>Configure + openConfigure(monitor.id)}>{t("configure", "Configure")} )} {isAdmin && ( - {monitor.isActive ? "Pause" : "Resume"} + {monitor.isActive ? t("pause", "Pause") : t("resume", "Resume")} )} {isAdmin && ( @@ -139,17 +145,17 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { onClick={openRemove} sx={{ color: theme.palette.error.main }} > - Remove + {t("remove", "Remove")} )} Date: Sat, 28 Jun 2025 17:41:13 -0400 Subject: [PATCH 04/12] Fix infrastructure action menu: correct pause/resume text display and handle undefined monitor properties --- .../Components/MonitorsTableMenu/index.jsx | 69 +++++++++++++------ 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx index 87a870d09..c9052ef1c 100644 --- a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx +++ b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx @@ -1,6 +1,6 @@ /* TODO I basically copied and pasted this component from the actionsMenu. Check how we can make it reusable */ -import { useRef, useState } from "react"; +import { useRef, useState, useEffect } from "react"; import { useTheme } from "@emotion/react"; import { useNavigate } from "react-router-dom"; import { createToast } from "../../../../../Utils/toastUtils"; @@ -30,9 +30,21 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { const anchor = useRef(null); const [isOpen, setIsOpen] = useState(false); const [isDialogOpen, setIsDialogOpen] = useState(false); + const [localMonitorState, setLocalMonitorState] = useState(monitor); const theme = useTheme(); const [pauseMonitor] = usePauseMonitor(); const { t } = useTranslation(); + + // Update local state when monitor prop changes + useEffect(() => { + // Ensure we have a valid monitor object with default values for missing properties + if (monitor) { + setLocalMonitorState({ + ...monitor, + status: monitor.status || 'active' // Default to active if status is undefined + }); + } + }, [monitor]); const openMenu = (e) => { e.stopPropagation(); @@ -64,19 +76,21 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { const handlePause = async () => { try { - await pauseMonitor({ monitorId: monitor.id }); - createToast({ - body: t("monitorActions.pauseResumeSuccess", "Monitor {{action}} successfully", { - action: monitor.isActive ? t("monitorActions.paused", "paused") : t("monitorActions.resumed", "resumed") - }), - }); - updateCallback(); + // Toggle the local state immediately for better UI responsiveness + setLocalMonitorState(prevState => ({ + ...prevState, + status: prevState.status === "paused" ? "active" : "paused" + })); + + // Pass updateCallback as triggerUpdate to the hook + await pauseMonitor({ monitorId: monitor.id, triggerUpdate: updateCallback }); + // Toast is already displayed in the hook, no need to display it again } catch (error) { - createToast({ - body: t("monitorActions.pauseResumeFailed", "Failed to {{action}} monitor", { - action: monitor.isActive ? t("pause", "pause") : t("resume", "resume") - }), - }); + // Error handling is done in the hook - revert the local state on error + setLocalMonitorState(prevState => ({ + ...prevState, + status: prevState.status === "paused" ? "active" : "paused" + })); } }; @@ -131,13 +145,25 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { }, }} > - openDetails(monitor.id)}>{t("monitorActions.details", "Details")} + { + e.stopPropagation(); + openDetails(monitor.id); + closeMenu(e); + }}>{t("monitorActions.details", "Details")} {isAdmin && ( - openConfigure(monitor.id)}>{t("configure", "Configure")} + { + e.stopPropagation(); + openConfigure(monitor.id); + closeMenu(e); + }}>{t("configure", "Configure")} )} {isAdmin && ( - - {monitor.isActive ? t("pause", "Pause") : t("resume", "Resume")} + { + e.stopPropagation(); + await handlePause(); + closeMenu(e); + }}> + {localMonitorState?.status === "paused" ? t("resume", "Resume") : t("pause", "Pause")} )} {isAdmin && ( @@ -166,13 +192,14 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { InfrastructureMenu.propTypes = { monitor: PropTypes.shape({ - id: PropTypes.string, + id: PropTypes.string.isRequired, url: PropTypes.string, - type: PropTypes.string, + type: PropTypes.string, // Made optional isActive: PropTypes.bool, + status: PropTypes.string, }).isRequired, - isAdmin: PropTypes.bool, - updateCallback: PropTypes.func, + isAdmin: PropTypes.bool.isRequired, + updateCallback: PropTypes.func.isRequired, }; export { InfrastructureMenu }; From c44325ba7f4503b90fe7961086f2f23b3aa9f3e1 Mon Sep 17 00:00:00 2001 From: mohadeseh safari Date: Sat, 28 Jun 2025 18:46:17 -0400 Subject: [PATCH 05/12] Add missing translation keys for MonitorsTableMenu component --- client/src/locales/en.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/src/locales/en.json b/client/src/locales/en.json index 8d26f75fd..e94f3c758 100644 --- a/client/src/locales/en.json +++ b/client/src/locales/en.json @@ -483,6 +483,9 @@ "message": "Message", "monitor": "monitor", "monitorActions": { + "deleteSuccess": "Monitor deleted successfully", + "deleteFailed": "Failed to delete monitor", + "details": "Details", "export": "Export Monitors", "import": "Import Monitors", "title": "Export/Import" From 5ba82415adcd93b9b27489ff05225070d9a5d386 Mon Sep 17 00:00:00 2001 From: mohadeseh safari Date: Sat, 28 Jun 2025 18:50:14 -0400 Subject: [PATCH 06/12] Format MonitorsTableMenu component --- .../Components/MonitorsTableMenu/index.jsx | 65 ++++++++++++------- 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx index c9052ef1c..36ca945c2 100644 --- a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx +++ b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx @@ -34,14 +34,14 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { const theme = useTheme(); const [pauseMonitor] = usePauseMonitor(); const { t } = useTranslation(); - + // Update local state when monitor prop changes useEffect(() => { // Ensure we have a valid monitor object with default values for missing properties if (monitor) { setLocalMonitorState({ ...monitor, - status: monitor.status || 'active' // Default to active if status is undefined + status: monitor.status || "active", // Default to active if status is undefined }); } }, [monitor]); @@ -77,19 +77,19 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { const handlePause = async () => { try { // Toggle the local state immediately for better UI responsiveness - setLocalMonitorState(prevState => ({ + setLocalMonitorState((prevState) => ({ ...prevState, - status: prevState.status === "paused" ? "active" : "paused" + status: prevState.status === "paused" ? "active" : "paused", })); - + // Pass updateCallback as triggerUpdate to the hook await pauseMonitor({ monitorId: monitor.id, triggerUpdate: updateCallback }); // Toast is already displayed in the hook, no need to display it again } catch (error) { // Error handling is done in the hook - revert the local state on error - setLocalMonitorState(prevState => ({ + setLocalMonitorState((prevState) => ({ ...prevState, - status: prevState.status === "paused" ? "active" : "paused" + status: prevState.status === "paused" ? "active" : "paused", })); } }; @@ -99,7 +99,9 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { await networkService.deleteMonitorById({ monitorId: monitor.id, }); - createToast({ body: t("monitorActions.deleteSuccess", "Monitor deleted successfully") }); + createToast({ + body: t("monitorActions.deleteSuccess", "Monitor deleted successfully"), + }); } catch (error) { createToast({ body: t("monitorActions.deleteFailed", "Failed to delete monitor") }); } finally { @@ -145,25 +147,37 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { }, }} > - { - e.stopPropagation(); - openDetails(monitor.id); - closeMenu(e); - }}>{t("monitorActions.details", "Details")} - {isAdmin && ( - { + { e.stopPropagation(); - openConfigure(monitor.id); + openDetails(monitor.id); closeMenu(e); - }}>{t("configure", "Configure")} + }} + > + {t("monitorActions.details", "Details")} + + {isAdmin && ( + { + e.stopPropagation(); + openConfigure(monitor.id); + closeMenu(e); + }} + > + {t("configure", "Configure")} + )} {isAdmin && ( - { - e.stopPropagation(); - await handlePause(); - closeMenu(e); - }}> - {localMonitorState?.status === "paused" ? t("resume", "Resume") : t("pause", "Pause")} + { + e.stopPropagation(); + await handlePause(); + closeMenu(e); + }} + > + {localMonitorState?.status === "paused" + ? t("resume", "Resume") + : t("pause", "Pause")} )} {isAdmin && ( @@ -179,7 +193,10 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { open={isDialogOpen} theme={theme} title={t("deleteDialogTitle", "Do you really want to delete this monitor?")} - description={t("deleteDialogDescription", "Once deleted, this monitor cannot be retrieved.")} + description={t( + "deleteDialogDescription", + "Once deleted, this monitor cannot be retrieved." + )} onCancel={cancelRemove} confirmationButtonLabel={t("delete", "Delete")} onConfirm={handleRemove} From 1f804a725e40387558efe24b28d4e0ebf98c01b1 Mon Sep 17 00:00:00 2001 From: mohadeseh safari Date: Sat, 28 Jun 2025 19:05:21 -0400 Subject: [PATCH 07/12] Add comment explaining why monitor.type must remain optional in PropTypes --- .../Monitors/Components/MonitorsTableMenu/index.jsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx index 36ca945c2..69911adca 100644 --- a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx +++ b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx @@ -211,8 +211,10 @@ InfrastructureMenu.propTypes = { monitor: PropTypes.shape({ id: PropTypes.string.isRequired, url: PropTypes.string, - type: PropTypes.string, // Made optional - isActive: PropTypes.bool, + // Note: type must remain optional. Making it required (type: PropTypes.string.isRequired) + // causes runtime errors as some monitors don't have a defined type property + type: PropTypes.string, + isActive: PropTypes.bool, // Consider deprecating in favor of status status: PropTypes.string, }).isRequired, isAdmin: PropTypes.bool.isRequired, From fbbd9b90921d511274ac9bee862c4fefa1bfd343 Mon Sep 17 00:00:00 2001 From: mohadeseh safari Date: Sat, 28 Jun 2025 19:09:27 -0400 Subject: [PATCH 08/12] Format MonitorsTableMenu component --- .../Monitors/Components/MonitorsTableMenu/index.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx index 69911adca..7a1c57d23 100644 --- a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx +++ b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx @@ -211,7 +211,7 @@ InfrastructureMenu.propTypes = { monitor: PropTypes.shape({ id: PropTypes.string.isRequired, url: PropTypes.string, - // Note: type must remain optional. Making it required (type: PropTypes.string.isRequired) + // Note: type must remain optional. Making it required (type: PropTypes.string.isRequired) // causes runtime errors as some monitors don't have a defined type property type: PropTypes.string, isActive: PropTypes.bool, // Consider deprecating in favor of status From d842f93a19347df196ad7a3f45089e0502c37f92 Mon Sep 17 00:00:00 2001 From: mohadeseh safari Date: Sun, 6 Jul 2025 18:09:17 -0400 Subject: [PATCH 09/12] fix: Remove unnecessary local monitor state in InfrastructureMenu component --- .../Components/MonitorsTableMenu/index.jsx | 28 +++---------------- 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx index 7a1c57d23..73216650b 100644 --- a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx +++ b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx @@ -1,6 +1,6 @@ /* TODO I basically copied and pasted this component from the actionsMenu. Check how we can make it reusable */ -import { useRef, useState, useEffect } from "react"; +import { useRef, useState } from "react"; import { useTheme } from "@emotion/react"; import { useNavigate } from "react-router-dom"; import { createToast } from "../../../../../Utils/toastUtils"; @@ -30,21 +30,11 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { const anchor = useRef(null); const [isOpen, setIsOpen] = useState(false); const [isDialogOpen, setIsDialogOpen] = useState(false); - const [localMonitorState, setLocalMonitorState] = useState(monitor); const theme = useTheme(); const [pauseMonitor] = usePauseMonitor(); const { t } = useTranslation(); - // Update local state when monitor prop changes - useEffect(() => { - // Ensure we have a valid monitor object with default values for missing properties - if (monitor) { - setLocalMonitorState({ - ...monitor, - status: monitor.status || "active", // Default to active if status is undefined - }); - } - }, [monitor]); + const openMenu = (e) => { e.stopPropagation(); @@ -76,21 +66,11 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { const handlePause = async () => { try { - // Toggle the local state immediately for better UI responsiveness - setLocalMonitorState((prevState) => ({ - ...prevState, - status: prevState.status === "paused" ? "active" : "paused", - })); - // Pass updateCallback as triggerUpdate to the hook await pauseMonitor({ monitorId: monitor.id, triggerUpdate: updateCallback }); // Toast is already displayed in the hook, no need to display it again } catch (error) { - // Error handling is done in the hook - revert the local state on error - setLocalMonitorState((prevState) => ({ - ...prevState, - status: prevState.status === "paused" ? "active" : "paused", - })); + // Error handling is done in the hook } }; @@ -175,7 +155,7 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { closeMenu(e); }} > - {localMonitorState?.status === "paused" + {monitor.status === "paused" ? t("resume", "Resume") : t("pause", "Pause")} From 9edc6e4b271c6bfccc8a459c9d9a25057d672a2c Mon Sep 17 00:00:00 2001 From: mohadeseh safari Date: Sun, 6 Jul 2025 18:11:30 -0400 Subject: [PATCH 10/12] Fix formating --- .../Monitors/Components/MonitorsTableMenu/index.jsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx index 73216650b..080bf6409 100644 --- a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx +++ b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx @@ -34,8 +34,6 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { const [pauseMonitor] = usePauseMonitor(); const { t } = useTranslation(); - - const openMenu = (e) => { e.stopPropagation(); setIsOpen(true); @@ -155,9 +153,7 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { closeMenu(e); }} > - {monitor.status === "paused" - ? t("resume", "Resume") - : t("pause", "Pause")} + {monitor.status === "paused" ? t("resume", "Resume") : t("pause", "Pause")} )} {isAdmin && ( From aa8029a854f8cbf41ec6dd0d33fd0c8cb6a2857c Mon Sep 17 00:00:00 2001 From: mohadeseh safari Date: Mon, 7 Jul 2025 12:16:17 -0400 Subject: [PATCH 11/12] fix: Update InfrastructureMenu to use isActive instead of status for pause state --- .../Components/MonitorsTableMenu/index.jsx | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx index 080bf6409..61a0053f1 100644 --- a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx +++ b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx @@ -21,7 +21,7 @@ import { useTranslation } from "react-i18next"; * @param {string} props.monitor.id - Unique ID of the monitor. * @param {string} [props.monitor.url] - URL associated with the monitor. * @param {string} props.monitor.type - Type of monitor (e.g., uptime, infrastructure). - * @param {boolean} props.monitor.isActive - Indicates if the monitor is currently active. + * @param {boolean} props.monitor.isActive - Indicates if the monitor is currently active (true) or paused (false). * @param {boolean} props.isAdmin - Whether the user has admin privileges. * @param {Function} props.updateCallback - Callback to trigger when the monitor data is updated. * @returns {JSX.Element} The rendered component. @@ -63,13 +63,9 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { }; const handlePause = async () => { - try { - // Pass updateCallback as triggerUpdate to the hook - await pauseMonitor({ monitorId: monitor.id, triggerUpdate: updateCallback }); - // Toast is already displayed in the hook, no need to display it again - } catch (error) { - // Error handling is done in the hook - } + // Pass updateCallback as triggerUpdate to the hook + await pauseMonitor({ monitorId: monitor.id, triggerUpdate: updateCallback }); + // Toast is already displayed in the hook, no need to display it again }; const handleRemove = async () => { @@ -153,7 +149,7 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { closeMenu(e); }} > - {monitor.status === "paused" ? t("resume", "Resume") : t("pause", "Pause")} + {!monitor.isActive ? t("resume", "Resume") : t("pause", "Pause")} )} {isAdmin && ( @@ -190,8 +186,8 @@ InfrastructureMenu.propTypes = { // Note: type must remain optional. Making it required (type: PropTypes.string.isRequired) // causes runtime errors as some monitors don't have a defined type property type: PropTypes.string, - isActive: PropTypes.bool, // Consider deprecating in favor of status - status: PropTypes.string, + isActive: PropTypes.bool, // Determines whether the monitor is paused (false) or active (true) + status: PropTypes.string, // Represents the monitor's operational status (e.g., 'up', 'down', etc.) }).isRequired, isAdmin: PropTypes.bool.isRequired, updateCallback: PropTypes.func.isRequired, From 9254b9096c6e8e1b9c90b1f8043ebe84f99faf53 Mon Sep 17 00:00:00 2001 From: mohadeseh safari Date: Mon, 7 Jul 2025 12:17:59 -0400 Subject: [PATCH 12/12] refactor: Remove default string parameter from t() calls --- .../Components/MonitorsTableMenu/index.jsx | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx index 61a0053f1..147f1c297 100644 --- a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx +++ b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx @@ -74,10 +74,10 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { monitorId: monitor.id, }); createToast({ - body: t("monitorActions.deleteSuccess", "Monitor deleted successfully"), + body: t("monitorActions.deleteSuccess"), }); } catch (error) { - createToast({ body: t("monitorActions.deleteFailed", "Failed to delete monitor") }); + createToast({ body: t("monitorActions.deleteFailed") }); } finally { setIsDialogOpen(false); updateCallback(); @@ -128,7 +128,7 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { closeMenu(e); }} > - {t("monitorActions.details", "Details")} + {t("monitorActions.details")} {isAdmin && ( { closeMenu(e); }} > - {t("configure", "Configure")} + {t("configure")} )} {isAdmin && ( @@ -149,7 +149,7 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { closeMenu(e); }} > - {!monitor.isActive ? t("resume", "Resume") : t("pause", "Pause")} + {!monitor.isActive ? t("resume") : t("pause")} )} {isAdmin && ( @@ -157,20 +157,17 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { onClick={openRemove} sx={{ color: theme.palette.error.main }} > - {t("remove", "Remove")} + {t("remove")} )}