Conneted Monitor page to backend. Added data normailization to Checks. Added JSdocs and proptypes
This commit is contained in:
1 parent
2f1053bd05
commit
171b1b8059
7 files changed
+92
-35
No files matched your search
+1
-1
@@ -31,7 +31,7 @@ function App() {
|
|||||||
<Route exact path="/register" element={<Register />} />
|
<Route exact path="/register" element={<Register />} />
|
||||||
<Route exact path="/login" element={<Login />} />
|
<Route exact path="/login" element={<Login />} />
|
||||||
<Route exact path="/demo" element={<Demo />} />
|
<Route exact path="/demo" element={<Demo />} />
|
||||||
<Route path="/toast" element={<ToastComponent />} />
|
{/* <Route path="/toast" element={<ToastComponent />} /> */}
|
||||||
<Route path="*" element={<NotFound />} />
|
<Route path="*" element={<NotFound />} />
|
||||||
<Route path="/playground" element={<PlayGround />} />
|
<Route path="/playground" element={<PlayGround />} />
|
||||||
<Route path="/forgot-password" element={<ForgotPassword />} />
|
<Route path="/forgot-password" element={<ForgotPassword />} />
|
||||||
|
|||||||
@@ -1,17 +1,57 @@
|
|||||||
import React from "react";
|
|
||||||
import "./barChart.css";
|
import "./barChart.css";
|
||||||
import PropTypes from "prop-types";
|
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>} checks - An array of check objects. Each check should have a `responseTime` property.
|
||||||
|
* @returns {Array<Checks>} 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>} 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 BarChart = ({ checks = [] }) => {
|
||||||
|
const normailzedChecks = normalizeData(checks);
|
||||||
return (
|
return (
|
||||||
<div className="bar-chart">
|
<div className="bar-chart">
|
||||||
{checks.map((value, index) => (
|
{normailzedChecks.map((check) => {
|
||||||
<div
|
return (
|
||||||
key={index}
|
<div
|
||||||
className={`bar ${value.status ? "green" : "red"}`}
|
key={check._id}
|
||||||
style={{ height: `${value.responseTime / 3}%` }}
|
className={`bar ${check.status ? "green" : "red"}`}
|
||||||
/>
|
style={{ height: `${check.responseTime}%` }}
|
||||||
))}
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
import SearchTextField from "../TextFields/Search/SearchTextField";
|
import SearchTextField from "../TextFields/Search/SearchTextField";
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
import React from "react";
|
|
||||||
import HostsTable from "../HostsTable";
|
import HostsTable from "../HostsTable";
|
||||||
import Pagination from "../Pagination";
|
import Pagination from "../Pagination";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CurrentMonitors displays the current status of monitor
|
||||||
|
*
|
||||||
|
* @component
|
||||||
|
* @param {Array<Monitor>} monitors - An array of monitor objects to be displayed.
|
||||||
|
*/
|
||||||
|
|
||||||
const CurrentMonitors = ({ monitors }) => {
|
const CurrentMonitors = ({ monitors }) => {
|
||||||
return (
|
return (
|
||||||
@@ -24,4 +31,8 @@ const CurrentMonitors = ({ monitors }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
CurrentMonitors.propTypes = {
|
||||||
|
monitors: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
export default CurrentMonitors;
|
export default CurrentMonitors;
|
||||||
@@ -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<Monitor>} monitors - An array of monitor objects to be displayed.
|
||||||
|
*/
|
||||||
|
|
||||||
const HostsTable = ({ monitors }) => {
|
const HostsTable = ({ monitors }) => {
|
||||||
return (
|
return (
|
||||||
@@ -8,20 +16,21 @@ const HostsTable = ({ monitors }) => {
|
|||||||
<tr className="theader-row">
|
<tr className="theader-row">
|
||||||
<td className="theader-row-cell">Host</td>
|
<td className="theader-row-cell">Host</td>
|
||||||
<td className="theader-row-cell">Status</td>
|
<td className="theader-row-cell">Status</td>
|
||||||
<td className="theader-row-cell">Team</td>
|
<td className="theader-row-cell">Response</td>
|
||||||
<td className="theader-row-cell">Actions</td>
|
<td className="theader-row-cell">Actions</td>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{monitors.map((monitor, index) => {
|
{monitors.map((monitor) => {
|
||||||
console.log(monitor);
|
|
||||||
return (
|
return (
|
||||||
<tr className="tbody-row" key={index}>
|
<tr className="tbody-row" key={monitor._id}>
|
||||||
<td className="tbody-row-cell">{monitor.url}</td>
|
<td className="tbody-row-cell">{monitor.url}</td>
|
||||||
<td className="tbody-row-cell">
|
<td className="tbody-row-cell">
|
||||||
{monitor.isActive ? "Active" : "Down"}
|
{monitor.isActive ? "Active" : "Down"}
|
||||||
</td>
|
</td>
|
||||||
<td className="tbody-row-cell">{monitor.team}</td>
|
<td className="tbody-row-cell">
|
||||||
|
<BarChart checks={monitor.checks} />
|
||||||
|
</td>
|
||||||
<td className="tbody-row-cell actions-cell">
|
<td className="tbody-row-cell actions-cell">
|
||||||
{monitor.actions}
|
{monitor.actions}
|
||||||
</td>
|
</td>
|
||||||
@@ -34,4 +43,8 @@ const HostsTable = ({ monitors }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
HostsTable.propTypes = {
|
||||||
|
monitors: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
export default HostsTable;
|
export default HostsTable;
|
||||||
@@ -3,24 +3,12 @@ import { Outlet } from "react-router";
|
|||||||
import DashboardSidebar from "../../Components/DashboardSidebar";
|
import DashboardSidebar from "../../Components/DashboardSidebar";
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
|
|
||||||
// Demo, remove me
|
|
||||||
import { useSelector } from "react-redux";
|
|
||||||
// Emd Demo
|
|
||||||
|
|
||||||
const HomeLayout = () => {
|
const HomeLayout = () => {
|
||||||
const authState = useSelector((state) => state.auth);
|
|
||||||
const { user, msg } = authState;
|
|
||||||
return (
|
return (
|
||||||
<div className="home-layout">
|
<div className="home-layout">
|
||||||
<NavBar />
|
<NavBar />
|
||||||
<div className="main-content">
|
<div className="main-content">
|
||||||
<DashboardSidebar />
|
<DashboardSidebar />
|
||||||
{/* Remove me later */}
|
|
||||||
{user && <p>{user.firstname}</p>}
|
|
||||||
{user && <p>{user.lastname}</p>}
|
|
||||||
{user && <p>{user.email}</p>}
|
|
||||||
{msg && <p>Msg: {msg}</p>}
|
|
||||||
{/* I am a demo */}
|
|
||||||
<Outlet />
|
<Outlet />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -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 Button from "../../Components/Button";
|
||||||
import ServerStatus from "../../Components/Charts/Servers/ServerStatus";
|
import ServerStatus from "../../Components/Charts/Servers/ServerStatus";
|
||||||
import CurrentMonitors from "../../Components/CurrentMonitors";
|
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<Monitor>} monitors - An array of monitor objects to be displayed.
|
||||||
|
*/
|
||||||
|
|
||||||
const CurrentStats = ({ monitors }) => {
|
const CurrentStats = ({ monitors }) => {
|
||||||
return (
|
return (
|
||||||
@@ -33,4 +35,8 @@ const CurrentStats = ({ monitors }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
CurrentStats.propTypes = {
|
||||||
|
monitors: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
export default CurrentStats;
|
export default CurrentStats;
|
||||||
@@ -18,7 +18,6 @@ const Monitors = () => {
|
|||||||
return (
|
return (
|
||||||
<div className="monitors">
|
<div className="monitors">
|
||||||
<CurrentStats monitors={monitorState.monitors} />
|
<CurrentStats monitors={monitorState.monitors} />
|
||||||
{/* <CreateNewMonitor /> */}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user