Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@tanstack/react-query-devtools": "^5.104.0",
"@tanstack/react-router": "^1.170.39",
"@tanstack/react-router-devtools": "^1.167.2",
"@tanstack/react-table": "^8.21.3",
"@tanstack/react-table": "^9.2.4",
"axios": "1.20.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/Admin/columns.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ColumnDef } from "@tanstack/react-table"

import type { UserPublic } from "@/client"
import type { DataTableFeatures } from "@/components/Common/DataTable"
import { Badge } from "@/components/ui/badge"
import { cn } from "@/lib/utils"
import { UserActionsMenu } from "./UserActionsMenu"
Expand All @@ -9,7 +10,7 @@ export type UserTableData = UserPublic & {
isCurrentUser: boolean
}

export const columns: ColumnDef<UserTableData>[] = [
export const columns: ColumnDef<DataTableFeatures, UserTableData>[] = [
{
accessorKey: "full_name",
header: "Full Name",
Expand Down
46 changes: 26 additions & 20 deletions frontend/src/components/Common/DataTable.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {
type ColumnDef,
createPaginatedRowModel,
flexRender,
getCoreRowModel,
getPaginationRowModel,
useReactTable,
type RowData,
rowPaginationFeature,
tableFeatures,
useTable,
} from "@tanstack/react-table"
import {
ChevronLeft,
Expand All @@ -29,20 +31,26 @@ import {
TableRow,
} from "@/components/ui/table"

interface DataTableProps<TData, TValue> {
columns: ColumnDef<TData, TValue>[]
const dataTableFeatures = tableFeatures({
rowPaginationFeature,
paginatedRowModel: createPaginatedRowModel(),
})

export type DataTableFeatures = typeof dataTableFeatures

interface DataTableProps<TData extends RowData> {
columns: ColumnDef<DataTableFeatures, TData>[]
data: TData[]
}

export function DataTable<TData, TValue>({
export function DataTable<TData extends RowData>({
columns,
data,
}: DataTableProps<TData, TValue>) {
const table = useReactTable({
}: DataTableProps<TData>) {
const table = useTable({
features: dataTableFeatures,
data,
columns,
getCoreRowModel: getCoreRowModel(),
getPaginationRowModel: getPaginationRowModel(),
})

return (
Expand Down Expand Up @@ -70,7 +78,7 @@ export function DataTable<TData, TValue>({
{table.getRowModel().rows.length ? (
table.getRowModel().rows.map((row) => (
<TableRow key={row.id}>
{row.getVisibleCells().map((cell) => (
{row.getAllCells().map((cell) => (
<TableCell key={cell.id}>
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</TableCell>
Expand All @@ -95,13 +103,13 @@ export function DataTable<TData, TValue>({
<div className="flex flex-col sm:flex-row sm:items-center gap-4">
<div className="text-sm text-muted-foreground">
Showing{" "}
{table.getState().pagination.pageIndex *
table.getState().pagination.pageSize +
{table.state.pagination.pageIndex *
table.state.pagination.pageSize +
1}{" "}
to{" "}
{Math.min(
(table.getState().pagination.pageIndex + 1) *
table.getState().pagination.pageSize,
(table.state.pagination.pageIndex + 1) *
table.state.pagination.pageSize,
data.length,
)}{" "}
of{" "}
Expand All @@ -111,15 +119,13 @@ export function DataTable<TData, TValue>({
<div className="flex items-center gap-x-2">
<p className="text-sm text-muted-foreground">Rows per page</p>
<Select
value={`${table.getState().pagination.pageSize}`}
value={`${table.state.pagination.pageSize}`}
onValueChange={(value) => {
table.setPageSize(Number(value))
}}
>
<SelectTrigger className="h-8 w-[70px]">
<SelectValue
placeholder={table.getState().pagination.pageSize}
/>
<SelectValue placeholder={table.state.pagination.pageSize} />
</SelectTrigger>
<SelectContent side="top">
{[5, 10, 25, 50].map((pageSize) => (
Expand All @@ -136,7 +142,7 @@ export function DataTable<TData, TValue>({
<div className="flex items-center gap-x-1 text-sm text-muted-foreground">
<span>Page</span>
<span className="font-medium text-foreground">
{table.getState().pagination.pageIndex + 1}
{table.state.pagination.pageIndex + 1}
</span>
<span>of</span>
<span className="font-medium text-foreground">
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/Items/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ColumnDef } from "@tanstack/react-table"
import { Check, Copy } from "lucide-react"

import type { ItemPublic } from "@/client"
import type { DataTableFeatures } from "@/components/Common/DataTable"
import { Button } from "@/components/ui/button"
import { useCopyToClipboard } from "@/hooks/useCopyToClipboard"
import { cn } from "@/lib/utils"
Expand Down Expand Up @@ -31,7 +32,7 @@ function CopyId({ id }: { id: string }) {
)
}

export const columns: ColumnDef<ItemPublic>[] = [
export const columns: ColumnDef<DataTableFeatures, ItemPublic>[] = [
{
accessorKey: "id",
header: "ID",
Expand Down
Loading