diff --git a/Client/src/Pages/Infrastructure/details/index.jsx b/Client/src/Pages/Infrastructure/details/index.jsx index bf31e8d27..571f52f31 100644 --- a/Client/src/Pages/Infrastructure/details/index.jsx +++ b/Client/src/Pages/Infrastructure/details/index.jsx @@ -1,10 +1,11 @@ -import { monitorData } from "./data"; import { useParams } from "react-router-dom"; +import { useEffect, useState } from "react"; import Breadcrumbs from "../../../Components/Breadcrumbs"; import { Stack, Box, Typography } from "@mui/material"; import { useTheme } from "@emotion/react"; import CustomGauge from "../../../Components/Charts/CustomGauge"; import AreaChart from "../../../Components/Charts/AreaChart"; +import axios from "axios"; import { TzTick, PercentTick, @@ -17,11 +18,18 @@ import PropTypes from "prop-types"; * @param {number} bytes - Number of bytes to convert * @returns {number} Converted value in gigabytes */ -const bytesToGB = (bytes) => { - if (typeof bytes !== "number") return 0; - if (bytes === 0) return 0; +const bytesToMBorGB = (bytes) => { + if (typeof bytes !== "number") return "0 GB"; + if (bytes === 0) return "0 GB"; + const GB = bytes / (1024 * 1024 * 1024); - return Number(GB.toFixed(0)); + const MB = bytes / (1024 * 1024); + + if (GB >= 1) { + return `${Number(GB.toFixed(0))} GB`; + } else { + return `${Number(MB.toFixed(0))} MB`; + } }; /** @@ -130,12 +138,12 @@ const GaugeBox = ({ value, heading, metricOne, valueOne, metricTwo, valueTwo }) }; GaugeBox.propTypes = { - value: PropTypes.number.isRequired, + value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired, heading: PropTypes.string.isRequired, metricOne: PropTypes.string.isRequired, - valueOne: PropTypes.string.isRequired, + valueOne: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, metricTwo: PropTypes.string.isRequired, - valueTwo: PropTypes.string.isRequired, + valueTwo: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, }; /** @@ -145,189 +153,208 @@ GaugeBox.propTypes = { const InfrastructureDetails = () => { const theme = useTheme(); const { monitorId } = useParams(); - const testData = monitorData; - const latestCheck = testData[testData.length - 1]; const navList = [ { name: "infrastructure monitors", path: "/infrastructure" }, { name: "details", path: `/infrastructure/${monitorId}` }, ]; + const [monitor, setMonitor] = useState(null); + + useEffect(() => { + const fetchData = async () => { + try { + const response = await axios.get("/dummyData.json", { + headers: { + "Content-Type": "application/json", + "Cache-Control": "no-cache", + }, + }); + setMonitor(response.data.data); + } catch (error) { + console.error(error); + } + }; + fetchData(); + }, []); + console.log(monitor?.checks?.[0]?.memory?.total_bytes); return ( - - - + monitor && ( + + - - - - - - - - - - {latestCheck.disk.map((disk, idx) => { - return ( - - ); - })} - - *": { - flexBasis: `calc(50% - ${theme.spacing(8)})`, - maxWidth: `calc(50% - ${theme.spacing(8)})`, - }, - }} - > - - - Memory usage - - ( - - )} - xTick={} - yTick={} - strokeColor={theme.palette.primary.main} - gradient={true} - gradientStartColor={theme.palette.primary.main} //FE team HELP! Not sure what colors to use - gradientEndColor="#ffffff" // FE team HELP! + + - - - - CPU usage - - ( - - )} - xTick={} - yTick={} - strokeColor={theme.palette.success.main} // FE team HELP! - gradient={true} - fill={theme.palette.success.main} // FE team HELP! - gradientStartColor={theme.palette.success.main} - gradientEndColor="#ffffff" + + + + + + + - - {latestCheck.disk.map((disk, idx) => { - // disk is an array of disks, so we need to map over it - return ( - - - {`Disk${idx} usage`} - - ( - - )} - xTick={} - yTick={} - strokeColor={theme.palette.warning.main} - gradient={true} - gradientStartColor={theme.palette.warning.main} - gradientEndColor="#ffffff" + + {monitor.checks[0].disk.map((disk, idx) => { + return ( + - - ); - })} + ); + })} + + *": { + flexBasis: `calc(50% - ${theme.spacing(8)})`, + maxWidth: `calc(50% - ${theme.spacing(8)})`, + }, + }} + > + + + Memory usage + + ( + + )} + xTick={} + yTick={} + strokeColor={theme.palette.primary.main} + gradient={true} + gradientStartColor={theme.palette.primary.main} //FE team HELP! Not sure what colors to use + gradientEndColor="#ffffff" // FE team HELP! + /> + + + + CPU usage + + ( + + )} + xTick={} + yTick={} + strokeColor={theme.palette.success.main} // FE team HELP! + gradient={true} + fill={theme.palette.success.main} // FE team HELP! + gradientStartColor={theme.palette.success.main} + gradientEndColor="#ffffff" + /> + + {monitor?.checks?.[0]?.disk?.map((disk, idx) => { + // disk is an array of disks, so we need to map over it + return ( + + + {`Disk${idx} usage`} + + ( + + )} + xTick={} + yTick={} + strokeColor={theme.palette.warning.main} + gradient={true} + gradientStartColor={theme.palette.warning.main} + gradientEndColor="#ffffff" + /> + + ); + })} + - - + + ) ); };