"use client"; import React, { useState } from "react"; import { ColumnDef, flexRender, getCoreRowModel, getPaginationRowModel, getSortedRowModel, useReactTable, SortingState, } from "@tanstack/react-table"; import { Button } from "@/components/ui/button"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { Badge } from "@/components/ui/badge"; import { format } from "date-fns"; import { BarChart3, Calendar, ChevronLeft, ChevronRight } from "lucide-react"; interface Import { id: number; name: string; importDate: string; layoutId: number; layout: { id: number; name: string; }; } interface TerraTechImportsTableProps { data: Import[]; onViewSummary: (importRecord: Import) => void; } export function TerraTechImportsTable({ data, onViewSummary }: TerraTechImportsTableProps) { const [sorting, setSorting] = useState([ { id: "importDate", desc: true }, ]); const columns: ColumnDef[] = [ { accessorKey: "name", header: "Name", cell: ({ row }) => (
{row.getValue("name")}
), }, { accessorKey: "layout.name", header: "Layout", cell: ({ row }) => ( {row.original.layout.name} ), }, { accessorKey: "importDate", header: "Import Date", cell: ({ row }) => { const date = new Date(row.getValue("importDate")); return (
{format(date, "MMM d, yyyy HH:mm")}
); }, }, { id: "actions", header: "Actions", cell: ({ row }) => (
), enableSorting: false, }, ]; const table = useReactTable({ data, columns, state: { sorting, }, onSortingChange: setSorting, getCoreRowModel: getCoreRowModel(), getPaginationRowModel: getPaginationRowModel(), getSortedRowModel: getSortedRowModel(), initialState: { pagination: { pageSize: 10, }, }, }); return (
{table.getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header) => (
{flexRender( header.column.columnDef.header, header.getContext() )} {header.column.getIsSorted() && ( {header.column.getIsSorted() === "asc" ? "↑" : "↓"} )}
))}
))}
{table.getRowModel().rows?.length ? ( table.getRowModel().rows.map((row) => ( {row.getVisibleCells().map((cell) => ( {flexRender(cell.column.columnDef.cell, cell.getContext())} ))} )) ) : ( No results. )}
Showing {table.getRowModel().rows.length} of {data.length} imports
Page {table.getState().pagination.pageIndex + 1} of{" "} {table.getPageCount()}
); }