import { useEffect, useState } from "react"; import { useTranslation } from "@termix/plugin-sdk/frontend"; import type { MetricsChartConfig, MetricsChartMetric, MetricsChartRange, WidgetEditFormProps, } from "@/types/homepage-types"; import { getSSHHosts } from "@/api/ssh-host-management-api"; import { Select2 } from "@/components/select2"; const METRICS: { id: MetricsChartMetric; label: string }[] = [ { id: "cpu", label: "CPU" }, { id: "memory", label: "Memory" }, { id: "disk", label: "Disk" }, { id: "net_rx", label: "RX MB/s" }, { id: "net_tx", label: "TX MB/s" }, ]; const RANGES: { id: MetricsChartRange; label: string }[] = [ { id: "15m", label: "15m" }, { id: "1h", label: "1h" }, { id: "6h", label: "6h" }, { id: "24h", label: "24h" }, ]; export function MetricsChartEditForm({ config, onChange, }: WidgetEditFormProps) { const { t } = useTranslation(); const [hosts, setHosts] = useState<{ id: number; name: string }[]>([]); useEffect(() => { getSSHHosts() .then((h) => setHosts(h.map((x) => ({ id: x.id, name: x.name })))) .catch(() => {}); }, []); return (
onChange({ ...config, hostId: Number(e.target.value) }) } className="h-8 text-xs bg-background border border-border px-2 text-foreground" > {hosts.map((h) => ( ))}
{METRICS.map((m) => ( ))}
{RANGES.map((r) => ( ))}
); }