import Stack from "@mui/material/Stack"; import MenuItem from "@mui/material/MenuItem"; import Grid from "@mui/material/Grid"; import { HistogramInfrastructure } from "@/components/monitors"; import { Select } from "@/components/inputs"; import type { AggregateCheck } from "@/types/check"; import { useMemo, useState, useEffect } from "react"; import { useTheme } from "@mui/material/styles"; import useMediaQuery from "@mui/material/useMediaQuery"; const getChartConfigs = ( theme: any, checks: AggregateCheck[], selectedInterface: string ) => { const idx = checks?.[0]?.net?.findIndex((i) => i.name === selectedInterface) ?? -1; if (idx === -1) return []; return [ { type: "Bytes received", dataKeys: [`net[${idx}].bytes_recv`], strokeColor: theme.palette.primary.main, gradientStartColor: theme.palette.primary.main, yDomain: [0, 1], idx: null, }, { type: "Bytes sent", dataKeys: [`net[${idx}].bytes_sent`], strokeColor: theme.palette.success.main, gradientStartColor: theme.palette.success.main, yDomain: [0, 1], idx: null, }, { type: "Packets received", dataKeys: [`net[${idx}].packets_recv`], strokeColor: theme.palette.warning.main, gradientStartColor: theme.palette.warning.main, yDomain: [0, 1], idx: null, }, { type: "Packets sent", dataKeys: [`net[${idx}].packets_sent`], strokeColor: theme.palette.error.main, gradientStartColor: theme.palette.error.main, yDomain: [0, 1], idx: null, }, ]; }; export const InfraDetailsNetGraphs = ({ checks, range, }: { checks: AggregateCheck[]; range: string; }) => { const theme = useTheme(); const isSmall = useMediaQuery(theme.breakpoints.down("md")); const [selectedInterface, setSelectedInterface] = useState(""); const chartConfigs = useMemo( () => getChartConfigs(theme, checks, selectedInterface), [theme, checks, selectedInterface] ); useEffect(() => { if (checks?.[0]?.net && checks[0].net.length > 0) { const firstNonLoopback = checks[0].net.find( (iface) => iface.name !== "lo" ); setSelectedInterface( firstNonLoopback?.name || checks[0].net[0]?.name || "" ); } else { setSelectedInterface(""); } }, [checks]); return ( {chartConfigs.map((config) => { return ( ); })} ); };