"use client" import { useMemo } from "react" import { type ColumnDef, getCoreRowModel, getSortedRowModel, useReactTable, } from "@tanstack/react-table" import { cn } from "@/lib/utils" import { DataGridShell } from "@/components/data-grids/shared/data-grid-shell" import { DATA_GRID_CELL_PAD, DATA_GRID_CELL_PAD_FIRST, DATA_GRID_CELL_PAD_LAST, } from "@/components/data-grids/shared/data-grid-layout" import { DataGridSortHeader } from "@/components/data-grids/shared/data-grid-sort-header" import { EmptyState } from "@/components/empty-state" import { ClockIcon } from "lucide-react" export interface SpeedProbeApiRow { id: string srcServerId: string dstServerId: string srcInterface: string dstInterface: string protocol: string direction: string durationSec: string enabled: boolean lastRunAt: string | null lastTxAvgMbps: number | null lastRxAvgMbps: number | null lastStatus: string | null lastError: string | null } interface ProbesSpeedProbesDataGridProps { rows: SpeedProbeApiRow[] serverName: (id: string) => string } function ProbesSpeedProbesDataGrid({ rows, serverName }: ProbesSpeedProbesDataGridProps) { const columns = useMemo[]>( () => [ { id: "src", header: ({ column }) => , accessorFn: (row) => row.srcServerId, cell: ({ row }) => { const r = row.original return ( {serverName(r.srcServerId)} {r.srcInterface ? ` · ${r.srcInterface}` : ""} ) }, meta: { headerTitle: "Источник", headerClassName: DATA_GRID_CELL_PAD_FIRST, cellClassName: DATA_GRID_CELL_PAD_FIRST, }, }, { id: "dst", accessorFn: (row) => row.dstServerId, header: ({ column }) => , cell: ({ row }) => { const r = row.original return ( {serverName(r.dstServerId)} {r.dstInterface ? ` · ${r.dstInterface}` : ""} ) }, meta: { headerTitle: "Назначение", headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD, }, }, { id: "protocol", accessorKey: "protocol", header: ({ column }) => , cell: ({ row }) => {row.original.protocol.toUpperCase()}, meta: { headerTitle: "Протокол", headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD, }, }, { id: "durationSec", accessorKey: "durationSec", header: ({ column }) => , cell: ({ row }) => {row.original.durationSec}s, meta: { headerTitle: "Сек", headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD, }, }, { id: "enabled", accessorKey: "enabled", header: ({ column }) => , cell: ({ row }) => {row.original.enabled ? "да" : "нет"}, meta: { headerTitle: "Вкл", headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD, }, }, { id: "lastRunAt", accessorKey: "lastRunAt", header: ({ column }) => , cell: ({ row }) => { const r = row.original return ( {r.lastRunAt ?? "—"} {r.lastStatus === "done" && r.lastTxAvgMbps != null && ( TX≈{r.lastTxAvgMbps.toFixed(1)} RX≈{(r.lastRxAvgMbps ?? 0).toFixed(1)} Mb/s )} {r.lastStatus === "error" && r.lastError && ( {r.lastError} )} ) }, meta: { headerTitle: "Последний запуск", headerClassName: DATA_GRID_CELL_PAD_LAST, cellClassName: DATA_GRID_CELL_PAD_LAST, }, }, ], [serverName], ) const table = useReactTable({ data: rows, columns, getCoreRowModel: getCoreRowModel(), getSortedRowModel: getSortedRowModel(), getRowId: (row) => row.id, }) if (rows.length === 0) { return ( } title="Нет записей speed-test" description="Настраиваются через API PUT /api/uptime/speed-probes" className="border-0 py-10" /> ) } return ( ) } export { ProbesSpeedProbesDataGrid, type ProbesSpeedProbesDataGridProps }