"use client" import * as React from "react" import { type DataTableRowAction } from "@/types/table" import { type ColumnDef } from "@tanstack/react-table" import { Ellipsis, InfoIcon, PenToolIcon, TrashIcon } from "lucide-react" import { formatDate } from "@/lib/utils" import { Button } from "@/components/ui/button" import { Checkbox } from "@/components/ui/checkbox" import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "@/components/ui/tooltip" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" import { Badge } from "@/components/ui/badge" import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header" import { EsgEvaluationsView } from "@/db/schema" interface GetColumnsProps { setRowAction: React.Dispatch | null>> } /** * ESG 평가표 테이블 컬럼 정의 */ export function getColumns({ setRowAction }: GetColumnsProps): ColumnDef[] { // ---------------------------------------------------------------- // 1) select 컬럼 (체크박스) // ---------------------------------------------------------------- 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" /> ), enableSorting: false, enableHiding: false, size: 40, } // ---------------------------------------------------------------- // 2) 기본 정보 컬럼들 // ---------------------------------------------------------------- const basicColumns: ColumnDef[] = [ { accessorKey: "serialNumber", header: ({ column }) => ( ), cell: ({ row }) => (
{row.getValue("serialNumber")}
), enableSorting: true, enableHiding: true, }, { accessorKey: "category", header: ({ column }) => ( ), cell: ({ row }) => ( {row.getValue("category")} ), }, { accessorKey: "inspectionItem", header: ({ column }) => ( ), cell: ({ row }) => (
{row.getValue("inspectionItem")}
), }, ] // ---------------------------------------------------------------- // 3) 통계 정보 컬럼들 // ---------------------------------------------------------------- const statsColumns: ColumnDef[] = [ { id: "evaluationItems", header: ({ column }) => ( ), cell: ({ row }) => { const evaluation = row.original; const count = evaluation.totalEvaluationItems || 0; // evaluationItemsList가 있다면 사용, 없다면 개수만 표시 const items = (evaluation as any).evaluationItemsList || []; if (items.length > 0) { return (
{items.slice(0, 3).map((item: string, index: number) => ( {item.length > 15 ? `${item.substring(0, 15)}...` : item} ))} {items.length > 3 && ( +{items.length - 3}개 더 )}

평가항목 목록:

{items.map((item: string, index: number) => (

{index + 1}. {item}

))}
); } // 평가항목이 없는 경우 return (
{count > 0 ? `${count}개 항목` : "항목 없음"}
); }, enableSorting: false, }, { accessorKey: "totalAnswerOptions", header: ({ column }) => ( ), cell: ({ row }) => (
{row.getValue("totalAnswerOptions") || 0}개
), }, ] // ---------------------------------------------------------------- // 4) 메타데이터 컬럼들 // ---------------------------------------------------------------- const metaColumns: ColumnDef[] = [ { accessorKey: "isActive", header: ({ column }) => ( ), cell: ({ row }) => ( {row.getValue("isActive") ? "활성" : "비활성"} ), }, { accessorKey: "createdAt", header: ({ column }) => ( ), cell: ({ row }) => { const date = row.getValue("createdAt") as Date return formatDate(date, "KR") }, }, { accessorKey: "updatedAt", header: ({ column }) => ( ), cell: ({ row }) => { const date = row.getValue("updatedAt") as Date return formatDate(date, "KR") }, }, ] // ---------------------------------------------------------------- // 5) actions 컬럼 (드롭다운 메뉴) // ---------------------------------------------------------------- const actionsColumn: ColumnDef = { id: "actions", header: "작업", enableHiding: false, cell: function Cell({ row }) { return ( setRowAction({ row, type: "view" })} > {/* */} 상세보기 setRowAction({ row, type: "update" })} > {/* */} 수정하기 setRowAction({ row, type: "delete" })} > {/* */} 삭제하기 ⌘⌫ ) }, size: 80, } // ---------------------------------------------------------------- // 6) 최종 컬럼 배열 (그룹화 버전) // ---------------------------------------------------------------- return [ selectColumn, { id: "basicInfo", header: "기본 정보", columns: basicColumns, }, { id: "statistics", header: "통계", columns: statsColumns, }, { id: "metadata", header: "메타데이터", columns: metaColumns, }, actionsColumn, ] } // ---------------------------------------------------------------- // 7) 컬럼 설정 (필터링용) // ---------------------------------------------------------------- export const esgEvaluationsColumnsConfig = [ { id: "serialNumber", label: "시리얼번호", group: "기본 정보", type: "text", excelHeader: "Serial Number", }, { id: "category", label: "분류", group: "기본 정보", type: "text", excelHeader: "Category", }, { id: "inspectionItem", label: "점검항목", group: "기본 정보", type: "text", excelHeader: "Inspection Item", }, { id: "totalEvaluationItems", label: "평가항목 수", group: "통계", type: "number", excelHeader: "Total Evaluation Items", }, { id: "totalAnswerOptions", label: "답변옵션 수", group: "통계", type: "number", excelHeader: "Total Answer Options", }, // { // id: "maxPossibleScore", // label: "최대점수", // group: "통계", // type: "number", // excelHeader: "Max Possible Score", // }, { id: "isActive", label: "상태", group: "메타데이터", type: "boolean", excelHeader: "Is Active", }, { id: "createdAt", label: "생성일", group: "메타데이터", type: "date", excelHeader: "Created At", }, { id: "updatedAt", label: "수정일", group: "메타데이터", type: "date", excelHeader: "Updated At", }, ] as const;