import { IconDotsVertical, IconEdit, IconPower, IconTrash } from "@tabler/icons-react"; import { createColumnHelper, getCoreRowModel, useReactTable } from "@tanstack/react-table"; import { useMemo } from "react"; import type { Stream } from "src/api/backend"; import { CertificateFormatter, DomainsFormatter, GravatarFormatter, StatusFormatter } from "src/components"; import { TableLayout } from "src/components/Table/TableLayout"; import { intl } from "src/locale"; import Empty from "./Empty"; interface Props { data: Stream[]; isFetching?: boolean; } export default function Table({ data, isFetching }: 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: "incomingPort", header: intl.formatMessage({ id: "column.incoming-port" }), cell: (info: any) => { const value = info.getValue(); // Bit of a hack to reuse the DomainsFormatter component return ; }, }), columnHelper.accessor((row: any) => row, { id: "forwardHttpCode", header: intl.formatMessage({ id: "column.destination" }), cell: (info: any) => { const value = info.getValue(); return `${value.forwardingHost}:${value.forwardingPort}`; }, }), columnHelper.accessor((row: any) => row, { id: "tcpForwarding", header: intl.formatMessage({ id: "column.protocol" }), cell: (info: any) => { const value = info.getValue(); return ( <> {value.tcpForwarding ? ( {intl.formatMessage({ id: "streams.tcp" })} ) : null} {value.udpForwarding ? ( {intl.formatMessage({ id: "streams.udp" })} ) : null} ); }, }), columnHelper.accessor((row: any) => row.certificate, { id: "certificate", header: intl.formatMessage({ id: "column.ssl" }), 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", // todo: not needed for a display? cell: (info: any) => { return (
{intl.formatMessage( { id: "streams.actions-title", }, { id: info.row.original.id }, )} {intl.formatMessage({ id: "action.edit" })} {intl.formatMessage({ id: "action.disable" })} ); }, meta: { className: "text-end w-1", }, }), ], [columnHelper], ); const tableInstance = useReactTable({ columns, data, getCoreRowModel: getCoreRowModel(), rowCount: data.length, meta: { isFetching, }, enableSortingRemoval: false, }); return } />; }