import { useEffect, useState } from "react"; import { useToast, useTranslation } from "@termix/plugin-sdk/frontend"; import { Button, Input } from "@termix/plugin-sdk/ui"; import { getMetricsHistoryRetention, saveMetricsHistoryRetention, } from "./host-metrics-api"; /** * How long metrics history is kept. Lives in the metrics backend's own * setting, so it saves with its own button rather than the page's. */ export function MetricsRetentionSetting() { const { t } = useTranslation(); const toast = useToast(); const [days, setDays] = useState("7"); useEffect(() => { let cancelled = false; getMetricsHistoryRetention() .then((value) => { if (!cancelled) setDays(String(value)); }) .catch(() => {}); return () => { cancelled = true; }; }, []); const save = async () => { const value = Number.parseInt(days, 10); if (Number.isNaN(value) || value < 1 || value > 90) { toast.error(t("admin.metricsHistoryRetentionRange")); return; } try { await saveMetricsHistoryRetention(value); toast.success(t("admin.monitoringSaved")); } catch { toast.error(t("admin.monitoringSaveFailed")); } }; return (