diff --git a/ui/src/components/TimePeriodSelector.tsx b/ui/src/components/TimePeriodSelector.tsx index 3439625..3f4e0e2 100644 --- a/ui/src/components/TimePeriodSelector.tsx +++ b/ui/src/components/TimePeriodSelector.tsx @@ -1,15 +1,15 @@ import type { TimePeriod } from "@/services/store"; type TimePeriodSelectorProps = { - currentPeriod: TimePeriod | "realtime"; - onChange: (period: TimePeriod | "realtime") => void; + currentPeriod: TimePeriod; + onChange: (period: TimePeriod) => void; }; export function TimePeriodSelector({ currentPeriod, onChange, }: TimePeriodSelectorProps) { - const periods: { value: TimePeriod | "realtime"; label: string }[] = [ + const periods: { value: TimePeriod; label: string }[] = [ { value: "realtime", label: "Real time" }, { value: "hour", label: "Past hour" }, { value: "day", label: "Past day" }, diff --git a/ui/src/pages/agent.tsx b/ui/src/pages/agent.tsx index 310fb80..3d44479 100644 --- a/ui/src/pages/agent.tsx +++ b/ui/src/pages/agent.tsx @@ -22,10 +22,12 @@ export function AgentPage() { const { agent } = useParams(); const { status, message } = useWebsocket(`ws://localhost:3000/ws/${agent}`); - const [period, setPeriod] = useState("all"); + const [period, setPeriod] = useState("realtime"); const [history, setHistory] = useState(null); useEffect(() => { + if (period === "realtime") return; + const fetchData = async () => { const data = await getHistoricalData( `http://localhost:3000/history/${agent}/${period}`, diff --git a/ui/src/services/store.ts b/ui/src/services/store.ts index fe68ff8..966d9c3 100644 --- a/ui/src/services/store.ts +++ b/ui/src/services/store.ts @@ -1,6 +1,6 @@ import type { StatusMessage } from "@/services/types"; -export type TimePeriod = "all" | "hour" | "day" | "week" | "month"; +export type TimePeriod = "realtime" | "hour" | "day" | "week" | "month" | "all"; let data: StatusMessage[] = []; const maxRealtimePoints = 50; @@ -13,12 +13,12 @@ export function addDataPoint(value: StatusMessage) { } } -export function getRealtimeData(): StatusMessage[] { - return data ?? []; +export function addDataPoint(value: StatusMessage) { + realtimeData.push(value); } -export function setHistoricalData(value: StatusMessage[]) { - data = value; +export function getRealtimeData(): StatusMessage[] { + return realtimeData ?? []; } export async function getHistoricalData(url: string): Promise {