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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
"use client"
import * as React from "react"
import { type ColumnDef } from "@tanstack/react-table"
import {
Ellipsis, FileText, Download, Eye,
MessageSquare, Upload
} from "lucide-react"
import { formatDate, formatBytes } 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, DropdownMenuTrigger
} from "@/components/ui/dropdown-menu"
import { Progress } from "@/components/ui/progress"
import { RevisionDialog } from "./revision-dialog"
import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header"
import { AddRevisionDialog } from "./add-revision-dialog"
interface GetAttachmentColumnsProps {
onSelectAttachment: (attachment: any) => void
}
export function getAttachmentColumns({
onSelectAttachment
}: GetAttachmentColumnsProps): ColumnDef<any>[] {
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: "serialNo",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="시리얼 번호" />
),
cell: ({ row }) => (
<Button
variant="link"
className="p-0 h-auto font-medium text-blue-600 hover:text-blue-800"
onClick={() => onSelectAttachment(row.original)}
>
{row.getValue("serialNo") as string}
</Button>
),
size: 100,
},
{
accessorKey: "attachmentType",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="문서 타입" />
),
cell: ({ row }) => {
const type = row.getValue("attachmentType") as string
return (
<Badge variant={type === "구매" ? "default" : "secondary"}>
{type}
</Badge>
)
},
size:100
},
{
accessorKey: "originalFileName",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="파일명" />
),
cell: ({ row }) => {
const fileName = row.getValue("originalFileName") as string
return (
<div className="flex items-center gap-2">
<FileText className="h-4 w-4 text-muted-foreground" />
<div className="min-w-0 flex-1">
<div className="truncate font-medium" title={fileName}>
{fileName}
</div>
</div>
</div>
)
},
size:250
},
{
id: "currentRevision",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="리비전" />
),
cell: ({ row }) => (
<RevisionDialog
attachmentId={row.original.id}
currentRevision={row.original.currentRevision}
originalFileName={row.original.originalFileName}
/>
),
size: 100,
},
{
accessorKey: "description",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="설명" />
),
cell: ({ row }) => {
const description = row.getValue("description") as string
return description
? <div className="max-w-[200px] truncate" title={description}>{description}</div>
: <span className="text-muted-foreground">-</span>
},
},
/** ───────────── 파일 정보 ───────────── */
// {
// accessorKey: "fileSize",
// header: ({ column }) => (
// <DataTableColumnHeaderSimple column={column} title="파일 크기" />
// ),
// cell: ({ row }) => {
// const size = row.getValue("fileSize") as number
// return size ? formatBytes(size) : "-"
// },
// },
{
accessorKey: "createdAt",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="등록일" />
),
cell: ({ row }) => {
const created = row.getValue("createdAt") as Date
const updated = row.original.updatedAt as Date
return (
<div>
<div>{formatDate(created, "KR")}</div>
<div className="text-xs text-muted-foreground">
{row.original.createdByName}
</div>
{updated && new Date(updated) > new Date(created) && (
<div className="text-xs text-blue-600">
수정: {formatDate(updated, "KR")}
</div>
)}
</div>
)
},
maxSize:150
},
/** ───────────── 벤더 응답 현황 ───────────── */
{
id: "vendorCount",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="벤더 수" />
),
cell: ({ row }) => {
const stats = row.original.responseStats
return stats
? (
<div className="text-center">
<div className="font-medium">{stats.totalVendors}</div>
<div className="text-xs text-muted-foreground">
활성: {stats.totalVendors - stats.waivedCount}
</div>
</div>
)
: <span className="text-muted-foreground">-</span>
},
},
{
id: "responseStatus",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="응답 현황" />
),
cell: ({ row }) => {
const stats = row.original.responseStats
return stats
? (
<div className="space-y-1">
<div className="flex items-center gap-2">
<div className="flex-1">
<Progress value={stats.responseRate} className="h-2" />
</div>
<span className="text-sm font-medium">
{stats.responseRate}%
</span>
</div>
<div className="flex gap-2 text-xs">
<span className="text-green-600">
응답: {stats.respondedCount}
</span>
<span className="text-orange-600">
대기: {stats.pendingCount}
</span>
{stats.waivedCount > 0 && (
<span className="text-gray-500">
면제: {stats.waivedCount}
</span>
)}
</div>
</div>
)
: <span className="text-muted-foreground">-</span>
},
},
/** ───────────── 액션 ───────────── */
{
id: "actions",
enableHiding: false,
cell: ({ row }) => {
const [isAddRevisionOpen, setIsAddRevisionOpen] = React.useState(false)
return (
<>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
aria-label="Open menu"
variant="ghost"
className="flex size-8 p-0 data-[state=open]:bg-muted"
>
<Ellipsis className="size-4" aria-hidden="true" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-48">
<DropdownMenuItem onClick={() => onSelectAttachment(row.original)}>
<MessageSquare className="mr-2 h-4 w-4" />
벤더 응답 보기
</DropdownMenuItem>
<DropdownMenuItem
onClick={() => row.original.filePath && window.open(row.original.filePath, "_blank")}
>
<Download className="mr-2 h-4 w-4" />
다운로드
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem onClick={() => setIsAddRevisionOpen(true)}>
<Upload className="mr-2 h-4 w-4" />
새 리비전 추가
</DropdownMenuItem>
<DropdownMenuItem className="text-red-600">
삭제
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
<AddRevisionDialog
open={isAddRevisionOpen}
onOpenChange={setIsAddRevisionOpen}
attachmentId={row.original.id}
currentRevision={row.original.currentRevision}
originalFileName={row.original.originalFileName}
onSuccess={() => window.location.reload()}
/>
</>
)
},
size: 40,
},
]
}
|