Docker images / prepare-release (push) Successful in 6s
Docker images / backend-image (push) Successful in 1m37s
Docker images / frontend-image (push) Successful in 1m50s
Docker images / updater-image (push) Successful in 44s
Docker images / notify-webhook (push) Has been skipped
Docker images / publish-release (push) Successful in 7s
156 lines
5.0 KiB
TypeScript
156 lines
5.0 KiB
TypeScript
"use client"
|
|
|
|
import { useMemo } from "react"
|
|
import {
|
|
type ColumnDef,
|
|
getCoreRowModel,
|
|
getPaginationRowModel,
|
|
getSortedRowModel,
|
|
useReactTable,
|
|
} from "@tanstack/react-table"
|
|
import type { Domain } from "@/lib/data"
|
|
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 { FilterIcon, GlobeIcon } from "lucide-react"
|
|
|
|
interface DomainsDataGridProps {
|
|
domains: Domain[]
|
|
isLoading?: boolean
|
|
pagination?: boolean
|
|
}
|
|
|
|
function DomainsDataGrid({ domains, isLoading, pagination = false }: DomainsDataGridProps) {
|
|
const columns = useMemo<ColumnDef<Domain>[]>(
|
|
() => [
|
|
{
|
|
id: "domain",
|
|
accessorKey: "domain",
|
|
header: ({ column }) => <DataGridSortHeader column={column} title="Домен" className="ml-1" />,
|
|
cell: ({ row }) => <span className="font-medium">{row.original.domain}</span>,
|
|
meta: {
|
|
headerTitle: "Домен",
|
|
headerClassName: DATA_GRID_CELL_PAD_FIRST,
|
|
cellClassName: DATA_GRID_CELL_PAD_FIRST,
|
|
},
|
|
},
|
|
{
|
|
id: "resolvedIp",
|
|
accessorKey: "resolvedIp",
|
|
header: ({ column }) => <DataGridSortHeader column={column} title="Resolved IP" />,
|
|
cell: ({ row }) => (
|
|
<span className="font-mono text-xs text-muted-foreground">{row.original.resolvedIp}</span>
|
|
),
|
|
meta: {
|
|
headerTitle: "Resolved IP",
|
|
headerClassName: DATA_GRID_CELL_PAD,
|
|
cellClassName: DATA_GRID_CELL_PAD,
|
|
},
|
|
},
|
|
{
|
|
id: "asn",
|
|
accessorKey: "asn",
|
|
header: ({ column }) => <DataGridSortHeader column={column} title="ASN" />,
|
|
cell: ({ row }) => <span className="font-mono text-xs">{row.original.asn}</span>,
|
|
meta: {
|
|
headerTitle: "ASN",
|
|
headerClassName: DATA_GRID_CELL_PAD,
|
|
cellClassName: DATA_GRID_CELL_PAD,
|
|
},
|
|
},
|
|
{
|
|
id: "purpose",
|
|
accessorKey: "purpose",
|
|
header: ({ column }) => <DataGridSortHeader column={column} title="Назначение" />,
|
|
cell: ({ row }) => (
|
|
<span className="text-xs border border-border rounded px-2 py-0.5">{row.original.purpose}</span>
|
|
),
|
|
meta: {
|
|
headerTitle: "Назначение",
|
|
headerClassName: DATA_GRID_CELL_PAD,
|
|
cellClassName: DATA_GRID_CELL_PAD,
|
|
},
|
|
},
|
|
{
|
|
id: "filter",
|
|
accessorKey: "filter",
|
|
header: ({ column }) => <DataGridSortHeader column={column} title="Фильтр" />,
|
|
cell: ({ row }) => (
|
|
<span className="inline-flex items-center gap-1 text-xs bg-muted rounded px-2 py-0.5">
|
|
<FilterIcon className="size-3 text-muted-foreground" />
|
|
{row.original.filter}
|
|
</span>
|
|
),
|
|
meta: {
|
|
headerTitle: "Фильтр",
|
|
headerClassName: DATA_GRID_CELL_PAD,
|
|
cellClassName: DATA_GRID_CELL_PAD,
|
|
},
|
|
},
|
|
{
|
|
id: "updated",
|
|
accessorKey: "updated",
|
|
header: ({ column }) => <DataGridSortHeader column={column} title="Обновлён" />,
|
|
cell: ({ row }) => <span className="text-xs text-muted-foreground">{row.original.updated}</span>,
|
|
meta: {
|
|
headerTitle: "Обновлён",
|
|
headerClassName: DATA_GRID_CELL_PAD,
|
|
cellClassName: DATA_GRID_CELL_PAD,
|
|
},
|
|
},
|
|
{
|
|
id: "enabled",
|
|
accessorKey: "enabled",
|
|
header: ({ column }) => <DataGridSortHeader column={column} title="Статус" />,
|
|
cell: ({ row }) => (
|
|
<span
|
|
className={`text-xs font-medium ${row.original.enabled ? "text-emerald-600" : "text-muted-foreground"}`}
|
|
>
|
|
{row.original.enabled ? "Активен" : "Отключён"}
|
|
</span>
|
|
),
|
|
meta: {
|
|
headerTitle: "Статус",
|
|
headerClassName: DATA_GRID_CELL_PAD_LAST,
|
|
cellClassName: DATA_GRID_CELL_PAD_LAST,
|
|
},
|
|
},
|
|
],
|
|
[],
|
|
)
|
|
|
|
const table = useReactTable({
|
|
data: domains,
|
|
columns,
|
|
getCoreRowModel: getCoreRowModel(),
|
|
getSortedRowModel: getSortedRowModel(),
|
|
...(pagination ? { getPaginationRowModel: getPaginationRowModel() } : {}),
|
|
getRowId: (row) => row.id,
|
|
})
|
|
|
|
return (
|
|
<DataGridShell
|
|
table={table}
|
|
recordCount={domains.length}
|
|
isLoading={isLoading}
|
|
loadingMode="skeleton"
|
|
pagination={pagination}
|
|
emptyMessage={
|
|
<EmptyState
|
|
icon={<GlobeIcon className="size-4" />}
|
|
title="Нет доменов"
|
|
description="Добавьте домены или импортируйте каталог"
|
|
className="border-0 py-12"
|
|
/>
|
|
}
|
|
/>
|
|
)
|
|
}
|
|
|
|
export { DomainsDataGrid, type DomainsDataGridProps }
|