// Observability (PEP-202): shared pieces of the monitors list and the monitor page. // glossary-ignore-file: the section is for the superadmin only. import type { MonitorKind, MonitorState, MonitorView } from "@peppa/core"; import type { Translator } from "@peppa/shared/i18n"; import { Badge } from "@/components/ui/badge"; import { Input, Label, NativeSelect } from "@/components/ui/input"; import { cn } from "@/lib/utils"; import { m } from "@peppa/shared/i18n"; export const KIND_LABEL: Record = { http: "HTTP(S)", tcp: "TCP", dns: "DNS", internet: m("Интернет"), heartbeat: "Heartbeat" }; const STATE_LABEL: Record = { up: m("работает"), down: m("не работает"), degraded: m("нестабилен"), unknown: m("проверяется") }; const STATE_VARIANT = { up: "ok", down: "danger", degraded: "warn", unknown: "muted" } as const; export function StateBadge({ m, t }: { m: Pick; t: Translator }) { if (m.paused) return {t("на паузе")}; return {t(STATE_LABEL[m.state])}; } export const pct = (v: number | null) => (v == null ? "—" : `${(v * 100).toFixed(v >= 0.9995 ? 0 : 2)}%`); /** The last checks as a strip of bars, oldest left. */ export function CheckStrip({ recent, t }: { recent: MonitorView["recent"]; t: Translator }) { return (
{Array.from({ length: Math.max(0, 30 - recent.length) }, (_, i) => ( ))} {recent.map((c) => ( ))}
); } /** Fields of the create / edit form; `where` is read by the kind (address, host, host:port, hosts). */ export function MonitorFields({ t, m, kindFixed }: { t: Translator; m?: MonitorView; kindFixed?: boolean }) { const tg = (m?.target ?? {}) as Record; const where = !m ? "" : m.kind === "http" ? String(tg.url) : m.kind === "tcp" ? `${tg.host}:${tg.port}` : m.kind === "dns" ? String(tg.host) : m.kind === "internet" ? (tg.hosts as string[]).join(", ") : ""; return (
); }