diff --git a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx index 15193da3e..147f1c297 100644 --- a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx +++ b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx @@ -9,6 +9,8 @@ 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"; +import { useTranslation } from "react-i18next"; /** * InfrastructureMenu Component @@ -19,7 +21,7 @@ import { networkService } from "../../../../../Utils/NetworkService.js"; * @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. @@ -29,6 +31,8 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { const [isOpen, setIsOpen] = useState(false); const [isDialogOpen, setIsDialogOpen] = useState(false); const theme = useTheme(); + const [pauseMonitor] = usePauseMonitor(); + const { t } = useTranslation(); const openMenu = (e) => { e.stopPropagation(); @@ -54,14 +58,26 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { navigate(`/infrastructure/${id}`); } + const openConfigure = (id) => { + navigate(`/infrastructure/configure/${id}`); + }; + + const handlePause = async () => { + // 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 () => { try { await networkService.deleteMonitorById({ monitorId: monitor.id, }); - createToast({ body: "Monitor deleted successfully." }); + createToast({ + body: t("monitorActions.deleteSuccess"), + }); } catch (error) { - createToast({ body: "Failed to delete monitor." }); + createToast({ body: t("monitorActions.deleteFailed") }); } finally { setIsDialogOpen(false); updateCallback(); @@ -105,15 +121,53 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { }, }} > - {isAdmin && Remove} + { + e.stopPropagation(); + openDetails(monitor.id); + closeMenu(e); + }} + > + {t("monitorActions.details")} + + {isAdmin && ( + { + e.stopPropagation(); + openConfigure(monitor.id); + closeMenu(e); + }} + > + {t("configure")} + + )} + {isAdmin && ( + { + e.stopPropagation(); + await handlePause(); + closeMenu(e); + }} + > + {!monitor.isActive ? t("resume") : t("pause")} + + )} + {isAdmin && ( + + {t("remove")} + + )} { InfrastructureMenu.propTypes = { monitor: PropTypes.shape({ - id: PropTypes.string, + id: PropTypes.string.isRequired, url: PropTypes.string, + // 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, + 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, - updateCallback: PropTypes.func, + isAdmin: PropTypes.bool.isRequired, + updateCallback: PropTypes.func.isRequired, }; export { InfrastructureMenu }; diff --git a/client/src/locales/en.json b/client/src/locales/en.json index 483714d13..a5d0d132a 100644 --- a/client/src/locales/en.json +++ b/client/src/locales/en.json @@ -490,6 +490,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"