1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
"use client"
import * as React from "react"
import { useMemo } from "react"
import { ColumnDef } from "@tanstack/react-table"
import { formatDate } 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 {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuShortcut,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { Button } from "@/components/ui/button"
import { Ellipsis } from "lucide-react"
import { Badge } from "@/components/ui/badge"
import { PqCriterias } from "@/db/schema/pq"
import { toast } from "sonner"
interface GetColumnsProps {
setRowAction: React.Dispatch<React.SetStateAction<DataTableRowAction<PqCriterias> | null>>
pqListInfo?: Awaited<ReturnType<typeof import("../service").getPQListInfo>>
}
export function getColumns({
setRowAction,
pqListInfo,
}: GetColumnsProps): ColumnDef<PqCriterias>[] {
return [
{
id: "select",
header: ({ table }) => (
<Checkbox
checked={
table.getIsAllPageRowsSelected() ||
(table.getIsSomePageRowsSelected() && "indeterminate")
}
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
aria-label="Select all"
className="translate-y-0.5"
/>
),
cell: ({ row }) => (
<Checkbox
checked={row.getIsSelected()}
onCheckedChange={(value) => row.toggleSelected(!!value)}
aria-label="Select row"
className="translate-y-0.5"
/>
),
size:40,
enableSorting: false,
enableHiding: false,
},
{
accessorKey: "groupName",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="대분류" />
),
cell: ({ row }) => <div>{row.getValue("groupName")}</div>,
meta: {
excelHeader: "Group Name"
},
enableResizing: true,
minSize: 60,
size: 100,
},
{
accessorKey: "subGroupName",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="소분류" />
),
cell: ({ row }) => <div>{row.getValue("subGroupName") || "-"}</div>,
meta: {
excelHeader: "Sub Group Name"
},
enableResizing: true,
minSize: 60,
size: 100,
},
{
accessorKey: "code",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="일련번호" />
),
cell: ({ row }) => <div>{row.getValue("code")}</div>,
meta: {
excelHeader: "Code"
},
enableResizing: true,
minSize: 50,
size: 100,
},
{
accessorKey: "checkPoint",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="PQ 항목" />
),
cell: ({ row }) => <div>{row.getValue("checkPoint")}</div>,
meta: {
excelHeader: "Check Point"
},
enableResizing: true,
minSize: 180,
size: 180,
},
{
accessorKey: "description",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="설명" />
),
cell: ({ row }) => {
const text = row.getValue("description") as string
return (
<div style={{ whiteSpace: "pre-wrap" }}>
{text}
</div>
)
},
meta: {
excelHeader: "Description"
},
enableResizing: true,
minSize: 180,
size: 180,
},
{
accessorKey: "remarks",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="비고" />
),
cell: ({ row }) => {
const text = row.getValue("remarks") as string
return (
<div style={{ whiteSpace: "pre-wrap" }}>
{text || "-"}
</div>
)
},
meta: {
excelHeader: "Remarks"
},
enableResizing: true,
minSize: 180,
size: 180,
},
{
accessorKey: "inputFormat",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="협력업체 입력사항" />
),
cell: ({ row }) => {
const format = row.getValue("inputFormat") as string
const formatLabels = {
TEXT: "텍스트",
FILE: "파일",
EMAIL: "이메일",
PHONE: "전화번호",
NUMBER: "숫자",
"TEXT_FILE": "텍스트 + 파일"
}
return (
<Badge variant="outline">
{formatLabels[format as keyof typeof formatLabels] || format}
</Badge>
)
},
meta: {
excelHeader: "Input Format"
},
enableResizing: true,
minSize: 100,
size: 120,
},
{
accessorKey: "createdAt",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="생성일" />
),
cell: ({ cell }) => {
const dateValue = cell.getValue() as Date
return useMemo(() => formatDate(dateValue, "ko-KR"), [dateValue])
},
enableResizing: true,
minSize: 180,
size: 180,
},
{
accessorKey: "updatedAt",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="수정일" />
),
cell: ({ cell }) => {
const dateValue = cell.getValue() as Date
return useMemo(() => formatDate(dateValue, "ko-KR"), [dateValue])
},
enableResizing: true,
minSize: 180,
size: 180,
},
{
id: "actions",
enableHiding: false,
cell: function Cell({ row }) {
const isActive = pqListInfo?.success && pqListInfo.data.status === "ACTIVE";
const handleRestrictedAction = () => {
toast.error("활성화된 PQ 목록은 수정할 수 없습니다. 먼저 PQ 목록을 비활성화해주세요.");
};
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
aria-label="Open menu"
variant="ghost"
className="flex size-7 p-0 data-[state=open]:bg-muted"
>
<Ellipsis className="size-4" aria-hidden="true" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-40">
{isActive ? (
<DropdownMenuItem
onSelect={handleRestrictedAction}
className="text-muted-foreground"
>
Edit
</DropdownMenuItem>
) : (
<DropdownMenuItem
onSelect={() => setRowAction({ row, type: "update" })}
>
Edit
</DropdownMenuItem>
)}
{isActive ? (
<DropdownMenuItem
onSelect={handleRestrictedAction}
className="text-muted-foreground"
>
Delete
<DropdownMenuShortcut>⌘⌫</DropdownMenuShortcut>
</DropdownMenuItem>
) : (
<DropdownMenuItem
onSelect={() => setRowAction({ row, type: "delete" })}
>
Delete
<DropdownMenuShortcut>⌘⌫</DropdownMenuShortcut>
</DropdownMenuItem>
)}
</DropdownMenuContent>
</DropdownMenu>
)
},
size: 40,
}
]
}
|