diff --git a/Client/src/Pages/Infrastructure/Details/empty.jsx b/Client/src/Pages/Infrastructure/Details/empty.jsx new file mode 100644 index 000000000..4a311233f --- /dev/null +++ b/Client/src/Pages/Infrastructure/Details/empty.jsx @@ -0,0 +1,37 @@ +import { useTheme } from "@emotion/react"; +import PlaceholderLight from "../../../assets/Images/data_placeholder.svg?react"; +import PlaceholderDark from "../../../assets/Images/data_placeholder_dark.svg?react"; +import { Box, Typography, Stack } from "@mui/material"; +import PropTypes from "prop-types"; +import { useSelector } from "react-redux"; +const Empty = ({ styles }) => { + const theme = useTheme(); + const mode = useSelector((state) => state.ui.mode); + return ( + + + {mode === "light" ? : } + + Your infrastructure dashboard will show here + + Hang tight! When we receive data, we'll show it here. Please check back in a few + minutes. + + + + ); +}; + +Empty.propTypes = { + styles: PropTypes.object, + mode: PropTypes.string, +}; + +export default Empty; diff --git a/Client/src/Pages/Infrastructure/Details/index.jsx b/Client/src/Pages/Infrastructure/Details/index.jsx index bdb43123c..9fbaae81a 100644 --- a/Client/src/Pages/Infrastructure/Details/index.jsx +++ b/Client/src/Pages/Infrastructure/Details/index.jsx @@ -9,6 +9,8 @@ import { useSelector } from "react-redux"; import { networkService } from "../../../main"; import PulseDot from "../../../Components/Animated/PulseDot"; import useUtils from "../../Monitors/utils"; +import { useNavigate } from "react-router-dom"; +import Empty from "./empty"; import { logger } from "../../../Utils/Logger"; import { formatDurationRounded, formatDurationSplit } from "../../../Utils/timeUtils"; import { @@ -27,6 +29,7 @@ const TYPOGRAPHY_PADDING = 8; * @returns {number} Converted value in gigabytes */ const formatBytes = (bytes) => { + if (bytes === undefined || bytes === null) return "0 GB"; if (typeof bytes !== "number") return "0 GB"; if (bytes === 0) return "0 GB"; @@ -40,6 +43,22 @@ const formatBytes = (bytes) => { } }; +/** + * Converts a decimal value to a percentage + * + * @function decimalToPercentage + * @param {number} value - Decimal value to convert + * @returns {number} Percentage representation + * + * @example + * decimalToPercentage(0.75) // Returns 75 + * decimalToPercentage(null) // Returns 0 + */ +const decimalToPercentage = (value) => { + if (value === null || value === undefined) return 0; + return value * 100; +}; + /** * Renders a base box with consistent styling * @param {Object} props - Component properties @@ -107,6 +126,7 @@ StatBox.propTypes = { */ const GaugeBox = ({ value, heading, metricOne, valueOne, metricTwo, valueTwo }) => { const theme = useTheme(); + return ( { + const navigate = useNavigate(); const theme = useTheme(); const { monitorId } = useParams(); const navList = [ @@ -196,19 +217,22 @@ const InfrastructureDetails = () => { numToDisplay: 50, normalize: false, }); + setMonitor(response.data.data); } catch (error) { - logger.error(error); + navigate("/not-found", { replace: true }); + logger.error(error); } }; fetchData(); - }, [dateRange, monitorId, authToken]); + }, [authToken, monitorId, dateRange]); + const statBoxConfigs = [ { id: 0, heading: "CPU", - subHeading: `${monitor?.checks[0]?.cpu?.physical_core} cores`, + subHeading: `${monitor?.checks[0]?.cpu?.physical_core ?? 0} cores`, }, { id: 1, @@ -231,7 +255,7 @@ const InfrastructureDetails = () => { const gaugeBoxConfigs = [ { type: "memory", - value: monitor?.checks[0]?.memory?.usage_percent * 100, + value: decimalToPercentage(monitor?.checks[0]?.memory?.usage_percent), heading: "Memory Usage", metricOne: "Used", valueOne: formatBytes(monitor?.checks[0]?.memory?.used_bytes), @@ -240,17 +264,17 @@ const InfrastructureDetails = () => { }, { type: "cpu", - value: monitor?.checks[0]?.cpu?.usage_percent * 100, + value: decimalToPercentage(monitor?.checks[0]?.cpu?.usage_percent), heading: "CPU Usage", metricOne: "Cores", - valueOne: monitor?.checks[0]?.cpu?.physical_core, + valueOne: monitor?.checks[0]?.cpu?.physical_core ?? 0, metricTwo: "Frequency", - valueTwo: `${(monitor?.checks[0]?.cpu?.frequency / 1000).toFixed(2)} Ghz`, + valueTwo: `${(monitor?.checks[0]?.cpu?.frequency ?? 0 / 1000).toFixed(2)} Ghz`, }, - ...(monitor?.checks[0]?.disk ?? []).map((disk, idx) => ({ + ...(monitor?.checks?.[0]?.disk ?? []).map((disk, idx) => ({ type: "disk", diskIndex: idx, - value: disk.usage_percent * 100, + value: decimalToPercentage(disk.usage_percent), heading: `Disk${idx} usage`, metricOne: "Used", valueOne: formatBytes(disk.total_bytes - disk.free_bytes), @@ -285,9 +309,9 @@ const InfrastructureDetails = () => { ]; return ( - monitor && ( - - + + + {monitor?.checks?.length > 0 ? ( { ))} - - ) + ) : ( + + )} + ); };