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
|
// lib/techsales-rfq/vendor-response/table/vendor-quotations-table.tsx
"use client"
import * as React from "react"
import { type DataTableAdvancedFilterField, type DataTableFilterField } from "@/types/table"
import { useDataTable } from "@/hooks/use-data-table"
import { DataTable } from "@/components/data-table/data-table"
import { DataTableAdvancedToolbar } from "@/components/data-table/data-table-advanced-toolbar"
import { TechSalesVendorQuotations, TECH_SALES_QUOTATION_STATUSES, TECH_SALES_QUOTATION_STATUS_CONFIG } from "@/db/schema"
import { useRouter } from "next/navigation"
import { getColumns } from "./vendor-quotations-table-columns"
interface QuotationWithRfqCode extends TechSalesVendorQuotations {
rfqCode?: string;
materialCode?: string;
dueDate?: Date;
rfqStatus?: string;
itemName?: string;
projNm?: string;
quotationCode?: string | null;
quotationVersion?: number | null;
rejectionReason?: string | null;
acceptedAt?: Date | null;
}
interface VendorQuotationsTableProps {
promises: Promise<[{ data: any[], pageCount: number, total?: number }]>;
}
export function VendorQuotationsTable({ promises }: VendorQuotationsTableProps) {
// TODO: 안정화 이후 삭제
console.log("렌더링 사이클 점검용 로그: VendorQuotationsTable 렌더링됨");
const [{ data, pageCount }] = React.use(promises);
const router = useRouter();
// 데이터 안정성을 위한 메모이제이션 - 핵심 속성만 비교
const stableData = React.useMemo(() => {
return data;
}, [data.length, data.map(item => `${item.id}-${item.status}-${item.updatedAt}`).join(',')]);
// 테이블 컬럼 정의 - router는 안정적이므로 한 번만 생성
const columns = React.useMemo(() => getColumns({
router,
}), [router]);
// 필터 필드 - 중앙화된 상태 상수 사용
const filterFields = React.useMemo<DataTableFilterField<QuotationWithRfqCode>[]>(() => [
{
id: "status",
label: "상태",
options: Object.entries(TECH_SALES_QUOTATION_STATUSES).map(([, statusValue]) => ({
label: TECH_SALES_QUOTATION_STATUS_CONFIG[statusValue].label,
value: statusValue,
}))
},
{
id: "rfqCode",
label: "RFQ 번호",
placeholder: "RFQ 번호 검색...",
},
{
id: "materialCode",
label: "자재 코드",
placeholder: "자재 코드 검색...",
}
], []);
// 고급 필터 필드 - 중앙화된 상태 상수 사용
const advancedFilterFields = React.useMemo<DataTableAdvancedFilterField<QuotationWithRfqCode>[]>(() => [
{
id: "rfqCode",
label: "RFQ 번호",
type: "text",
},
{
id: "materialCode",
label: "자재 코드",
type: "text",
},
{
id: "status",
label: "상태",
type: "multi-select",
options: Object.entries(TECH_SALES_QUOTATION_STATUSES).map(([, statusValue]) => ({
label: TECH_SALES_QUOTATION_STATUS_CONFIG[statusValue].label,
value: statusValue,
})),
},
{
id: "validUntil",
label: "유효기간",
type: "date",
},
{
id: "submittedAt",
label: "제출일",
type: "date",
},
], []);
// useDataTable 훅 사용
const { table } = useDataTable({
data: stableData,
columns,
pageCount,
filterFields,
enablePinning: true,
enableAdvancedFilter: true,
enableColumnResizing: true,
columnResizeMode: 'onChange',
initialState: {
sorting: [{ id: "updatedAt", desc: true }],
columnPinning: { right: ["actions"] },
},
getRowId: (originalRow) => String(originalRow.id),
shallow: false,
clearOnDefault: true,
defaultColumn: {
minSize: 50,
maxSize: 500,
},
});
return (
<div className="w-full">
<div className="overflow-x-auto">
<DataTable
table={table}
className="min-w-full"
>
<DataTableAdvancedToolbar
table={table}
filterFields={advancedFilterFields}
shallow={false}
>
</DataTableAdvancedToolbar>
</DataTable>
</div>
</div>
);
}
|