From 5ad2df1d8463bc9f7f8e814dbfd133993e1c1841 Mon Sep 17 00:00:00 2001 From: Caio Cabral Date: Fri, 29 Nov 2024 10:35:07 -0500 Subject: [PATCH] feat: adding Host component to Infrastructure and adapting it --- Client/src/Pages/Infrastructure/index.jsx | 11 ++++- .../Monitors/Home/MonitorTable/index.jsx | 5 ++- Client/src/Pages/Monitors/Home/host.jsx | 40 ++++++++++--------- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/Client/src/Pages/Infrastructure/index.jsx b/Client/src/Pages/Infrastructure/index.jsx index f7c02eae9..84df4bf6c 100644 --- a/Client/src/Pages/Infrastructure/index.jsx +++ b/Client/src/Pages/Infrastructure/index.jsx @@ -27,6 +27,7 @@ import { Pagination } from "./components/TablePagination"; // import { getInfrastructureMonitorsByTeamId } from "../../Features/InfrastructureMonitors/infrastructureMonitorsSlice"; import { networkService } from "../../Utils/NetworkService.js"; import CustomGauge from "../../Components/Charts/CustomGauge/index.jsx"; +import Host from "../Monitors/Home/host.jsx"; const columns = [ { label: "Host" }, @@ -124,7 +125,8 @@ function Infrastructure(/* {isAdmin} */) { console.log({ monitors }); console.log(monitors[0]?.checks[0]?.memory.usage_percent); const monitorsAsRows = monitors.map((monitor) => ({ - ip: monitor.name, + url: monitor.url, + name: monitor.name, status: determineState(monitor), processor: (monitor?.checks[0]?.cpu.frequency / 1000).toFixed(2) + " GHz", cpu: monitor?.checks[0]?.cpu.usage_percent * 100, @@ -228,7 +230,12 @@ function Infrastructure(/* {isAdmin} */) { /* ROWS */ monitorsAsRows.map((row, index) => ( {/* TODO iterate over column and get column id, applying row[column.id] */} - {row.ip} + + + { diff --git a/Client/src/Pages/Monitors/Home/host.jsx b/Client/src/Pages/Monitors/Home/host.jsx index 104eb29e7..68871cfe7 100644 --- a/Client/src/Pages/Monitors/Home/host.jsx +++ b/Client/src/Pages/Monitors/Home/host.jsx @@ -6,12 +6,14 @@ import PropTypes from "prop-types"; * * @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.percentage - The percentage to display. * @returns {React.ElementType} Returns a div element with the host details. */ -const Host = ({ params }) => { +const Host = ({ url, title, percentageColor, percentage }) => { + const noTitle = title === undefined || title === url; return ( { }, }} > - {params.title} + {title} - - {params.percentage}% - - {params.url} + {percentageColor && percentage && ( + + {percentage}% + + )} + {!noTitle && {url}} ); }; Host.propTypes = { - params: PropTypes.shape({ - title: PropTypes.string, - percentageColor: PropTypes.string, - percentage: PropTypes.string, - url: PropTypes.string, - }).isRequired, + title: PropTypes.string, + percentageColor: PropTypes.string, + percentage: PropTypes.string, + url: PropTypes.string, }; export default Host;