import { BasePage, StatBox } from "@/components/design-elements"; import { HeaderControls, HeaderRange } from "@/components/monitors"; import Stack from "@mui/material/Stack"; import prettyMilliseconds from "pretty-ms"; import { getStatusPalette } from "@/utils/MonitorUtils"; import { InfraDetailsGraphs } from "@/pages/infrastructure/InfraDetailsGraphs"; import { useGet, usePatch } from "@/hooks/UseApi"; import { useState } from "react"; import { useTheme } from "@mui/material/styles"; import { useParams } from "react-router"; import type { ApiResponse } from "@/hooks/UseApi"; import type { IMonitor, IMonitorWithMonitorStats } from "@/types/monitor"; import type { IInfraCheck } from "@/types/check"; import { getFrequency, getCores, getAvgTemp, getGbs, getDiskTotalGbs, getOsAndPlatform, } from "@/pages/infrastructure/InfraUtils"; import { InfraDetailsGauges } from "./InfraDetailsGauges"; import { config } from "@/config/index"; const GLOBAL_REFRESH = config.GLOBAL_REFRESH; const InfraDetailsPage = () => { const theme = useTheme(); const { id } = useParams(); const [range, setRange] = useState("2h"); const { response, isValidating, refetch } = useGet< ApiResponse >( `/monitors/${id}?embedChecks=true&range=${range}`, {}, { refreshInterval: GLOBAL_REFRESH, keepPreviousData: true } ); const { patch, loading: isPatching } = usePatch(); const monitor = response?.data?.monitor; const stats = response?.data?.stats; const checks = (response?.data?.checks || []) as IInfraCheck[]; const palette = getStatusPalette(monitor?.status || "initializing"); const streakDuration = stats?.currentStreakStartedAt ? Date.now() - stats?.currentStreakStartedAt : 0; const lastChecked = stats?.lastCheckTimestamp ? Date.now() - stats?.lastCheckTimestamp : -1; if (!monitor) { return null; } return ( = 0 ? `${prettyMilliseconds(lastChecked, { secondsDecimalDigits: 0, })} ago` : "N/A" } /> {/* Infrastructure overview */} {/* Network */} ); }; export default InfraDetailsPage;