mirror of
https://github.com/csehviktor/status-monitor.git
synced 2025-08-08 18:06:14 +02:00
fix naming + data type
This commit is contained in:
@@ -1,15 +1,15 @@
|
|||||||
import type { TimePeriod } from "@/services/store";
|
import type { TimePeriod } from "@/services/store";
|
||||||
|
|
||||||
type TimePeriodSelectorProps = {
|
type TimePeriodSelectorProps = {
|
||||||
currentPeriod: TimePeriod | "realtime";
|
currentPeriod: TimePeriod;
|
||||||
onChange: (period: TimePeriod | "realtime") => void;
|
onChange: (period: TimePeriod) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function TimePeriodSelector({
|
export function TimePeriodSelector({
|
||||||
currentPeriod,
|
currentPeriod,
|
||||||
onChange,
|
onChange,
|
||||||
}: TimePeriodSelectorProps) {
|
}: TimePeriodSelectorProps) {
|
||||||
const periods: { value: TimePeriod | "realtime"; label: string }[] = [
|
const periods: { value: TimePeriod; label: string }[] = [
|
||||||
{ value: "realtime", label: "Real time" },
|
{ value: "realtime", label: "Real time" },
|
||||||
{ value: "hour", label: "Past hour" },
|
{ value: "hour", label: "Past hour" },
|
||||||
{ value: "day", label: "Past day" },
|
{ value: "day", label: "Past day" },
|
||||||
|
|||||||
@@ -22,10 +22,12 @@ export function AgentPage() {
|
|||||||
const { agent } = useParams();
|
const { agent } = useParams();
|
||||||
const { status, message } = useWebsocket(`ws://localhost:3000/ws/${agent}`);
|
const { status, message } = useWebsocket(`ws://localhost:3000/ws/${agent}`);
|
||||||
|
|
||||||
const [period, setPeriod] = useState<TimePeriod | "realtime">("all");
|
const [period, setPeriod] = useState<TimePeriod>("realtime");
|
||||||
const [history, setHistory] = useState<StatusMessage[] | null>(null);
|
const [history, setHistory] = useState<StatusMessage[] | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (period === "realtime") return;
|
||||||
|
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
const data = await getHistoricalData(
|
const data = await getHistoricalData(
|
||||||
`http://localhost:3000/history/${agent}/${period}`,
|
`http://localhost:3000/history/${agent}/${period}`,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { StatusMessage } from "@/services/types";
|
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[] = [];
|
let data: StatusMessage[] = [];
|
||||||
const maxRealtimePoints = 50;
|
const maxRealtimePoints = 50;
|
||||||
@@ -13,12 +13,12 @@ export function addDataPoint(value: StatusMessage) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getRealtimeData(): StatusMessage[] {
|
export function addDataPoint(value: StatusMessage) {
|
||||||
return data ?? [];
|
realtimeData.push(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setHistoricalData(value: StatusMessage[]) {
|
export function getRealtimeData(): StatusMessage[] {
|
||||||
data = value;
|
return realtimeData ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getHistoricalData(url: string): Promise<StatusMessage[]> {
|
export async function getHistoricalData(url: string): Promise<StatusMessage[]> {
|
||||||
|
|||||||
Reference in New Issue
Block a user