From 1a2241c40e10193c5ff7008a7b7b36cc1d855d96 Mon Sep 17 00:00:00 2001
From: joonhoekim <26rote@gmail.com>
Date: Tue, 25 Mar 2025 15:55:45 +0900
Subject: initial commit

---
 lib/vendor-document/table/doc-table-column.tsx | 150 +++++++++++++++++++++++++
 1 file changed, 150 insertions(+)
 create mode 100644 lib/vendor-document/table/doc-table-column.tsx

(limited to 'lib/vendor-document/table/doc-table-column.tsx')

diff --git a/lib/vendor-document/table/doc-table-column.tsx b/lib/vendor-document/table/doc-table-column.tsx
new file mode 100644
index 00000000..e53b03b9
--- /dev/null
+++ b/lib/vendor-document/table/doc-table-column.tsx
@@ -0,0 +1,150 @@
+"use client"
+
+import * as React from "react"
+import { ColumnDef } from "@tanstack/react-table"
+import { formatDate, formatDateTime } from "@/lib/utils"
+import { Checkbox } from "@/components/ui/checkbox"
+import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header"
+import { DataTableRowAction } from "@/types/table"
+import { VendorDocumentsView } from "@/db/schema/vendorDocu"
+
+interface GetColumnsProps {
+  setRowAction: React.Dispatch<React.SetStateAction<DataTableRowAction<VendorDocumentsView> | null>>
+}
+
+export function getColumns({
+  setRowAction,
+}: GetColumnsProps): ColumnDef<VendorDocumentsView>[] {
+  return [
+    {
+      id: "select",
+      // Remove the "Select all" checkbox in header since we're doing single-select
+      header: () => <span className="sr-only">Select</span>,
+      cell: ({ row, table }) => (
+        <Checkbox
+          checked={row.getIsSelected()}
+          onCheckedChange={(value) => {
+            // If selecting this row
+            if (value) {
+              // First deselect all rows (to ensure single selection)
+              table.toggleAllRowsSelected(false)
+              // Then select just this row
+              row.toggleSelected(true)
+              // Trigger the same action that was in the "Select" button
+              setRowAction({ row, type: "select" })
+            } else {
+              // Just deselect this row
+              row.toggleSelected(false)
+            }
+          }}
+          aria-label="Select row"
+          className="translate-y-0.5"
+        />
+      ),
+      enableSorting: false,
+      enableHiding: false,
+      enableResizing: false,
+      size: 40,
+      minSize: 40,
+      maxSize: 40,
+    },
+    
+    {
+      accessorKey: "docNumber",
+      header: ({ column }) => (
+        <DataTableColumnHeaderSimple column={column} title="Doc Number" />
+      ),
+      cell: ({ row }) => <div>{row.getValue("docNumber")}</div>,
+      meta: {
+        excelHeader: "Doc Number"
+      },
+      enableResizing: true,
+      minSize: 100,
+      size: 160,
+    },
+    {
+      accessorKey: "title",
+      header: ({ column }) => (
+        <DataTableColumnHeaderSimple column={column} title="Doc title" />
+      ),
+      cell: ({ row }) => <div>{row.getValue("title")}</div>,
+      meta: {
+        excelHeader: "Doc title"
+      },
+      enableResizing: true,
+      minSize: 100,
+      size: 160,
+    },
+    {
+      accessorKey: "latestStageName",
+      header: ({ column }) => (
+        <DataTableColumnHeaderSimple column={column} title="Latest Stage Name" />
+      ),
+      cell: ({ row }) => <div>{row.getValue("latestStageName")}</div>,
+      meta: {
+        excelHeader: "Latest Stage Name"
+      },
+      enableResizing: true,
+      minSize: 100,
+      size: 160,
+    },
+    {
+      accessorKey: "latestStagePlanDate",
+      header: ({ column }) => (
+        <DataTableColumnHeaderSimple column={column} title="Latest Stage Plan Date" />
+      ),
+      cell: ({ cell }) => {
+        const value = cell.getValue();
+        return value ? formatDate(value as Date) : "";
+      },      meta: {
+        excelHeader: "Latest Stage Plan Date"
+      },
+      enableResizing: true,
+      minSize: 100,
+      size: 160,
+    },
+    {
+      accessorKey: "latestStageActualDate",
+      header: ({ column }) => (
+        <DataTableColumnHeaderSimple column={column} title="Latest Stage Actual Date" />
+      ),
+      cell: ({ cell }) => {
+        const value = cell.getValue();
+        return value ? formatDate(value as Date) : "";
+      },      meta: {
+        excelHeader: "Latest Stage Actual Date"
+      },
+      enableResizing: true,
+      minSize: 100,
+      size: 160,
+    },
+    {
+      accessorKey: "latestRevision",
+      header: ({ column }) => (
+        <DataTableColumnHeaderSimple column={column} title="Latest Revision" />
+      ),
+      cell: ({ row }) => <div>{row.getValue("latestRevision")}</div>,
+      meta: {
+        excelHeader: "Latest Revision"
+      },
+      enableResizing: true,
+      minSize: 100,
+      size: 160,
+    },
+
+    {
+      accessorKey: "updatedAt",
+      header: ({ column }) => (
+        <DataTableColumnHeaderSimple column={column} title="Updated At" />
+      ),
+      cell: ({ cell }) => formatDateTime(cell.getValue() as Date),
+      meta: {
+        excelHeader: "updated At"
+      },
+      enableResizing: true,
+      minSize: 120,
+      size: 180,
+    },
+    // The "actions" column has been removed
+  ]
+}
\ No newline at end of file
-- 
cgit v1.2.3

