From 7b04fcb9fed197c0b5a3663a9e027dc2cf08f054 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 5 Jul 2024 13:30:09 -0700 Subject: [PATCH 1/5] Initial refactor --- Client/src/Components/MonitorTable/index.css | 49 +++++++ Client/src/Components/MonitorTable/index.jsx | 129 +++++++++++++++++++ Client/src/Pages/Monitors/index.jsx | 2 + Client/src/Pages/Monitors/monitors.css | 25 ---- Client/src/Pages/TestUpload/index.jsx | 17 +++ Server/db/MongoDB.js | 4 +- 6 files changed, 199 insertions(+), 27 deletions(-) create mode 100644 Client/src/Components/MonitorTable/index.css create mode 100644 Client/src/Components/MonitorTable/index.jsx create mode 100644 Client/src/Pages/TestUpload/index.jsx diff --git a/Client/src/Components/MonitorTable/index.css b/Client/src/Components/MonitorTable/index.css new file mode 100644 index 000000000..23b463f87 --- /dev/null +++ b/Client/src/Components/MonitorTable/index.css @@ -0,0 +1,49 @@ +.host-row { + display: flex; + align-items: center; +} + +.host-open-icon { + width: var(--env-var-img-width-2); + height: var(--env-var-img-width-2); + margin-right: 8px; +} + +.host-name { + width: 100px; + font-size: var(--env-var-font-size-medium); + font-weight: bold; + margin-right: var(--env-var-spacing-1); + text-overflow: ellipsis; + overflow: hidden; + white-space: nowrap; +} + +.host-percentage { + font-size: var(--env-var-font-size-medium); +} + +.host-status { + display: flex; + align-items: center; + height: 100%; +} + +.host-status-details { + display: flex; + align-items: center; + border: 1px solid var(--env-var-color-4); + border-radius: var(--env-var-radius-2); + padding: calc(var(--env-var-spacing-1) / 2); +} + +.host-status-text { + font-size: var(--env-var-font-size-medium); + line-height: var(--env-var-font-size-medium); +} +.host-status-dot { + width: 6px; + height: 6px; + border-radius: 50%; + margin-right: calc(var(--env-var-spacing-1) / 2); +} diff --git a/Client/src/Components/MonitorTable/index.jsx b/Client/src/Components/MonitorTable/index.jsx new file mode 100644 index 000000000..4b7b3ab87 --- /dev/null +++ b/Client/src/Components/MonitorTable/index.jsx @@ -0,0 +1,129 @@ +import "./index.css"; +import PropTypes from "prop-types"; +import { DataGrid } from "@mui/x-data-grid"; +import OpenIt from "../../assets/Images/Icon-open-in-tab-gray.png"; +import ResponseTimeChart from "../Charts/ResponseTimeChart"; + +const Host = ({ params }) => { + return ( +
+ + OpenIt + +
{params.value.title}
+
+ {params.value.precentage}% +
+
+ ); +}; + +const Status = ({ params }) => { + console.log(params.value.status); + return ( +
+
+
+ {params.value.status} +
+
+ ); +}; + +const cols = [ + { + field: "host", + headerName: "Host", + renderCell: (params) => { + return ; + }, + flex: 1, + }, + { + field: "status", + headerName: "Status", + renderCell: (params) => { + return ; + }, + }, + { + field: "response", + headerName: "Response", + renderCell: (params) => { + return ; + }, + flex: 1, + }, + { + field: "actions", + headerName: "Actions", + }, +]; + +let rows = []; + +const MonitorTable = ({ monitors = [] }) => { + rows = monitors.map((monitor) => { + return { + id: monitor._id, + host: { + title: monitor.name, + url: monitor.url, + precentage: 100, + percentageColor: + monitor.status === true + ? "var(--env-var-color-17)" + : "var(--env-var-color-19)", + }, + status: { + status: monitor.status === true ? "Up" : "Down", + backgroundColor: + monitor.status === true + ? "var(--env-var-color-20)" + : "var(--env-var-color-21)", + statusDotColor: + monitor.status === true + ? "var(--env-var-color-17)" + : "var(--env-var-color-19)", + }, + response: { + checks: monitor.checks, + }, + }; + }); + + return ( +
+

Monitor Table

+ +
+ ); +}; + +MonitorTable.propTypes = { + monitors: PropTypes.arrayOf(PropTypes.object).isRequired, +}; + +Status.propTypes = { params: PropTypes.object.isRequired }; +Host.propTypes = { params: PropTypes.object.isRequired }; + +export default MonitorTable; diff --git a/Client/src/Pages/Monitors/index.jsx b/Client/src/Pages/Monitors/index.jsx index 4c6d18606..7adfc13cd 100644 --- a/Client/src/Pages/Monitors/index.jsx +++ b/Client/src/Pages/Monitors/index.jsx @@ -9,6 +9,7 @@ import ServerStatus from "../../Components/Charts/Servers/ServerStatus"; import SearchTextField from "../../Components/TextFields/Search/SearchTextField"; import HostsTable from "../../Components/HostsTable"; import Pagination from "../../Components/Pagination"; +import MonitorTable from "../../Components/MonitorTable"; const Monitors = () => { const navigate = useNavigate(); @@ -28,6 +29,7 @@ const Monitors = () => { return (
+
Hello, {authState.user.firstname} diff --git a/Client/src/Pages/Monitors/monitors.css b/Client/src/Pages/Monitors/monitors.css index c2ed8532f..3a442aa42 100644 --- a/Client/src/Pages/Monitors/monitors.css +++ b/Client/src/Pages/Monitors/monitors.css @@ -66,24 +66,6 @@ font-size: var(--env-var-font-size-medium); } -.host-list-item { - display: flex; - align-items: center; - cursor: pointer; -} - -.host-list-item-open { - width: var(--env-var-img-width-2); - height: var(--env-var-img-width-2); - margin-right: 8px; -} - -.host-list-item-name { - font-size: var(--env-var-font-size-medium); - font-weight: bold; - margin-right: var(--env-var-spacing-1); -} - .host-list-item-precentage { font-size: var(--env-var-font-size-medium); } @@ -101,13 +83,6 @@ padding: calc(var(--env-var-spacing-1) / 2); } -.host-status-box-circle { - width: 6px; - height: 6px; - border-radius: 50%; - margin-right: calc(var(--env-var-spacing-1) / 2); -} - .host-actions { margin: auto; cursor: pointer; diff --git a/Client/src/Pages/TestUpload/index.jsx b/Client/src/Pages/TestUpload/index.jsx new file mode 100644 index 000000000..809aa44f7 --- /dev/null +++ b/Client/src/Pages/TestUpload/index.jsx @@ -0,0 +1,17 @@ +import { useState } from "react"; + +const TestUpload = () => { + const [file, setFile] = useState(); + function handleChange(e) { + setFile(URL.createObjectURL(e.target.files[0])); + } + + return ( +
+ + +
+ ); +}; + +export default TestUpload; diff --git a/Server/db/MongoDB.js b/Server/db/MongoDB.js index 83668a512..1d16a14d3 100644 --- a/Server/db/MongoDB.js +++ b/Server/db/MongoDB.js @@ -68,8 +68,8 @@ const getUserByEmail = async (req, res) => { try { // Need the password to be able to compare, removed .select() // We can strip the hash before returing the user - const user = await UserModel.findOne( - { email: req.body.email }.select("-profileImage") + const user = await UserModel.findOne({ email: req.body.email }).select( + "-profileImage" ); if (user) { return user; From 4e1f0095a71116b87aa041541b1d913b5f2a6e2f Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 5 Jul 2024 14:38:16 -0700 Subject: [PATCH 2/5] Removed animation from chart --- .../Charts/ResponseTimeChart/index.jsx | 2 +- Client/src/Components/MonitorTable/index.jsx | 90 +++++++++---------- Client/src/Pages/Monitors/index.jsx | 11 +-- 3 files changed, 48 insertions(+), 55 deletions(-) diff --git a/Client/src/Components/Charts/ResponseTimeChart/index.jsx b/Client/src/Components/Charts/ResponseTimeChart/index.jsx index 2121169b6..0518ebee8 100644 --- a/Client/src/Components/Charts/ResponseTimeChart/index.jsx +++ b/Client/src/Components/Charts/ResponseTimeChart/index.jsx @@ -54,7 +54,7 @@ const ResponseTimeChart = ({ checks = [] }) => {
- + {normalizedChecks.map((check, index) => ( { return (
@@ -22,7 +22,6 @@ const Host = ({ params }) => { }; const Status = ({ params }) => { - console.log(params.value.status); return (
{ - rows = monitors.map((monitor) => { - return { - id: monitor._id, - host: { - title: monitor.name, - url: monitor.url, - precentage: 100, - percentageColor: - monitor.status === true - ? "var(--env-var-color-17)" - : "var(--env-var-color-19)", - }, - status: { - status: monitor.status === true ? "Up" : "Down", - backgroundColor: - monitor.status === true - ? "var(--env-var-color-20)" - : "var(--env-var-color-21)", - statusDotColor: - monitor.status === true - ? "var(--env-var-color-17)" - : "var(--env-var-color-19)", - }, - response: { - checks: monitor.checks, - }, - }; - }); + const [rows, setRows] = useState([]); + useEffect(() => { + const mappedRows = monitors.map((monitor) => { + return { + id: monitor._id, + host: { + title: monitor.name, + url: monitor.url, + precentage: 100, + percentageColor: + monitor.status === true + ? "var(--env-var-color-17)" + : "var(--env-var-color-19)", + }, + status: { + status: monitor.status === true ? "Up" : "Down", + backgroundColor: + monitor.status === true + ? "var(--env-var-color-20)" + : "var(--env-var-color-21)", + statusDotColor: + monitor.status === true + ? "var(--env-var-color-17)" + : "var(--env-var-color-19)", + }, + response: { + checks: monitor.checks, + }, + }; + }); + setRows(mappedRows); + }, [monitors]); return ( -
-

Monitor Table

- -
+ ); }; diff --git a/Client/src/Pages/Monitors/index.jsx b/Client/src/Pages/Monitors/index.jsx index 7adfc13cd..a895ae47a 100644 --- a/Client/src/Pages/Monitors/index.jsx +++ b/Client/src/Pages/Monitors/index.jsx @@ -7,8 +7,6 @@ import { useNavigate } from "react-router-dom"; import Button from "../../Components/Button"; import ServerStatus from "../../Components/Charts/Servers/ServerStatus"; import SearchTextField from "../../Components/TextFields/Search/SearchTextField"; -import HostsTable from "../../Components/HostsTable"; -import Pagination from "../../Components/Pagination"; import MonitorTable from "../../Components/MonitorTable"; const Monitors = () => { @@ -26,10 +24,8 @@ const Monitors = () => { }, 0); const down = monitorState.monitors.length - up; - return (
-
Hello, {authState.user.firstname} @@ -62,10 +58,9 @@ const Monitors = () => {
-
- -
- +
+ +
); From 30c9c1d0a3a068ff79af2811a01b765d1f63d1f5 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 5 Jul 2024 14:41:27 -0700 Subject: [PATCH 3/5] Removed test upload component --- Client/src/Pages/TestUpload/index.jsx | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 Client/src/Pages/TestUpload/index.jsx diff --git a/Client/src/Pages/TestUpload/index.jsx b/Client/src/Pages/TestUpload/index.jsx deleted file mode 100644 index 809aa44f7..000000000 --- a/Client/src/Pages/TestUpload/index.jsx +++ /dev/null @@ -1,17 +0,0 @@ -import { useState } from "react"; - -const TestUpload = () => { - const [file, setFile] = useState(); - function handleChange(e) { - setFile(URL.createObjectURL(e.target.files[0])); - } - - return ( -
- - -
- ); -}; - -export default TestUpload; From 6a7a9197896903a476d6e8f40f5fc3809c6a8211 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Sat, 6 Jul 2024 21:59:41 -0700 Subject: [PATCH 4/5] Use react table instead of data grid for performance --- Client/src/Components/MonitorTable/index.jsx | 182 ++++++++++--------- 1 file changed, 101 insertions(+), 81 deletions(-) diff --git a/Client/src/Components/MonitorTable/index.jsx b/Client/src/Components/MonitorTable/index.jsx index 5e032f875..c84313b52 100644 --- a/Client/src/Components/MonitorTable/index.jsx +++ b/Client/src/Components/MonitorTable/index.jsx @@ -3,117 +3,137 @@ import PropTypes from "prop-types"; import { DataGrid } from "@mui/x-data-grid"; import OpenIt from "../../assets/Images/Icon-open-in-tab-gray.png"; import ResponseTimeChart from "../Charts/ResponseTimeChart"; -import { useState, useEffect } from "react"; +import { + Table, + TableBody, + TableCell, + TableContainer, + TableHead, + TableRow, + Paper, +} from "@mui/material"; + +/** + * Host component. + * This subcomponent receives a params object and displays the host details. + * + * @component + * @param {Object} params - An object containing the following properties: + * @param {string} params.url - The URL of the host. + * @param {string} params.title - The name of the host. + * @param {string} params.percentageColor - The color of the percentage text. + * @param {number} params.precentage - The percentage to display. + * @returns {React.ElementType} Returns a div element with the host details. + */ const Host = ({ params }) => { return (
- + OpenIt -
{params.value.title}
+
{params.title}
- {params.value.precentage}% + {params.precentage}%
); }; +/** + * Status component. + * This subcomponent receives a params object and displays the status details of a monitor. + * + * @component + * @param {Object} params - An object containing the following properties: + * @param {string} params.backgroundColor - The background color of the status box. + * @param {string} params.statusDotColor - The color of the status dot. + * @param {string} params.status - The status text to display. + * @returns {React.ElementType} Returns a div element with the host status. + */ const Status = ({ params }) => { return (
- {params.value.status} + {params.status}
); }; -const cols = [ - { - field: "host", - headerName: "Host", - renderCell: (params) => { - return ; - }, - flex: 1, - }, - { - field: "status", - headerName: "Status", - renderCell: (params) => { - return ; - }, - }, - { - field: "response", - headerName: "Response", - renderCell: (params) => { - return ; - }, - flex: 1, - }, - { - field: "actions", - headerName: "Actions", - }, -]; - +/** + * MonitorTable component. + * Takes an array of monitor objects and displays them in a table. + * Each row in the table represents a monitor and includes the host, status, response time, and action. + * + * @component + * @param {Object[]} monitors - An array of monitor objects. Each object should have the following properties: + * @param {string} monitors[].url - The URL of the monitor. + * @param {string} monitors[].name - The name of the monitor. + * @param {boolean} monitors[].status - The status of the monitor. True if the monitor is up, false otherwise. + * @param {Object[]} monitors[].checks - An array of check objects for the response time chart. + * @returns {React.Component} Returns a table with the monitor data. + */ const MonitorTable = ({ monitors = [] }) => { - const [rows, setRows] = useState([]); - useEffect(() => { - const mappedRows = monitors.map((monitor) => { - return { - id: monitor._id, - host: { - title: monitor.name, - url: monitor.url, - precentage: 100, - percentageColor: - monitor.status === true - ? "var(--env-var-color-17)" - : "var(--env-var-color-19)", - }, - status: { - status: monitor.status === true ? "Up" : "Down", - backgroundColor: - monitor.status === true - ? "var(--env-var-color-20)" - : "var(--env-var-color-21)", - statusDotColor: - monitor.status === true - ? "var(--env-var-color-17)" - : "var(--env-var-color-19)", - }, - response: { - checks: monitor.checks, - }, - }; - }); - setRows(mappedRows); - }, [monitors]); + const mappedRows = monitors.map((monitor) => { + const params = { + url: monitor.url, + title: monitor.name, + precentage: 100, + percentageColor: + monitor.status === true + ? "var(--env-var-color-17)" + : "var(--env-var-color-19)", + status: monitor.status === true ? "up" : "down", + backgroundColor: + monitor.status === true + ? "var(--env-var-color-20)" + : "var(--env-var-color-21)", + statusDotColor: + monitor.status === true + ? "var(--env-var-color-17)" + : "var(--env-var-color-19)", + }; + + return ( + + + + + + + + + + + TODO Add Actions + + ); + }); return ( - + + + + + Host + Status + Response Time + Action + + + {mappedRows} +
+
); }; From 0555157200827295be8005eb136ffb1a7dfc1556 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Sat, 6 Jul 2024 23:07:04 -0700 Subject: [PATCH 5/5] Added animations back, added pagination --- .../Charts/ResponseTimeChart/index.jsx | 2 +- Client/src/Components/MonitorTable/index.jsx | 98 ++++++++++++------- 2 files changed, 64 insertions(+), 36 deletions(-) diff --git a/Client/src/Components/Charts/ResponseTimeChart/index.jsx b/Client/src/Components/Charts/ResponseTimeChart/index.jsx index 0518ebee8..2121169b6 100644 --- a/Client/src/Components/Charts/ResponseTimeChart/index.jsx +++ b/Client/src/Components/Charts/ResponseTimeChart/index.jsx @@ -54,7 +54,7 @@ const ResponseTimeChart = ({ checks = [] }) => {
- + {normalizedChecks.map((check, index) => ( { * @returns {React.Component} Returns a table with the monitor data. */ const MonitorTable = ({ monitors = [] }) => { - const mappedRows = monitors.map((monitor) => { - const params = { - url: monitor.url, - title: monitor.name, - precentage: 100, - percentageColor: - monitor.status === true - ? "var(--env-var-color-17)" - : "var(--env-var-color-19)", - status: monitor.status === true ? "up" : "down", - backgroundColor: - monitor.status === true - ? "var(--env-var-color-20)" - : "var(--env-var-color-21)", - statusDotColor: - monitor.status === true - ? "var(--env-var-color-17)" - : "var(--env-var-color-19)", - }; + const [page, setPage] = useState(0); + const [rowsPerPage, setRowsPerPage] = useState(5); - return ( - - - - - - - - - - - TODO Add Actions - - ); - }); + const handleChangePage = (event, newPage) => { + setPage(newPage); + }; + + const handleChangeRowsPerPage = (event) => { + setRowsPerPage(parseInt(event.target.value, 10)); + setPage(0); + }; + + const mappedRows = monitors + .slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage) + .map((monitor) => { + const params = { + url: monitor.url, + title: monitor.name, + precentage: 100, + percentageColor: + monitor.status === true + ? "var(--env-var-color-17)" + : "var(--env-var-color-19)", + status: monitor.status === true ? "up" : "down", + backgroundColor: + monitor.status === true + ? "var(--env-var-color-20)" + : "var(--env-var-color-21)", + statusDotColor: + monitor.status === true + ? "var(--env-var-color-17)" + : "var(--env-var-color-19)", + }; + + return ( + + + + + + + + + + + TODO Add Actions + + ); + }); return ( @@ -132,6 +148,18 @@ const MonitorTable = ({ monitors = [] }) => { {mappedRows} + + + + + );