Merge pull request #287 from bluewave-labs/feat/MUI-table-and-pagination

Feat/m UI table and pagination
This commit is contained in:
Alexander Holliday authored and GitHub committed 2024-07-08 08:32:57 -07:00
commit f9ca58c00a
4 files changed
+228 -32

No files matched your search

@@ -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);
}
@@ -0,0 +1,175 @@
import "./index.css";
import { useState } from "react";
import PropTypes from "prop-types";
import OpenIt from "../../assets/Images/Icon-open-in-tab-gray.png";
import ResponseTimeChart from "../Charts/ResponseTimeChart";
import {
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableRow,
TableFooter,
TablePagination,
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 (
<div className="host-row">
<a href={params.url} target="_blank">
<img className="host-open-icon" src={OpenIt} alt="OpenIt" />
</a>
<div className="host-name">{params.title}</div>
<div
className="host-percentage"
style={{ color: params.percentageColor }}
>
{params.precentage}%
</div>
</div>
);
};
/**
* 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 (
<div className="host-status">
<div
className="host-status-details"
style={{ backgroundColor: params.backgroundColor }}
>
<div
className="host-status-dot"
style={{ backgroundColor: params.statusDotColor }}
/>
<span className="host-status-text">{params.status}</span>
</div>
</div>
);
};
/**
* 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 [page, setPage] = useState(0);
const [rowsPerPage, setRowsPerPage] = useState(5);
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 (
<TableRow key={monitor._id}>
<TableCell>
<Host params={params} />
</TableCell>
<TableCell>
<Status params={params} />
</TableCell>
<TableCell>
<ResponseTimeChart checks={monitor.checks} />
</TableCell>
<TableCell>TODO Add Actions</TableCell>
</TableRow>
);
});
return (
<TableContainer component={Paper}>
<Table>
<TableHead>
<TableRow>
<TableCell>Host</TableCell>
<TableCell>Status</TableCell>
<TableCell>Response Time</TableCell>
<TableCell>Action</TableCell>
</TableRow>
</TableHead>
<TableBody>{mappedRows}</TableBody>
<TableFooter>
<TableRow>
<TablePagination
rowsPerPageOptions={[5, 10, 25]}
count={monitors.length}
rowsPerPage={rowsPerPage}
page={page}
onPageChange={handleChangePage}
onRowsPerPageChange={handleChangeRowsPerPage}
/>
</TableRow>
</TableFooter>
</Table>
</TableContainer>
);
};
MonitorTable.propTypes = {
monitors: PropTypes.arrayOf(PropTypes.object).isRequired,
};
Status.propTypes = { params: PropTypes.object.isRequired };
Host.propTypes = { params: PropTypes.object.isRequired };
export default MonitorTable;
+4 -7
View File
@@ -7,8 +7,7 @@ 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 = () => {
const navigate = useNavigate();
@@ -25,7 +24,6 @@ const Monitors = () => {
}, 0);
const down = monitorState.monitors.length - up;
return (
<div className="monitors">
<div className="monitors-bar">
@@ -60,10 +58,9 @@ const Monitors = () => {
<SearchTextField />
</div>
</div>
<div className="monitors-v-gaping"></div>
<HostsTable monitors={monitorState.monitors} />
<div className="monitors-v-gaping"></div>
<Pagination />
<div className="monitors-v-gaping" />
<MonitorTable monitors={monitorState.monitors} />
<div className="monitors-v-gaping" />
</div>
</div>
);
-25
View File
@@ -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;