import { Fragment } from "react"; import { ColumnDef, flexRender, getCoreRowModel, getSortedRowModel, SortingState, useReactTable, ColumnResizeMode, VisibilityState, } from "@tanstack/react-table"; import React from "react"; import { Table, TableHead, TableHeaderCell, TableBody, TableRow, TableCell, } from "@tremor/react"; import { SwitchVerticalIcon, ChevronUpIcon, ChevronDownIcon, TableIcon } from "@heroicons/react/outline"; interface ModelDataTableProps { data: TData[]; columns: ColumnDef[]; isLoading?: boolean; table: any; // Add table prop to access column visibility controls } export function ModelDataTable({ data = [], columns, isLoading = false, table }: ModelDataTableProps) { const [sorting, setSorting] = React.useState([ { id: "model_info.created_at", desc: true } ]); const [columnResizeMode] = React.useState("onChange"); const [columnSizing, setColumnSizing] = React.useState({}); const [columnVisibility, setColumnVisibility] = React.useState({}); const tableInstance = useReactTable({ data, columns, state: { sorting, columnSizing, columnVisibility, }, columnResizeMode, onSortingChange: setSorting, onColumnSizingChange: setColumnSizing, onColumnVisibilityChange: setColumnVisibility, getCoreRowModel: getCoreRowModel(), getSortedRowModel: getSortedRowModel(), enableSorting: true, enableColumnResizing: true, defaultColumn: { minSize: 40, maxSize: 500, }, }); // Expose table instance to parent React.useEffect(() => { if (table) { table.current = tableInstance; } }, [tableInstance, table]); const getHeaderText = (header: any): string => { if (typeof header === 'string') { return header; } if (typeof header === 'function') { const headerElement = header(); if (headerElement && headerElement.props && headerElement.props.children) { const children = headerElement.props.children; if (typeof children === 'string') { return children; } if (children.props && children.props.children) { return children.props.children; } } } return ''; }; return (
{tableInstance.getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header) => (
{header.isPlaceholder ? null : ( flexRender( header.column.columnDef.header, header.getContext() ) )}
{header.id !== 'actions' && (
{header.column.getIsSorted() ? ( { asc: , desc: }[header.column.getIsSorted() as string] ) : ( )}
)}
{header.column.getCanResize() && (
)} ))} ))} {isLoading ? (

🚅 Loading models...

) : tableInstance.getRowModel().rows.length > 0 ? ( tableInstance.getRowModel().rows.map((row) => ( {row.getVisibleCells().map((cell) => ( {flexRender(cell.column.columnDef.cell, cell.getContext())} ))} )) ) : (

No models found

)}
); }