"use client" import { ColumnDef, ColumnFiltersState, SortingState, flexRender, getCoreRowModel, getFilteredRowModel, getPaginationRowModel, getSortedRowModel, useReactTable, } from "@tanstack/react-table" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import * as React from "react" interface DataTableProps { columns: ColumnDef[] data: TData[] searchKey: string searchPlaceholder?: string, headerActions?: React.ReactNode, } export function DataTable({ columns, data, searchKey, searchPlaceholder, headerActions, }: DataTableProps) { const [sorting, setSorting] = React.useState([]) const [columnFilters, setColumnFilters] = React.useState( [] ) const table = useReactTable({ data, columns, getCoreRowModel: getCoreRowModel(), getPaginationRowModel: getPaginationRowModel(), onSortingChange: setSorting, getSortedRowModel: getSortedRowModel(), onColumnFiltersChange: setColumnFilters, getFilteredRowModel: getFilteredRowModel(), autoResetPageIndex: false, state: { sorting, columnFilters, }, }) return (
table.getColumn(searchKey)?.setFilterValue(event.target.value) } className="max-w-sm" /> {/* TODO(auth): Combine this logic with existing add repo button logic in AddRepoButton component Show a button on the demo site that allows users to add new repositories by updating the demo-site-config.json file and opening a PR. */} {headerActions}
{table.getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header) => { return ( {header.isPlaceholder ? null : flexRender( header.column.columnDef.header, header.getContext() )} ) })} ))} {table.getRowModel().rows?.length ? ( table.getRowModel().rows.map((row) => ( {row.getVisibleCells().map((cell) => ( {flexRender(cell.column.columnDef.cell, cell.getContext())} ))} )) ) : ( No results. )}
) }