From 1ef7483fed0137bec0962ed7bdf489c44049700b Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Sun, 18 Aug 2024 22:52:58 -0700 Subject: [PATCH 1/3] Refactored action menu --- .../src/Pages/Monitors/ActionMenu/index.jsx | 88 +++++++++++++++++++ Client/src/Pages/Monitors/index.jsx | 73 ++------------- 2 files changed, 95 insertions(+), 66 deletions(-) create mode 100644 Client/src/Pages/Monitors/ActionMenu/index.jsx diff --git a/Client/src/Pages/Monitors/ActionMenu/index.jsx b/Client/src/Pages/Monitors/ActionMenu/index.jsx new file mode 100644 index 000000000..a8fb437bc --- /dev/null +++ b/Client/src/Pages/Monitors/ActionMenu/index.jsx @@ -0,0 +1,88 @@ +import { useState } from "react"; +import { Box, IconButton, Menu, MenuItem } from "@mui/material"; +import Settings from "../../../assets/icons/settings-bold.svg?react"; +import { useNavigate } from "react-router-dom"; + +const ActionsMenu = ({ monitor }) => { + const [anchorEl, setAnchorEl] = useState(null); + const [actions, setActions] = useState({}); + const openMenu = (event, id, url) => { + event.preventDefault(); + setAnchorEl(event.currentTarget); + setActions({ id: id, url: url }); + }; + + const openRemove = () => { + closeMenu(); + setIsOpen(true); + }; + + const closeMenu = () => { + setAnchorEl(null); + }; + + const navigate = useNavigate(); + return ( + <> + { + event.stopPropagation(); + openMenu( + event, + monitor._id, + monitor.type === "ping" ? null : monitor.url + ); + }} + sx={{ + "&:focus": { + outline: "none", + }, + }} + > + + + + + {actions.url !== null ? ( + { + window.open(actions.url, "_blank", "noreferrer"); + }} + > + Open site + + ) : ( + "" + )} + { + e.stopPropagation(); + navigate(`/monitors/${actions.id}`); + }} + > + Details + + {/* TODO - pass monitor id to Incidents page */} + Incidents + { + e.stopPropagation(); + + navigate(`/monitors/configure/${actions.id}`); + }} + > + Configure + + Remove + + + ); +}; + +export default ActionsMenu; diff --git a/Client/src/Pages/Monitors/index.jsx b/Client/src/Pages/Monitors/index.jsx index b80e88f5a..24ab4d172 100644 --- a/Client/src/Pages/Monitors/index.jsx +++ b/Client/src/Pages/Monitors/index.jsx @@ -11,7 +11,6 @@ import ServerStatus from "../../Components/Charts/Servers/ServerStatus"; import { useTheme } from "@emotion/react"; import ArrowDownwardRoundedIcon from "@mui/icons-material/ArrowDownwardRounded"; import OpenInNewPage from "../../assets/icons/open-in-new-page.svg?react"; -import Settings from "../../assets/icons/settings-bold.svg?react"; import BasicTable from "../../Components/BasicTable"; import { StatusLabel } from "../../Components/Label"; import { createToast } from "../../Utils/toastUtils"; @@ -26,6 +25,7 @@ import { Stack, Typography, } from "@mui/material"; +import ActionsMenu from "./ActionMenu"; /** * Host component. @@ -111,22 +111,8 @@ const Monitors = () => { const authState = useSelector((state) => state.auth); const dispatch = useDispatch({}); - const [anchorEl, setAnchorEl] = useState(null); - const [actions, setActions] = useState({}); - const openMenu = (event, id, url) => { - event.preventDefault(); - setAnchorEl(event.currentTarget); - setActions({ id: id, url: url }); - }; - const closeMenu = () => { - setAnchorEl(null); - }; - const [isOpen, setIsOpen] = useState(false); - const openRemove = () => { - closeMenu(); - setIsOpen(true); - }; + const handleRemove = async (event) => { event.preventDefault(); let monitor = { _id: actions.id }; @@ -191,7 +177,9 @@ const Monitors = () => { return { id: monitor._id, // disabled for now - handleClick: () => navigate(`/monitors/${monitor._id}`), + handleClick: () => { + navigate(`/monitors/${monitor._id}`); + }, data: [ { id: idx, data: }, { @@ -213,28 +201,7 @@ const Monitors = () => { }, { id: idx + 4, - data: ( - <> - { - event.stopPropagation(); - openMenu( - event, - monitor._id, - monitor.type === "ping" ? null : monitor.url - ); - }} - sx={{ - "&:focus": { - outline: "none", - }, - }} - > - - - - ), + data: , }, ], }; @@ -327,33 +294,7 @@ const Monitors = () => { )} )} - - {actions.url !== null ? ( - { - window.open(actions.url, "_blank", "noreferrer"); - }} - > - Open site - - ) : ( - "" - )} - navigate(`/monitors/${actions.id}`)}> - Details - - {/* TODO - pass monitor id to Incidents page */} - Incidents - navigate(`/monitors/configure/${actions.id}`)}> - Configure - - Remove - + Date: Mon, 19 Aug 2024 11:28:56 -0700 Subject: [PATCH 2/3] Moved action menu back into Monitor page as separate component, refactored modal --- .../src/Pages/Monitors/ActionMenu/index.jsx | 88 ------- Client/src/Pages/Monitors/index.jsx | 231 +++++++++++++----- 2 files changed, 166 insertions(+), 153 deletions(-) delete mode 100644 Client/src/Pages/Monitors/ActionMenu/index.jsx diff --git a/Client/src/Pages/Monitors/ActionMenu/index.jsx b/Client/src/Pages/Monitors/ActionMenu/index.jsx deleted file mode 100644 index a8fb437bc..000000000 --- a/Client/src/Pages/Monitors/ActionMenu/index.jsx +++ /dev/null @@ -1,88 +0,0 @@ -import { useState } from "react"; -import { Box, IconButton, Menu, MenuItem } from "@mui/material"; -import Settings from "../../../assets/icons/settings-bold.svg?react"; -import { useNavigate } from "react-router-dom"; - -const ActionsMenu = ({ monitor }) => { - const [anchorEl, setAnchorEl] = useState(null); - const [actions, setActions] = useState({}); - const openMenu = (event, id, url) => { - event.preventDefault(); - setAnchorEl(event.currentTarget); - setActions({ id: id, url: url }); - }; - - const openRemove = () => { - closeMenu(); - setIsOpen(true); - }; - - const closeMenu = () => { - setAnchorEl(null); - }; - - const navigate = useNavigate(); - return ( - <> - { - event.stopPropagation(); - openMenu( - event, - monitor._id, - monitor.type === "ping" ? null : monitor.url - ); - }} - sx={{ - "&:focus": { - outline: "none", - }, - }} - > - - - - - {actions.url !== null ? ( - { - window.open(actions.url, "_blank", "noreferrer"); - }} - > - Open site - - ) : ( - "" - )} - { - e.stopPropagation(); - navigate(`/monitors/${actions.id}`); - }} - > - Details - - {/* TODO - pass monitor id to Incidents page */} - Incidents - { - e.stopPropagation(); - - navigate(`/monitors/configure/${actions.id}`); - }} - > - Configure - - Remove - - - ); -}; - -export default ActionsMenu; diff --git a/Client/src/Pages/Monitors/index.jsx b/Client/src/Pages/Monitors/index.jsx index 24ab4d172..19a4b4c4f 100644 --- a/Client/src/Pages/Monitors/index.jsx +++ b/Client/src/Pages/Monitors/index.jsx @@ -25,7 +25,172 @@ import { Stack, Typography, } from "@mui/material"; -import ActionsMenu from "./ActionMenu"; + +import Settings from "../../assets/icons/settings-bold.svg?react"; + +const ActionsMenu = ({ monitor }) => { + const [anchorEl, setAnchorEl] = useState(null); + const [actions, setActions] = useState({}); + const [isOpen, setIsOpen] = useState(false); + const dispatch = useDispatch(); + const theme = useTheme(); + const authState = useSelector((state) => state.auth); + + const handleRemove = async (event) => { + event.preventDefault(); + event.stopPropagation(); + let monitor = { _id: actions.id }; + const action = await dispatch( + deleteUptimeMonitor({ authToken: authState.authToken, monitor }) + ); + if (action.meta.requestStatus === "fulfilled") { + setIsOpen(false); // close modal + dispatch(getUptimeMonitorsByUserId(authState.authToken)); + createToast({ body: "Monitor deleted successfully." }); + } else { + createToast({ body: "Failed to delete monitor." }); + } + }; + + const openMenu = (event, id, url) => { + event.preventDefault(); + event.stopPropagation(); + setAnchorEl(event.currentTarget); + setActions({ id: id, url: url }); + }; + + const openRemove = (e) => { + closeMenu(e); + setIsOpen(true); + }; + + const closeMenu = (e) => { + e.stopPropagation(); + setAnchorEl(null); + }; + + const navigate = useNavigate(); + return ( + <> + { + event.stopPropagation(); + openMenu( + event, + monitor._id, + monitor.type === "ping" ? null : monitor.url + ); + }} + sx={{ + "&:focus": { + outline: "none", + }, + }} + > + + + + closeMenu(e)} + > + {actions.url !== null ? ( + { + closeMenu(e); + e.stopPropagation(); + window.open(actions.url, "_blank", "noreferrer"); + }} + > + Open site + + ) : ( + "" + )} + { + e.stopPropagation(); + navigate(`/monitors/${actions.id}`); + }} + > + Details + + {/* TODO - pass monitor id to Incidents page */} + Incidents + { + e.stopPropagation(); + + navigate(`/monitors/configure/${actions.id}`); + }} + > + Configure + + { + e.stopPropagation(); + openRemove(e); + }} + > + Remove + + + setIsOpen(false)} + disablePortal + > + + + Do you really want to delete this monitor? + + + Once deleted, this monitor cannot be retrieved. + + +