"use client" import * as React from "react" import { type DataTableRowAction } from "@/types/table" import { type ColumnDef } from "@tanstack/react-table" import { Ellipsis, Eye } from "lucide-react" import type { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime" import { formatDate } from "@/lib/utils" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { Checkbox } from "@/components/ui/checkbox" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header" import { type GtcDocumentWithRelations } from "@/db/schema/gtc" interface GetColumnsProps { setRowAction: React.Dispatch | null>> router: AppRouterInstance } /** GTC Documents 테이블 컬럼 정의 (그룹 헤더 제거) */ export function getColumns({ setRowAction, router }: GetColumnsProps): ColumnDef[] { const selectColumn: ColumnDef = { id: "select", header: ({ table }) => ( table.toggleAllPageRowsSelected(!!value)} aria-label="Select all" className="translate-y-0.5" /> ), cell: ({ row }) => ( row.toggleSelected(!!value)} aria-label="Select row" className="translate-y-0.5" /> ), size: 40, enableSorting: false, enableHiding: false, } const basicInfoColumns: ColumnDef[] = [ { accessorKey: "type", header: ({ column }) => , cell: ({ row }) => { const type = row.getValue("type") as string return ( {type === "standard" ? "표준" : "프로젝트"} ) }, size: 100, enableResizing: true, meta: { excelHeader: "구분" }, }, { accessorKey: "project", header: ({ column }) => , cell: ({ row }) => { const projectName = row.original.projectName const projectCode = row.original.projectCode if (!projectName) return - return (
{projectName} {projectCode}
) }, size: 200, enableResizing: true, meta: { excelHeader: "프로젝트" }, }, { accessorKey: "title", header: ({ column }) => , cell: ({ row }) => { const title = row.original.title if (!title) return - return (
{title}
) }, size: 200, enableResizing: true, meta: { excelHeader: "GTC 제목" }, }, { accessorKey: "revision", header: ({ column }) => , cell: ({ row }) => { const revision = row.getValue("revision") as number return v{revision} }, size: 80, enableResizing: true, meta: { excelHeader: "Rev." }, }, ] const auditColumns: ColumnDef[] = [ { accessorKey: "createdAt", header: ({ column }) => , cell: ({ row }) => { const date = row.getValue("createdAt") as Date return date ? formatDate(date, "KR") : "-" }, size: 120, enableResizing: true, meta: { excelHeader: "최초등록일" }, }, { accessorKey: "createdBy", header: ({ column }) => , cell: ({ row }) => { const createdBy = row.original.createdBy return createdBy ? {createdBy.name} : - }, size: 120, enableResizing: true, meta: { excelHeader: "최초등록자" }, }, { accessorKey: "updatedAt", header: ({ column }) => , cell: ({ row }) => { const date = row.getValue("updatedAt") as Date return date ? formatDate(date, "KR") : "-" }, size: 120, enableResizing: true, meta: { excelHeader: "최종수정일" }, }, { accessorKey: "updatedBy", header: ({ column }) => , cell: ({ row }) => { const updatedBy = row.original.updatedBy return updatedBy ? {updatedBy.name} : - }, size: 120, enableResizing: true, meta: { excelHeader: "최종수정자" }, }, { accessorKey: "editReason", header: ({ column }) => , cell: ({ row }) => { const reason = row.getValue("editReason") as string return reason ? ( {reason.length > 30 ? `${reason.substring(0, 30)}...` : reason} ) : ( - ) }, size: 200, enableResizing: true, meta: { excelHeader: "최종 편집사유" }, }, ] const actionsColumn: ColumnDef = { id: "actions", enableHiding: false, cell: ({ row }) => { const gtcDocument = row.original const handleViewDetails = () => { router.push(`/evcp/gtc/${gtcDocument.id}`) } const handleCreateNewRevision = () => { setRowAction({ row, type: "createRevision" }) } const handleClone = () => { setRowAction({ row, type: "clone" }) } return ( {/* */} 상세보기 setRowAction({ row, type: "update" })}> 수정하기 리비전 생성하기 복제하기 setRowAction({ row, type: "delete" })}> 삭제하기 {/* ⌘⌫ */} ) }, size: 40, } // 그룹 없이 평평한 배열 반환 return [ selectColumn, ...basicInfoColumns, ...auditColumns, actionsColumn, ] }