|
| 1 | +"use client" |
| 2 | + |
| 3 | +import { type ColumnDef } from "@tanstack/react-table" |
| 4 | + |
| 5 | +import { type Task } from "@/data/schema" |
| 6 | +import { labels, priorities, statuses } from "@/data/data" |
| 7 | +import { Checkbox } from "./ui/checkbox" |
| 8 | +import { DataTableColumnHeader } from "./table/data-table-column-header" |
| 9 | +import { Badge } from "./ui/badge" |
| 10 | +import { DataTableRowActions } from "./table/data-table-row-actions" |
| 11 | + |
| 12 | +const columns: ColumnDef<Task>[] = [ |
| 13 | + { |
| 14 | + id: "select", |
| 15 | + header: ({ table }) => ( |
| 16 | + <Checkbox |
| 17 | + checked={ |
| 18 | + table.getIsAllPageRowsSelected() || |
| 19 | + (table.getIsSomePageRowsSelected() && "indeterminate") |
| 20 | + } |
| 21 | + onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)} |
| 22 | + aria-label="Select all" |
| 23 | + className="translate-y-[2px]" |
| 24 | + /> |
| 25 | + ), |
| 26 | + cell: ({ row }) => ( |
| 27 | + <Checkbox |
| 28 | + checked={row.getIsSelected()} |
| 29 | + onCheckedChange={(value) => row.toggleSelected(!!value)} |
| 30 | + aria-label="Select row" |
| 31 | + className="translate-y-[2px]" |
| 32 | + /> |
| 33 | + ), |
| 34 | + enableSorting: false, |
| 35 | + enableHiding: false, |
| 36 | + }, |
| 37 | + { |
| 38 | + accessorKey: "id", |
| 39 | + header: ({ column }) => ( |
| 40 | + <DataTableColumnHeader column={column} title="Task" /> |
| 41 | + ), |
| 42 | + cell: ({ row }) => <div className="w-[80px]">{row.getValue("id")}</div>, |
| 43 | + enableSorting: false, |
| 44 | + enableHiding: false, |
| 45 | + }, |
| 46 | + { |
| 47 | + accessorKey: "title", |
| 48 | + header: ({ column }) => ( |
| 49 | + <DataTableColumnHeader column={column} title="Title" /> |
| 50 | + ), |
| 51 | + cell: ({ row }) => { |
| 52 | + const label = labels.find((label) => label.value === row.original.label) |
| 53 | + |
| 54 | + return ( |
| 55 | + <div className="flex space-x-2"> |
| 56 | + {label && <Badge variant="outline">{label.label}</Badge>} |
| 57 | + <span className="max-w-[500px] truncate font-medium"> |
| 58 | + {row.getValue("title")} |
| 59 | + </span> |
| 60 | + </div> |
| 61 | + ) |
| 62 | + }, |
| 63 | + }, |
| 64 | + { |
| 65 | + accessorKey: "status", |
| 66 | + header: ({ column }) => ( |
| 67 | + <DataTableColumnHeader column={column} title="Status" /> |
| 68 | + ), |
| 69 | + cell: ({ row }) => { |
| 70 | + const status = statuses.find( |
| 71 | + (status) => status.value === row.getValue("status") |
| 72 | + ) |
| 73 | + |
| 74 | + if (!status) { |
| 75 | + return null |
| 76 | + } |
| 77 | + |
| 78 | + return ( |
| 79 | + <div className="flex w-[100px] items-center"> |
| 80 | + {status.icon && ( |
| 81 | + <status.icon className="mr-2 h-4 w-4 text-muted-foreground" /> |
| 82 | + )} |
| 83 | + <span>{status.label}</span> |
| 84 | + </div> |
| 85 | + ) |
| 86 | + }, |
| 87 | + // filterFn: (row, id, value) => { |
| 88 | + // return value.includes(row.getValue(id)) |
| 89 | + // }, |
| 90 | + }, |
| 91 | + { |
| 92 | + accessorKey: "priority", |
| 93 | + header: ({ column }) => ( |
| 94 | + <DataTableColumnHeader column={column} title="Priority" /> |
| 95 | + ), |
| 96 | + cell: ({ row }) => { |
| 97 | + const priority = priorities.find( |
| 98 | + (priority) => priority.value === row.getValue("priority") |
| 99 | + ) |
| 100 | + |
| 101 | + if (!priority) { |
| 102 | + return null |
| 103 | + } |
| 104 | + |
| 105 | + return ( |
| 106 | + <div className="flex items-center"> |
| 107 | + {priority.icon && ( |
| 108 | + <priority.icon className="mr-2 h-4 w-4 text-muted-foreground" /> |
| 109 | + )} |
| 110 | + <span>{priority.label}</span> |
| 111 | + </div> |
| 112 | + ) |
| 113 | + }, |
| 114 | + // filterFn: (row, id, value) => { |
| 115 | + // return value.includes(row.getValue(id)) |
| 116 | + // }, |
| 117 | + }, |
| 118 | + { |
| 119 | + id: "actions", |
| 120 | + cell: ({ row }) => <DataTableRowActions row={row} />, |
| 121 | + }, |
| 122 | +] |
| 123 | + |
| 124 | +export default columns |
| 125 | + |
0 commit comments