"use client" import { useMemo } from "react" import { type ColumnDef, getCoreRowModel, useReactTable, } from "@tanstack/react-table" import { ActionBadge, ChainBadge } from "@/components/data-grids/firewall-rules-data-grid" 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 { cn } from "@/lib/utils" import { PowerIcon, Trash2Icon } from "lucide-react" function ScenarioCell({ enabled, children }: { enabled: boolean; children: React.ReactNode }) { return
{children}
} export interface ScenarioRuleRow { id: string chain: string action: string proto: string src: string dst: string port: string iface: string comment: string enabled: boolean } interface FirewallScenarioRulesDataGridProps { rules: ScenarioRuleRow[] onToggleEnabled: (id: string) => void onMoveUp: (id: string) => void onMoveDown: (id: string) => void onRemove: (id: string) => void } function FirewallScenarioRulesDataGrid({ rules, onToggleEnabled, onMoveUp, onMoveDown, onRemove, }: FirewallScenarioRulesDataGridProps) { const indexedRules = useMemo( () => rules.map((rule, index) => ({ ...rule, _index: index + 1 })), [rules], ) const columns = useMemo[]>( () => [ { id: "index", accessorKey: "_index", header: () => #, enableSorting: false, cell: ({ row }) => ( {row.original._index} ), size: 40, meta: { headerClassName: DATA_GRID_CELL_PAD_FIRST, cellClassName: DATA_GRID_CELL_PAD_FIRST, }, }, { id: "chain", accessorKey: "chain", header: () => Цепочка, enableSorting: false, cell: ({ row }) => ( ), meta: { headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD }, }, { id: "action", accessorKey: "action", header: () => Действие, enableSorting: false, cell: ({ row }) => , meta: { headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD }, }, { id: "src", accessorKey: "src", header: () => Src, enableSorting: false, cell: ({ row }) => ( {row.original.src || "any"} ), meta: { headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD }, }, { id: "dst", accessorKey: "dst", header: () => Dst, enableSorting: false, cell: ({ row }) => ( {row.original.dst || "any"} ), meta: { headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD }, }, { id: "port", accessorKey: "port", header: () => Порт, enableSorting: false, cell: ({ row }) => ( {row.original.port || "—"} ), meta: { headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD }, }, { id: "iface", accessorKey: "iface", header: () => Iface, enableSorting: false, cell: ({ row }) => ( {row.original.iface || "—"} ), meta: { headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD }, }, { id: "comment", accessorKey: "comment", header: () => Комментарий, enableSorting: false, cell: ({ row }) => ( {row.original.comment || "—"} ), meta: { headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD }, }, { id: "actions", header: () => null, enableSorting: false, cell: ({ row }) => { const index = row.original._index - 1 return (
) }, meta: { headerClassName: DATA_GRID_CELL_PAD_LAST, cellClassName: DATA_GRID_CELL_PAD_LAST }, }, ], [onMoveDown, onMoveUp, onRemove, onToggleEnabled, rules.length], ) const table = useReactTable({ data: indexedRules, columns, getCoreRowModel: getCoreRowModel(), getRowId: (row) => row.id, }) return ( ) } export { FirewallScenarioRulesDataGrid, type FirewallScenarioRulesDataGridProps }