From e9debd202b09620249d958c0caeabd6ee80404da Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 27 Aug 2024 15:18:18 -0700 Subject: [PATCH] Refactored monitor page for readability --- Client/src/App.jsx | 2 +- .../src/Pages/Monitors/Home/actionsMenu.jsx | 199 ++++++++ Client/src/Pages/Monitors/Home/fallback.jsx | 43 ++ Client/src/Pages/Monitors/Home/host.jsx | 33 ++ .../src/Pages/Monitors/{ => Home}/index.css | 0 Client/src/Pages/Monitors/Home/index.jsx | 110 +++++ .../src/Pages/Monitors/Home/monitorData.jsx | 77 +++ Client/src/Pages/Monitors/Home/skeleton.jsx | 36 ++ Client/src/Pages/Monitors/index.jsx | 451 ------------------ 9 files changed, 499 insertions(+), 452 deletions(-) create mode 100644 Client/src/Pages/Monitors/Home/actionsMenu.jsx create mode 100644 Client/src/Pages/Monitors/Home/fallback.jsx create mode 100644 Client/src/Pages/Monitors/Home/host.jsx rename Client/src/Pages/Monitors/{ => Home}/index.css (100%) create mode 100644 Client/src/Pages/Monitors/Home/index.jsx create mode 100644 Client/src/Pages/Monitors/Home/monitorData.jsx create mode 100644 Client/src/Pages/Monitors/Home/skeleton.jsx delete mode 100644 Client/src/Pages/Monitors/index.jsx diff --git a/Client/src/App.jsx b/Client/src/App.jsx index f8a2f72f5..22313a50b 100644 --- a/Client/src/App.jsx +++ b/Client/src/App.jsx @@ -7,7 +7,7 @@ import Login from "./Pages/Auth/Login"; import Register from "./Pages/Auth/Register/Register"; import HomeLayout from "./Layouts/HomeLayout"; import Account from "./Pages/Account"; -import Monitors from "./Pages/Monitors"; +import Monitors from "./Pages/Monitors/Home"; import CreateMonitor from "./Pages/Monitors/CreateMonitor"; import Incidents from "./Pages/Incidents"; import Status from "./Pages/Status"; diff --git a/Client/src/Pages/Monitors/Home/actionsMenu.jsx b/Client/src/Pages/Monitors/Home/actionsMenu.jsx new file mode 100644 index 000000000..b2b26e92a --- /dev/null +++ b/Client/src/Pages/Monitors/Home/actionsMenu.jsx @@ -0,0 +1,199 @@ +import { useState } from "react"; +import { useSelector, useDispatch } from "react-redux"; +import { createToast } from "../../../Utils/toastUtils"; +import { + IconButton, + Menu, + MenuItem, + Modal, + Stack, + Typography, +} from "@mui/material"; +import { + deleteUptimeMonitor, + getUptimeMonitorsByTeamId, +} from "../../../Features/UptimeMonitors/uptimeMonitorsSlice"; +import Settings from "../../../assets/icons/settings-bold.svg?react"; +import { useTheme } from "@emotion/react"; +import Button from "../../../Components/Button"; +import PropTypes from "prop-types"; +import { useNavigate } from "react-router-dom"; + +const ActionsMenu = ({ monitor, isAdmin }) => { + 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(getUptimeMonitorsByTeamId(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 + {isAdmin && ( + { + e.stopPropagation(); + + navigate(`/monitors/configure/${actions.id}`); + }} + > + Configure + + )} + {isAdmin && ( + { + e.stopPropagation(); + openRemove(e); + }} + > + Remove + + )} + + setIsOpen(false)} + disablePortal + > + + + Do you really want to delete this monitor? + + + Once deleted, this monitor cannot be retrieved. + + +