Files
Checkmate/Client/src/Pages/Monitors/CurrentStats.jsx
T

56 lines
1.7 KiB
React
Raw Normal View History

2024-06-18 22:39:58 +03:30
import Button from "../../Components/Button";
import ServerStatus from "../../Components/Charts/Servers/ServerStatus";
import CurrentMonitors from "../../Components/CurrentMonitors";
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.
*/
2024-06-18 22:39:58 +03:30
2024-06-21 11:08:31 -07:00
const CurrentStats = ({ monitors }) => {
2024-06-21 15:51:53 -07:00
const up = monitors.reduce((acc, cur) => {
2024-06-24 10:59:18 -07:00
if (cur.checks.length > 0) {
2024-06-21 15:51:53 -07:00
return cur.checks[cur.checks.length - 1].status === true ? acc + 1 : acc;
}
2024-06-24 10:59:18 -07:00
return 0;
2024-06-21 15:51:53 -07:00
}, 0);
const down = monitors.reduce((acc, cur) => {
2024-06-24 10:59:18 -07:00
if (cur.checks.length > 0) {
2024-06-21 15:51:53 -07:00
return cur.checks[cur.checks.length - 1].status === false ? acc + 1 : acc;
}
2024-06-24 10:59:18 -07:00
return 0;
2024-06-21 15:51:53 -07:00
}, 0);
2024-06-18 22:39:58 +03:30
return (
<div>
<div className="monitors-gaps-medium"></div>
<div className="monitors-gaps-medium"></div>
<div className="monitors-bar">
<div className="monitors-bar-title">Hello, Jackie</div>
<Button
level="primary"
label="Create new monitor"
sx={{ padding: "10px 20px", fontSize: "13px" }}
/>
</div>
<div className="monitors-gaps-medium"></div>
<div className="monitors-stats">
2024-06-21 15:51:53 -07:00
<ServerStatus title="Up" value={up} state="up" />
<ServerStatus title="Down" value={down} state="down" />
<ServerStatus title="Paused" value={0} state="pause" />
2024-06-18 22:39:58 +03:30
</div>
<div className="monitors-gaps-medium"></div>
<CurrentMonitors monitors={monitors} />
</div>
);
};
CurrentStats.propTypes = {
monitors: PropTypes.arrayOf(PropTypes.object).isRequired,
};
2024-06-18 22:39:58 +03:30
export default CurrentStats;