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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
|
import { Checkbox } from "@/components/ui/checkbox"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { Edit, Trash2 } from "lucide-react"
import { type ColumnDef, TableMeta } from "@tanstack/react-table"
import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header"
import { EditableCell } from "@/components/data-table/editable-cell"
// 수정 여부 확인 헬퍼 함수
const getIsModified = (table: any, rowId: string, fieldName: string) => {
const pendingChanges = table.options.meta?.getPendingChanges?.() || {}
return String(rowId) in pendingChanges && fieldName in pendingChanges[String(rowId)]
}
// 테이블 메타 타입 확장
declare module "@tanstack/react-table" {
interface TableMeta<TData> {
onCellUpdate?: (id: string, field: keyof TData, newValue: any) => Promise<void>
onCellCancel?: (id: string, field: keyof TData) => void
onAction?: (action: string, data?: any) => void
onSaveEmptyRow?: (tempId: string) => Promise<void>
onCancelEmptyRow?: (tempId: string) => void
isEmptyRow?: (id: string) => boolean
}
}
// AVL 상세 아이템 타입
export type AvlDetailItem = {
id: string
no: number
selected: boolean
// AVL 리스트 ID (외래키)
avlListId: number
// 설계 정보
equipBulkDivision: 'EQUIP' | 'BULK'
disciplineCode: string
disciplineName: string
// 자재 정보
materialNameCustomerSide: string
packageCode: string
packageName: string
materialGroupCode: string
materialGroupName: string
// 협력업체 정보
vendorId?: number
vendorName: string
vendorCode: string
avlVendorName: string
tier: string
// FA 정보
faTarget: boolean
faStatus: string
// Agent 정보
isAgent: boolean
agentStatus: string // UI 표시용
// 계약 서명주체
contractSignerId?: number
contractSignerName: string
contractSignerCode: string
// 위치 정보
headquarterLocation: string
manufacturingLocation: string
// SHI Qualification
shiAvl: boolean
shiBlacklist: boolean
shiBcc: boolean
// 기술영업 견적결과
salesQuoteNumber: string
quoteCode: string
salesVendorInfo: string
salesCountry: string
totalAmount: string
quoteReceivedDate: string
// 업체 실적 현황(구매)
recentQuoteDate: string
recentQuoteNumber: string
recentOrderDate: string
recentOrderNumber: string
// 기타
remarks: string
// 타임스탬프
createdAt: string
updatedAt: string
}
// 테이블 컬럼 정의
export const columns: ColumnDef<AvlDetailItem>[] = [
// 기본 정보 그룹
{
header: "기본 정보",
columns: [
{
id: "select",
header: ({ table }) => (
<Checkbox
checked={
table.getIsAllPageRowsSelected() ||
(table.getIsSomePageRowsSelected() && "indeterminate")
}
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
aria-label="Select all"
/>
),
cell: ({ row }) => (
<Checkbox
checked={row.getIsSelected()}
onCheckedChange={(value) => row.toggleSelected(!!value)}
aria-label="Select row"
/>
),
enableSorting: false,
enableHiding: false,
size: 50,
},
{
accessorKey: "no",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="No." />
),
size: 60,
},
{
accessorKey: "equipBulkDivision",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="Equip/Bulk 구분" />
),
cell: ({ row, table }) => {
const value = row.getValue("equipBulkDivision") as string
const isEmptyRow = String(row.original.id).startsWith('temp-')
const onSave = async (newValue: any) => {
if (table.options.meta?.onCellUpdate) {
await table.options.meta.onCellUpdate(row.original.id, "equipBulkDivision", newValue)
}
}
const isModified = getIsModified(table, row.original.id, "equipBulkDivision")
return (
<EditableCell
value={value}
type="select"
onSave={onSave}
options={[
{ label: "EQUIP", value: "EQUIP" },
{ label: "BULK", value: "BULK" }
]}
placeholder="구분 선택"
autoSave={true}
disabled={false}
initialEditMode={isEmptyRow}
isModified={isModified}
/>
)
},
size: 120,
},
{
accessorKey: "disciplineName",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="설계공종" />
),
cell: ({ row, table }) => {
const value = row.getValue("disciplineName")
const isEmptyRow = String(row.original.id).startsWith('temp-')
const onSave = async (newValue: any) => {
if (table.options.meta?.onCellUpdate) {
await table.options.meta.onCellUpdate(row.original.id, "disciplineName", newValue)
}
}
const isModified = getIsModified(table, row.original.id, "disciplineName")
return (
<EditableCell
value={value}
type="text"
onSave={onSave}
placeholder="설계공종 입력"
maxLength={50}
autoSave={true}
disabled={false}
initialEditMode={isEmptyRow}
isModified={isModified}
/>
)
},
size: 120,
},
{
accessorKey: "materialNameCustomerSide",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="고객사 AVL 자재명" />
),
cell: ({ row, table }) => {
const value = row.getValue("materialNameCustomerSide")
const isEmptyRow = String(row.original.id).startsWith('temp-')
const onSave = async (newValue: any) => {
if (table.options.meta?.onCellUpdate) {
await table.options.meta.onCellUpdate(row.original.id, "materialNameCustomerSide", newValue)
}
}
const isModified = getIsModified(table, row.original.id, "materialNameCustomerSide")
return (
<EditableCell
value={value}
type="text"
onSave={onSave}
placeholder="자재명 입력"
maxLength={100}
autoSave={true}
disabled={false}
initialEditMode={isEmptyRow}
isModified={isModified}
/>
)
},
size: 150,
},
{
accessorKey: "packageName",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="패키지 정보" />
),
cell: ({ row, table }) => {
const value = row.getValue("packageName")
const isEmptyRow = String(row.original.id).startsWith('temp-')
const onSave = async (newValue: any) => {
if (table.options.meta?.onCellUpdate) {
await table.options.meta.onCellUpdate(row.original.id, "packageName", newValue)
}
}
const isModified = getIsModified(table, row.original.id, "packageName")
return (
<EditableCell
value={value}
type="text"
onSave={onSave}
placeholder="패키지명 입력"
maxLength={100}
autoSave={true}
disabled={false}
initialEditMode={isEmptyRow}
isModified={isModified}
/>
)
},
size: 130,
},
{
accessorKey: "materialGroupCode",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="자재그룹코드" />
),
cell: ({ row, table }) => {
const value = row.getValue("materialGroupCode")
const isEmptyRow = String(row.original.id).startsWith('temp-')
const onSave = async (newValue: any) => {
if (table.options.meta?.onCellUpdate) {
await table.options.meta.onCellUpdate(row.original.id, "materialGroupCode", newValue)
}
}
const isModified = getIsModified(table, row.original.id, "materialGroupCode")
return (
<EditableCell
value={value}
type="text"
onSave={onSave}
placeholder="자재그룹코드 입력"
maxLength={50}
autoSave={true}
disabled={false}
initialEditMode={isEmptyRow}
isModified={isModified}
/>
)
},
size: 120,
},
{
accessorKey: "materialGroupName",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="자재그룹명" />
),
cell: ({ row, table }) => {
const value = row.getValue("materialGroupName")
const isEmptyRow = String(row.original.id).startsWith('temp-')
const onSave = async (newValue: any) => {
if (table.options.meta?.onCellUpdate) {
await table.options.meta.onCellUpdate(row.original.id, "materialGroupName", newValue)
}
}
const isModified = getIsModified(table, row.original.id, "materialGroupName")
return (
<EditableCell
value={value}
type="text"
onSave={onSave}
placeholder="자재그룹명 입력"
maxLength={100}
autoSave={true}
disabled={false}
initialEditMode={isEmptyRow}
isModified={isModified}
/>
)
},
size: 130,
},
{
accessorKey: "vendorCode",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="협력업체코드" />
),
cell: ({ row, table }) => {
const value = row.getValue("vendorCode")
const isEmptyRow = String(row.original.id).startsWith('temp-')
const onSave = async (newValue: any) => {
if (table.options.meta?.onCellUpdate) {
await table.options.meta.onCellUpdate(row.original.id, "vendorCode", newValue)
}
}
const isModified = getIsModified(table, row.original.id, "vendorCode")
return (
<EditableCell
value={value}
type="text"
onSave={onSave}
placeholder="협력업체코드 입력"
maxLength={50}
autoSave={true}
disabled={false}
initialEditMode={isEmptyRow}
isModified={isModified}
/>
)
},
size: 120,
},
{
accessorKey: "vendorName",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="협력업체명" />
),
cell: ({ row, table }) => {
const value = row.getValue("vendorName")
const isEmptyRow = String(row.original.id).startsWith('temp-')
const onSave = async (newValue: any) => {
if (table.options.meta?.onCellUpdate) {
await table.options.meta.onCellUpdate(row.original.id, "vendorName", newValue)
}
}
const isModified = getIsModified(table, row.original.id, "vendorName")
return (
<EditableCell
value={value}
type="text"
onSave={onSave}
placeholder="협력업체명 입력"
maxLength={100}
autoSave={true}
disabled={false}
initialEditMode={isEmptyRow}
isModified={isModified}
/>
)
},
size: 140,
},
{
accessorKey: "avlVendorName",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="AVL 등재업체명" />
),
cell: ({ row, table }) => {
const value = row.getValue("avlVendorName")
const isEmptyRow = String(row.original.id).startsWith('temp-')
const onSave = async (newValue: any) => {
if (table.options.meta?.onCellUpdate) {
await table.options.meta.onCellUpdate(row.original.id, "avlVendorName", newValue)
}
}
const isModified = getIsModified(table, row.original.id, "avlVendorName")
return (
<EditableCell
value={value}
type="text"
onSave={onSave}
placeholder="AVL 등재업체명 입력"
maxLength={100}
autoSave={true}
disabled={false}
initialEditMode={isEmptyRow}
isModified={isModified}
/>
)
},
size: 140,
},
{
accessorKey: "tier",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="등급 (Tier)" />
),
cell: ({ row, table }) => {
const value = row.getValue("tier") as string
const isEmptyRow = String(row.original.id).startsWith('temp-')
const onSave = async (newValue: any) => {
if (table.options.meta?.onCellUpdate) {
await table.options.meta.onCellUpdate(row.original.id, "tier", newValue)
}
}
const isModified = getIsModified(table, row.original.id, "tier")
return (
<EditableCell
value={value}
type="select"
onSave={onSave}
options={[
{ label: "Tier 1", value: "Tier 1" },
{ label: "Tier 2", value: "Tier 2" },
{ label: "Tier 3", value: "Tier 3" }
]}
placeholder="등급 선택"
autoSave={true}
disabled={false}
initialEditMode={isEmptyRow}
isModified={isModified}
/>
)
},
size: 100,
},
],
},
// FA 정보 그룹
{
header: "FA 정보",
columns: [
{
accessorKey: "faTarget",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="FA 대상" />
),
cell: ({ row, table }) => {
const value = row.getValue("faTarget") as boolean
const isEmptyRow = String(row.original.id).startsWith('temp-')
const onSave = async (newValue: any) => {
if (table.options.meta?.onCellUpdate) {
await table.options.meta.onCellUpdate(row.original.id, "faTarget", newValue)
}
}
const isModified = getIsModified(table, row.original.id, "faTarget")
return (
<EditableCell
value={value}
type="checkbox"
onSave={onSave}
autoSave={true}
disabled={false}
initialEditMode={isEmptyRow}
isModified={isModified}
/>
)
},
size: 80,
},
{
accessorKey: "faStatus",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="FA 현황" />
),
cell: ({ row, table }) => {
const value = row.getValue("faStatus")
const isEmptyRow = String(row.original.id).startsWith('temp-')
const onSave = async (newValue: any) => {
if (table.options.meta?.onCellUpdate) {
await table.options.meta.onCellUpdate(row.original.id, "faStatus", newValue)
}
}
const isModified = getIsModified(table, row.original.id, "faStatus")
return (
<EditableCell
value={value}
type="text"
onSave={onSave}
placeholder="FA 현황 입력"
maxLength={50}
autoSave={true}
disabled={false}
initialEditMode={isEmptyRow}
isModified={isModified}
/>
)
},
size: 100,
},
],
},
// SHI Qualification 그룹
{
header: "SHI Qualification",
columns: [
{
accessorKey: "shiAvl",
header: "AVL",
cell: ({ row, table }) => {
const value = row.getValue("shiAvl") as boolean
const isEmptyRow = String(row.original.id).startsWith('temp-')
const onSave = async (newValue: any) => {
if (table.options.meta?.onCellUpdate) {
await table.options.meta.onCellUpdate(row.original.id, "shiAvl", newValue)
}
}
const isModified = getIsModified(table, row.original.id, "shiAvl")
return (
<EditableCell
value={value}
type="checkbox"
onSave={onSave}
autoSave={true}
disabled={false}
initialEditMode={isEmptyRow}
isModified={isModified}
/>
)
},
size: 80,
},
{
accessorKey: "shiBlacklist",
header: "Blacklist",
cell: ({ row, table }) => {
const value = row.getValue("shiBlacklist") as boolean
const isEmptyRow = String(row.original.id).startsWith('temp-')
const onSave = async (newValue: any) => {
if (table.options.meta?.onCellUpdate) {
await table.options.meta.onCellUpdate(row.original.id, "shiBlacklist", newValue)
}
}
const isModified = getIsModified(table, row.original.id, "shiBlacklist")
return (
<EditableCell
value={value}
type="checkbox"
onSave={onSave}
autoSave={true}
disabled={false}
initialEditMode={isEmptyRow}
isModified={isModified}
/>
)
},
size: 100,
},
{
accessorKey: "shiBcc",
header: "BCC",
cell: ({ row, table }) => {
const value = row.getValue("shiBcc") as boolean
const isEmptyRow = String(row.original.id).startsWith('temp-')
const onSave = async (newValue: any) => {
if (table.options.meta?.onCellUpdate) {
await table.options.meta.onCellUpdate(row.original.id, "shiBcc", newValue)
}
}
const isModified = getIsModified(table, row.original.id, "shiBcc")
return (
<EditableCell
value={value}
type="checkbox"
onSave={onSave}
autoSave={true}
disabled={false}
initialEditMode={isEmptyRow}
isModified={isModified}
/>
)
},
size: 80,
},
],
},
// 액션 컬럼
{
id: "actions",
header: "액션",
cell: ({ row, table }) => {
const isEmptyRow = String(row.original.id).startsWith('temp-')
return (
<div className="flex items-center gap-2">
{!isEmptyRow && (
<>
<Button
variant="ghost"
size="sm"
onClick={() => table.options.meta?.onAction?.('edit', row.original)}
className="h-8 w-8 p-0"
>
<Edit className="h-4 w-4" />
</Button>
<Button
variant="ghost"
size="sm"
onClick={() => table.options.meta?.onAction?.('delete', row.original)}
className="h-8 w-8 p-0 text-destructive hover:text-destructive"
>
<Trash2 className="h-4 w-4" />
</Button>
</>
)}
{isEmptyRow && (
<>
<Button
variant="ghost"
size="sm"
onClick={() => table.options.meta?.onSaveEmptyRow?.(row.original.id)}
className="h-8 w-8 p-0"
>
저장
</Button>
<Button
variant="ghost"
size="sm"
onClick={() => table.options.meta?.onCancelEmptyRow?.(row.original.id)}
className="h-8 w-8 p-0"
>
취소
</Button>
</>
)}
</div>
)
},
size: 100,
enableSorting: false,
enableHiding: false,
},
]
|