"use client" import { useMemo } from "react" import type { PingProbe, Server, ServerType } from "@/lib/data" import { Flag } from "@/components/flag" import { StatusBadge } from "@/components/status-badge" import { StatusDot } from "@/components/status-dot" import { Sparkline } from "@/components/sparkline" import { CompactDataGrid, type CompactDataGridColumn } from "@/components/data-grids/compact-data-grid" import { cn } from "@/lib/utils" import { FilterIcon } from "lucide-react" function formatLossPct(loss: number): string { if (!Number.isFinite(loss)) return "—" return Number.isInteger(loss) ? `${loss}%` : `${loss.toFixed(1)}%` } function TypeChip({ type }: { type: ServerType }) { return ( {type === "jump-host" ? "JH" : type === "home-router" ? "HR" : "EN"} ) } function ProbeSourceCell({ probe, catalog }: { probe: PingProbe; catalog: Server[] }) { const srv = catalog.find((s) => s.id === probe.srcServerId) const iface = (probe.srcInterface ?? "").trim() || "auto" if (!srv) { return (

Сервер {probe.srcServerId}

{iface}

) } return (
{srv.name}

{iface} {srv.site && srv.site !== "—" && ( · {srv.site} )}

) } interface DashboardActiveProbesDataGridProps { probes: PingProbe[] catalog: Server[] isLoading?: boolean emptyTitle?: string emptyDescription?: string } function DashboardActiveProbesDataGrid({ probes, catalog, isLoading, emptyTitle = "Нет активных проб", emptyDescription, }: DashboardActiveProbesDataGridProps) { const columns = useMemo[]>( () => [ { id: "source", header: "Источник", enableSorting: false, cell: (p) => , }, { id: "name", header: "Проба", accessorKey: "name", cell: (p) => {p.name}, }, { id: "target", header: "Цель", accessorKey: "target", cell: (p) => {p.target}, }, { id: "filter", header: "Фильтр", accessorKey: "filter", enableSorting: false, cell: (p) => ( {p.filter} ), }, { id: "rtt", header: "RTT", headerClassName: "text-right", cellClassName: "font-mono text-right", cell: (p) => (p.rtt == null ? "—" : `${p.rtt} мс`), }, { id: "loss", header: "Потери", headerClassName: "text-right", cellClassName: "font-mono text-right", cell: (p) => ( 5 ? "text-red-500" : p.loss > 0 ? "text-amber-500" : "text-muted-foreground", )} > {formatLossPct(p.loss)} ), }, { id: "series", header: "60с", enableSorting: false, headerClassName: "w-36", cell: (p) => { const sparkColor = p.status === "down" ? "hsl(0 84% 60%)" : p.status === "warn" ? "hsl(32 94% 44%)" : "hsl(142 76% 36%)" return }, }, { id: "status", header: "Статус", enableSorting: false, cell: (p) => ( ), }, ], [catalog], ) return ( ) } export { DashboardActiveProbesDataGrid, type DashboardActiveProbesDataGridProps }