import { IconDotsVertical, IconEdit, IconPower, IconTrash } from "@tabler/icons-react"; import { createColumnHelper, getCoreRowModel, useReactTable } from "@tanstack/react-table"; import { useMemo } from "react"; import type { ProxyHost } from "src/api/backend"; import { AccessListFormatter, CertificateFormatter, DomainsFormatter, EmptyData, GravatarFormatter, StatusFormatter, } from "src/components"; import { TableLayout } from "src/components/Table/TableLayout"; import { intl, T } from "src/locale"; interface Props { data: ProxyHost[]; isFiltered?: boolean; isFetching?: boolean; onEdit?: (id: number) => void; onDelete?: (id: number) => void; onDisableToggle?: (id: number, enabled: boolean) => void; onNew?: () => void; } export default function Table({ data, isFetching, onEdit, onDelete, onDisableToggle, onNew, isFiltered }: Props) { const columnHelper = createColumnHelper(); const columns = useMemo( () => [ columnHelper.accessor((row: any) => row.owner, { id: "owner", cell: (info: any) => { const value = info.getValue(); return ; }, meta: { className: "w-1", }, }), columnHelper.accessor((row: any) => row, { id: "domainNames", header: intl.formatMessage({ id: "column.source" }), cell: (info: any) => { const value = info.getValue(); return ; }, }), columnHelper.accessor((row: any) => row, { id: "forwardHost", header: intl.formatMessage({ id: "column.destination" }), cell: (info: any) => { const value = info.getValue(); return `${value.forwardHost}:${value.forwardPort}`; }, }), columnHelper.accessor((row: any) => row.certificate, { id: "certificate", header: intl.formatMessage({ id: "column.ssl" }), cell: (info: any) => { return ; }, }), columnHelper.accessor((row: any) => row.accessList, { id: "accessList", header: intl.formatMessage({ id: "column.access" }), cell: (info: any) => { return ; }, }), columnHelper.accessor((row: any) => row.enabled, { id: "enabled", header: intl.formatMessage({ id: "column.status" }), cell: (info: any) => { return ; }, }), columnHelper.display({ id: "id", cell: (info: any) => { return (
{ e.preventDefault(); onEdit?.(info.row.original.id); }} > { e.preventDefault(); onDisableToggle?.(info.row.original.id, !info.row.original.enabled); }} > ); }, meta: { className: "text-end w-1", }, }), ], [columnHelper, onEdit, onDisableToggle, onDelete], ); const tableInstance = useReactTable({ columns, data, getCoreRowModel: getCoreRowModel(), rowCount: data.length, meta: { isFetching, }, enableSortingRemoval: false, }); return ( } /> ); }