import { useMemo, useState } from "react"; import { Alert, Button, Stack, Tab, Typography } from "@mui/material"; import { useNavigate } from "react-router-dom"; import { useMonitoringMachines, useMonitoringPoller, } from "../hooks/useMonitoring"; import { useMonitoringOverview } from "../hooks/useDashboard"; import { MachineMonitoringSection } from "../components/MachineMonitoringSection"; import { MonitoringOverviewTable } from "../components/MonitoringOverviewTable"; import { SectionCard } from "../components/SectionCard"; import { TabbedCard } from "../components/TabbedCard"; type MonitoringTab = "overview" | string; export function Monitoring() { const { data: machines = [], isLoading, error } = useMonitoringMachines(); const { data: poller } = useMonitoringPoller(); const { data: overview } = useMonitoringOverview(); const navigate = useNavigate(); const [tab, setTab] = useState("overview"); const selectedMachine = useMemo( () => machines.find((machine) => machine.id === tab) ?? null, [machines, tab], ); return ( Monitoring Review fleet health first, then switch to a machine-specific tab. {error ? {String(error)} : null} {isLoading ? ( Loading monitoring machines... ) : null} , ...machines.map((machine) => ( )), ]} contentSx={{ p: 1.5 }} > {tab === "overview" ? ( Fleet overview {poller?.worker_running ? "running" : "stopped"} {!isLoading && machines.length === 0 ? ( navigate("/settings")} > Open Settings } > No monitoring machines are configured yet. ) : overview ? ( ) : ( Loading fleet overview... )} ) : selectedMachine ? ( ) : null} ); }