From 76f4143097e13d9d4172fcc518b27faa02f1e55e Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 31 Jul 2024 13:59:14 -0700 Subject: [PATCH 1/5] Notifications removed and readded on monitor edit --- Server/controllers/monitorController.js | 16 ++++++++++++++++ Server/db/mongo/modules/monitorModule.js | 2 ++ 2 files changed, 18 insertions(+) diff --git a/Server/controllers/monitorController.js b/Server/controllers/monitorController.js index 8f7e21453..e05ed0389 100644 --- a/Server/controllers/monitorController.js +++ b/Server/controllers/monitorController.js @@ -234,7 +234,23 @@ const editMonitor = async (req, res, next) => { try { const monitorBeforeEdit = await req.db.getMonitorById(req, res); + + // Get notifications from the request body + const notifications = req.body.notifications; + const editedMonitor = await req.db.editMonitor(req, res); + + await req.db.deleteNotificationsByMonitorId(editedMonitor._id); + + if (notifications && notifications.length !== 0) { + await Promise.all( + notifications.map(async (notification) => { + notification.monitorId = editedMonitor._id; + await req.db.createNotification(notification); + }) + ); + } + // Delete the old job(editedMonitor has the same ID as the old monitor) await req.jobQueue.deleteJob(monitorBeforeEdit); // Add the new job back to the queue diff --git a/Server/db/mongo/modules/monitorModule.js b/Server/db/mongo/modules/monitorModule.js index f82496551..6f795e35a 100644 --- a/Server/db/mongo/modules/monitorModule.js +++ b/Server/db/mongo/modules/monitorModule.js @@ -209,6 +209,8 @@ const deleteMonitorsByUserId = async (userId) => { const editMonitor = async (req, res) => { const candidateId = req.params.monitorId; const candidateMonitor = req.body; + candidateMonitor.notifications = undefined; + try { const editedMonitor = await Monitor.findByIdAndUpdate( candidateId, From 4ce67b54b6b8b851441f67bb8c9ef95ebfc7e11b Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Wed, 31 Jul 2024 19:20:50 -0400 Subject: [PATCH 2/5] Added icons to integrations page --- Client/src/Pages/Integrations/index.jsx | 45 ++++++++++++++++-------- Client/src/assets/icons/discord-icon.svg | 8 +++++ Client/src/assets/icons/slack-icon.svg | 10 ++++++ Client/src/assets/icons/zapier-icon.svg | 8 +++++ 4 files changed, 57 insertions(+), 14 deletions(-) create mode 100644 Client/src/assets/icons/discord-icon.svg create mode 100644 Client/src/assets/icons/slack-icon.svg create mode 100644 Client/src/assets/icons/zapier-icon.svg diff --git a/Client/src/Pages/Integrations/index.jsx b/Client/src/Pages/Integrations/index.jsx index 376ef6657..dc8e668e0 100644 --- a/Client/src/Pages/Integrations/index.jsx +++ b/Client/src/Pages/Integrations/index.jsx @@ -2,19 +2,22 @@ import PropTypes from "prop-types"; import { Stack, Box, Typography, Grid } from "@mui/material"; import Button from "../../Components/Button"; import { useTheme } from "@emotion/react"; +import Discord from "../../assets/icons/discord-icon.svg?react"; +import Slack from "../../assets/icons/slack-icon.svg?react"; +import Zapier from "../../assets/icons/zapier-icon.svg?react"; import "./index.css"; /** * Integrations component * @param {Object} props - Props for the IntegrationsComponent. - * @param {string} props.url - The URL for the integration image. + * @param {string} props.icon - The icon for the integration image. * @param {string} props.header - The header for the integration. * @param {string} props.info - Information about the integration. * @param {Function} props.onClick - The onClick handler for the integration button. * @returns {JSX.Element} The JSX representation of the IntegrationsComponent. */ -const IntegrationsComponent = ({ url, header, info, onClick }) => { +const IntegrationsComponent = ({ icon, header, info, onClick }) => { const theme = useTheme(); return ( @@ -24,14 +27,12 @@ const IntegrationsComponent = ({ url, header, info, onClick }) => { justifyContent="space-between" gap={theme.gap.large} p={theme.gap.ml} + pl={theme.gap.large} + height="100%" > - + + {icon} + {header} { level="primary" onClick={onClick} sx={{ alignSelf: "center" }} + disabled={true} /> @@ -56,7 +58,7 @@ const IntegrationsComponent = ({ url, header, info, onClick }) => { // PropTypes for IntegrationsComponent IntegrationsComponent.propTypes = { - url: PropTypes.string.isRequired, + icon: PropTypes.object.isRequired, header: PropTypes.string.isRequired, info: PropTypes.string.isRequired, onClick: PropTypes.func.isRequired, @@ -72,19 +74,34 @@ const Integrations = () => { const integrations = [ { - url: "https://via.placeholder.com/80", + icon: ( + + ), header: "Slack", info: "Connect with Slack and see incidents in a channel", onClick: () => {}, }, { - url: "https://via.placeholder.com/80", + icon: ( + + ), header: "Discord", info: "Connect with Discord and view incidents directly in a channel", onClick: () => {}, }, { - url: "https://via.placeholder.com/80", + icon: ( + + ), header: "Zapier", info: "Send all incidents to Zapier, and then see them everywhere", onClick: () => {}, @@ -102,7 +119,7 @@ const Integrations = () => { {integrations.map((integration, index) => ( + + + + + + + \ No newline at end of file diff --git a/Client/src/assets/icons/slack-icon.svg b/Client/src/assets/icons/slack-icon.svg new file mode 100644 index 000000000..ff256fd4d --- /dev/null +++ b/Client/src/assets/icons/slack-icon.svg @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Client/src/assets/icons/zapier-icon.svg b/Client/src/assets/icons/zapier-icon.svg new file mode 100644 index 000000000..6ee0b5eca --- /dev/null +++ b/Client/src/assets/icons/zapier-icon.svg @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file From c48249e30dbb92ac09b793f4b7c9d0512443839f Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Wed, 31 Jul 2024 19:23:52 -0400 Subject: [PATCH 3/5] Removed redundant code --- Client/src/Pages/Integrations/index.jsx | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Client/src/Pages/Integrations/index.jsx b/Client/src/Pages/Integrations/index.jsx index dc8e668e0..75da41a6b 100644 --- a/Client/src/Pages/Integrations/index.jsx +++ b/Client/src/Pages/Integrations/index.jsx @@ -1,5 +1,5 @@ import PropTypes from "prop-types"; -import { Stack, Box, Typography, Grid } from "@mui/material"; +import { Stack, Typography, Grid } from "@mui/material"; import Button from "../../Components/Button"; import { useTheme } from "@emotion/react"; import Discord from "../../assets/icons/discord-icon.svg?react"; @@ -30,9 +30,7 @@ const IntegrationsComponent = ({ icon, header, info, onClick }) => { pl={theme.gap.large} height="100%" > - - {icon} - + {icon} {header} { icon: ( ), header: "Slack", @@ -88,7 +86,7 @@ const Integrations = () => { icon: ( ), header: "Discord", @@ -99,7 +97,7 @@ const Integrations = () => { icon: ( ), header: "Zapier", From b126830110587b916a50acd87e86de391a95e9a2 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 31 Jul 2024 20:20:04 -0700 Subject: [PATCH 4/5] Add notifications to monitors before returning --- Server/db/mongo/modules/monitorModule.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Server/db/mongo/modules/monitorModule.js b/Server/db/mongo/modules/monitorModule.js index 6f795e35a..65dae92b2 100644 --- a/Server/db/mongo/modules/monitorModule.js +++ b/Server/db/mongo/modules/monitorModule.js @@ -2,6 +2,7 @@ const Monitor = require("../../../models/Monitor"); const Check = require("../../../models/Check"); const PageSpeedCheck = require("../../../models/PageSpeedCheck"); const { errorMessages } = require("../../../utils/messages"); +const Notification = require("../../../models/Notification"); /** * Get all monitors @@ -119,7 +120,12 @@ const getMonitorsByUserId = async (req, res) => { createdAt: sortOrder, }) .limit(limit); - return { ...monitor.toObject(), checks }; + + // Get notifications + const notifications = await Notification.find({ + monitorId: monitor._id, + }); + return { ...monitor.toObject(), checks, notifications }; }) ); return monitorsWithChecks; From 75a897716f437d1393982a68c3b7904e586544af Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 31 Jul 2024 20:22:11 -0700 Subject: [PATCH 5/5] Add notifcations to getMonitorById as well --- Server/db/mongo/modules/monitorModule.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Server/db/mongo/modules/monitorModule.js b/Server/db/mongo/modules/monitorModule.js index 65dae92b2..9bca432c2 100644 --- a/Server/db/mongo/modules/monitorModule.js +++ b/Server/db/mongo/modules/monitorModule.js @@ -64,7 +64,8 @@ const getMonitorById = async (req, res) => { createdAt: sortOrder, }) .limit(limit); - const monitorWithChecks = { ...monitor.toObject(), checks }; + const notifications = await Notification.find({ monitorId: monitor._id }); + const monitorWithChecks = { ...monitor.toObject(), checks, notifications }; return monitorWithChecks; } catch (error) { throw error;