diff --git a/Client/src/App.jsx b/Client/src/App.jsx index 367a66758..ec0e4130c 100644 --- a/Client/src/App.jsx +++ b/Client/src/App.jsx @@ -31,7 +31,7 @@ function App() { } /> } /> } /> - } /> + {/* } /> */} } /> } /> } /> diff --git a/Client/src/Components/Charts/BarChart/BarChart.jsx b/Client/src/Components/Charts/BarChart/BarChart.jsx index e424fef3e..a1f3d48b0 100644 --- a/Client/src/Components/Charts/BarChart/BarChart.jsx +++ b/Client/src/Components/Charts/BarChart/BarChart.jsx @@ -1,17 +1,57 @@ -import React from "react"; import "./barChart.css"; import PropTypes from "prop-types"; +const RANGE_MAX = 100; +const RANGE_MIN = 1; + +/** + * Normalizes the response times of a set of checks to a specified range. + * This function calculates the minimum and maximum response times from the input, + * then scales each check's response time linearly between `RANGE_MIN` and `RANGE_MAX`. + * + * @param {Array} checks - An array of check objects. Each check should have a `responseTime` property. + * @returns {Array} An array of check objects with normalized `responseTime` values. + */ +const normalizeData = (checks) => { + const min = checks.reduce((accum, cur) => { + return Math.min(accum, cur.responseTime); + }, Infinity); + + const max = checks.reduce((accum, cur) => { + return Math.max(accum, cur.responseTime); + }, 0); + + const normalizedChecks = checks.map((check) => { + let normailzedResponseTime = + RANGE_MIN + + ((check.responseTime - min) * (RANGE_MAX - RANGE_MIN)) / (max - min); + const normalizedCheck = { ...check, responseTime: normailzedResponseTime }; + return normalizedCheck; + }); + return normalizedChecks; +}; + +/** + * BarChart renders a bar chart visualization for a set of checks. Each bar represents a check's response time, + * with the color indicating the check's status (green for successful checks, red for failed ones). + * + * @component + * @param {Array} checks - An array of check objects to be visualized. Each check object should have an `_id`, + * a `status` indicating success (true) or failure (false), and a `responseTime` representing the height of the bar in percentage. + */ const BarChart = ({ checks = [] }) => { + const normailzedChecks = normalizeData(checks); return (
- {checks.map((value, index) => ( -
- ))} + {normailzedChecks.map((check) => { + return ( +
+ ); + })}
); }; diff --git a/Client/src/Components/CurrentMonitors/index.jsx b/Client/src/Components/CurrentMonitors/index.jsx index 4f53ebeb5..2357c850e 100644 --- a/Client/src/Components/CurrentMonitors/index.jsx +++ b/Client/src/Components/CurrentMonitors/index.jsx @@ -1,8 +1,15 @@ import SearchTextField from "../TextFields/Search/SearchTextField"; import "./index.css"; -import React from "react"; import HostsTable from "../HostsTable"; import Pagination from "../Pagination"; +import PropTypes from "prop-types"; + +/** + * CurrentMonitors displays the current status of monitor + * + * @component + * @param {Array} monitors - An array of monitor objects to be displayed. + */ const CurrentMonitors = ({ monitors }) => { return ( @@ -24,4 +31,8 @@ const CurrentMonitors = ({ monitors }) => { ); }; +CurrentMonitors.propTypes = { + monitors: PropTypes.arrayOf(PropTypes.object).isRequired, +}; + export default CurrentMonitors; diff --git a/Client/src/Components/HostsTable/index.jsx b/Client/src/Components/HostsTable/index.jsx index c5c5faf48..2fb7991ea 100644 --- a/Client/src/Components/HostsTable/index.jsx +++ b/Client/src/Components/HostsTable/index.jsx @@ -1,4 +1,12 @@ -import React from "react"; +import BarChart from "../Charts/BarChart/BarChart"; +import PropTypes from "prop-types"; + +/** + * HostsTable displays the current status of monitor + * + * @component + * @param {Array} monitors - An array of monitor objects to be displayed. + */ const HostsTable = ({ monitors }) => { return ( @@ -8,20 +16,21 @@ const HostsTable = ({ monitors }) => { Host Status - Team + Response Actions - {monitors.map((monitor, index) => { - console.log(monitor); + {monitors.map((monitor) => { return ( - + {monitor.url} {monitor.isActive ? "Active" : "Down"} - {monitor.team} + + + {monitor.actions} @@ -34,4 +43,8 @@ const HostsTable = ({ monitors }) => { ); }; +HostsTable.propTypes = { + monitors: PropTypes.arrayOf(PropTypes.object).isRequired, +}; + export default HostsTable; diff --git a/Client/src/Layouts/HomeLayout/index.jsx b/Client/src/Layouts/HomeLayout/index.jsx index a7f7ce9df..2e4bc5e6b 100644 --- a/Client/src/Layouts/HomeLayout/index.jsx +++ b/Client/src/Layouts/HomeLayout/index.jsx @@ -3,24 +3,12 @@ import { Outlet } from "react-router"; import DashboardSidebar from "../../Components/DashboardSidebar"; import "./index.css"; -// Demo, remove me -import { useSelector } from "react-redux"; -// Emd Demo - const HomeLayout = () => { - const authState = useSelector((state) => state.auth); - const { user, msg } = authState; return (
- {/* Remove me later */} - {user &&

{user.firstname}

} - {user &&

{user.lastname}

} - {user &&

{user.email}

} - {msg &&

Msg: {msg}

} - {/* I am a demo */}
diff --git a/Client/src/Pages/Monitors/CurrentStats.jsx b/Client/src/Pages/Monitors/CurrentStats.jsx index c0cd42c99..b2455936c 100644 --- a/Client/src/Pages/Monitors/CurrentStats.jsx +++ b/Client/src/Pages/Monitors/CurrentStats.jsx @@ -1,12 +1,14 @@ -import React, { useEffect, useState } from "react"; -import Host from "../../Components/Host"; -import HostStatus from "../../Components/HostStatus"; -import HostActions from "../../Components/HostActions"; -import BarChart from "../../Components/Charts/BarChart/BarChart"; import Button from "../../Components/Button"; import ServerStatus from "../../Components/Charts/Servers/ServerStatus"; import CurrentMonitors from "../../Components/CurrentMonitors"; -import MockData from "../../Mock/sample_data.json"; +import PropTypes from "prop-types"; + +/** + * CurrentStats displays the current status of monitor + * + * @component + * @param {Array} monitors - An array of monitor objects to be displayed. + */ const CurrentStats = ({ monitors }) => { return ( @@ -33,4 +35,8 @@ const CurrentStats = ({ monitors }) => { ); }; +CurrentStats.propTypes = { + monitors: PropTypes.arrayOf(PropTypes.object).isRequired, +}; + export default CurrentStats; diff --git a/Client/src/Pages/Monitors/index.jsx b/Client/src/Pages/Monitors/index.jsx index f863eedc4..875f59443 100644 --- a/Client/src/Pages/Monitors/index.jsx +++ b/Client/src/Pages/Monitors/index.jsx @@ -18,7 +18,6 @@ const Monitors = () => { return (
- {/* */}
); };