From 82ddaf6c9749005c9a245ef2bad72ad2c03ce9aa Mon Sep 17 00:00:00 2001 From: "[dyad]" Date: Fri, 12 Sep 2025 16:30:50 +0200 Subject: [PATCH] [dyad] Fixed quantity display to show total quantity in BookOutDataTable - wrote 1 file(s) --- src/components/book-out/BookOutDataTable.tsx | 204 ++++++------------- 1 file changed, 59 insertions(+), 145 deletions(-) diff --git a/src/components/book-out/BookOutDataTable.tsx b/src/components/book-out/BookOutDataTable.tsx index 633cb5d..dad193f 100644 --- a/src/components/book-out/BookOutDataTable.tsx +++ b/src/components/book-out/BookOutDataTable.tsx @@ -3,17 +3,10 @@ import * as React from "react" import { ColumnDef, - ColumnFiltersState, - SortingState, - VisibilityState, flexRender, getCoreRowModel, - getFilteredRowModel, - getPaginationRowModel, - getSortedRowModel, useReactTable, } from "@tanstack/react-table" -import { Columns } from "lucide-react" import { Table, @@ -24,13 +17,15 @@ import { TableRow, } from "@/components/ui/table" import { Button } from "@/components/ui/button" -import { Input } from "@/components/ui/input" -import { - DropdownMenu, - DropdownMenuCheckboxItem, - DropdownMenuContent, - DropdownMenuTrigger, -} from "@/components/ui/dropdown-menu" + +interface BookOutRecord { + id: string + customerName: string + itemName: string + sku: string + quantity: number | number[] // Can be number or array of numbers + dateBookedOut: string +} interface BookOutDataTableProps { columns: ColumnDef[] @@ -41,146 +36,65 @@ export function BookOutDataTable({ columns, data, }: BookOutDataTableProps) { - const [sorting, setSorting] = React.useState([]) - const [columnFilters, setColumnFilters] = React.useState([]) - const [columnVisibility, setColumnVisibility] = React.useState(() => { - if (typeof window !== 'undefined' && window.innerWidth < 768) { - return { - sku: false, - dateBookedOut: false, - actions: false, - }; - } - return {}; - }); - const [rowSelection, setRowSelection] = React.useState({}) - const table = useReactTable({ data, columns, getCoreRowModel: getCoreRowModel(), - getPaginationRowModel: getPaginationRowModel(), - onSortingChange: setSorting, - getSortedRowModel: getSortedRowModel(), - onColumnFiltersChange: setColumnFilters, - getFilteredRowModel: getFilteredRowModel(), - onColumnVisibilityChange: setColumnVisibility, - onRowSelectionChange: setRowSelection, - state: { - sorting, - columnFilters, - columnVisibility, - rowSelection, - }, }) return ( -
-
- - table.getColumn("customerName")?.setFilterValue(event.target.value) - } - className="max-w-sm" - /> - - - - - - {table - .getAllColumns() - .filter( - (column) => column.getCanHide() - ) - .map((column) => { - return ( - - column.toggleVisibility(!!value) +
+ + + {table.getHeaderGroups().map((headerGroup) => ( + + {headerGroup.headers.map((header) => ( + + {header.isPlaceholder + ? null + : flexRender(header.column.columnDef.header, header.getContext())} + + ))} + + ))} + + + {table.getRowModel().rows.length ? ( + table.getRowModel().rows.map((row) => { + const record = row.original as BookOutRecord + // Calculate total quantity if quantity is array + const totalQuantity = Array.isArray(record.quantity) + ? record.quantity.reduce((sum, q) => sum + q, 0) + : record.quantity + + return ( + + {row.getVisibleCells().map((cell) => { + if (cell.column.id === "quantity") { + return ( + + {totalQuantity} + + ) } - > - {column.id} - - ) - })} - - - -
-
- - {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())} - - ))} + return ( + + {flexRender(cell.column.columnDef.cell, cell.getContext())} + + ) + })} - )) - ) : ( - - - No results. - - - )} - -
-
-
-
- {table.getFilteredSelectedRowModel().rows.length} of{" "} - {table.getFilteredRowModel().rows.length} row(s) selected. -
- - -
+ ) + }) + ) : ( + + + No results. + + + )} + +
) } \ No newline at end of file