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
|
"use client"
import * as React from "react"
import { useReactTable, getCoreRowModel, getPaginationRowModel, getSortedRowModel, getFilteredRowModel, type ColumnDef } from "@tanstack/react-table"
import { DataTable } from "@/components/data-table/data-table"
import { Button } from "@/components/ui/button"
import { Checkbox } from "@/components/ui/checkbox"
import { getStandardAvlVendorInfo } from "../service"
import { GetStandardAvlSchema } from "../validations"
import { AvlDetailItem } from "../types"
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select"
import { Search } from "lucide-react"
import { toast } from "sonner"
// 검색 옵션들
const constructionSectorOptions = [
{ value: "all", label: "전체" },
{ value: "조선", label: "조선" },
{ value: "해양", label: "해양" },
]
const shipTypeOptions = [
{ value: "all", label: "전체" },
{ value: "컨테이너선", label: "컨테이너선" },
{ value: "유조선", label: "유조선" },
{ value: "LNG선", label: "LNG선" },
{ value: "LPG선", label: "LPG선" },
{ value: "벌크선", label: "벌크선" },
{ value: "여객선", label: "여객선" },
]
const avlKindOptions = [
{ value: "all", label: "전체" },
{ value: "표준", label: "표준" },
{ value: "특별", label: "특별" },
{ value: "임시", label: "임시" },
]
const htDivisionOptions = [
{ value: "all", label: "전체" },
{ value: "H", label: "Hull (H)" },
{ value: "T", label: "Topside (T)" },
]
// 선종별 표준 AVL 테이블에서는 AvlDetailItem을 사용
export type StandardAvlItem = AvlDetailItem
interface StandardAvlTableProps {
onSelectionChange?: (count: number) => void
resetCounter?: number
constructionSector?: string // 공사부문 필터
shipType?: string // 선종 필터
avlKind?: string // AVL 종류 필터
htDivision?: string // H/T 구분 필터
}
// 선종별 표준 AVL 테이블 컬럼
const standardAvlColumns: ColumnDef<StandardAvlItem>[] = [
{
id: "select",
header: ({ table }) => (
<Checkbox
checked={
table.getIsAllPageRowsSelected() ||
(table.getIsSomePageRowsSelected() && "indeterminate")
}
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
aria-label="Select all"
/>
),
cell: ({ row, table }) => {
// 선종별 표준 AVL 테이블의 단일 선택 핸들러
const handleRowSelection = (checked: boolean) => {
if (checked) {
// 다른 모든 행의 선택 해제
table.getRowModel().rows.forEach(r => {
if (r !== row && r.getIsSelected()) {
r.toggleSelected(false)
}
})
}
// 현재 행 선택/해제
row.toggleSelected(checked)
}
return (
<Checkbox
checked={row.getIsSelected()}
onCheckedChange={handleRowSelection}
aria-label="Select row"
/>
)
},
enableSorting: false,
enableHiding: false,
size: 50,
},
{
accessorKey: "no",
header: "No.",
size: 60,
},
{
accessorKey: "disciplineName",
header: "설계공종",
size: 120,
},
{
accessorKey: "avlVendorName",
header: "AVL 등재업체명",
size: 140,
},
{
accessorKey: "materialGroupCode",
header: "자재그룹 코드",
size: 120,
},
{
accessorKey: "materialGroupName",
header: "자재그룹 명",
size: 130,
},
{
accessorKey: "vendorCode",
header: "협력업체 코드",
size: 120,
},
{
accessorKey: "vendorName",
header: "협력업체 명",
size: 130,
},
{
accessorKey: "headquarterLocation",
header: "본사 위치 (국가)",
size: 140,
},
{
accessorKey: "tier",
header: "등급 (Tier)",
size: 120,
},
]
export function StandardAvlTable({
onSelectionChange,
resetCounter,
constructionSector: initialConstructionSector,
shipType: initialShipType,
avlKind: initialAvlKind,
htDivision: initialHtDivision
}: StandardAvlTableProps) {
const [data, setData] = React.useState<StandardAvlItem[]>([])
const [loading, setLoading] = React.useState(false)
const [pageCount, setPageCount] = React.useState(0)
// 검색 상태
const [searchConstructionSector, setSearchConstructionSector] = React.useState(initialConstructionSector || "all")
const [searchShipType, setSearchShipType] = React.useState(initialShipType || "all")
const [searchAvlKind, setSearchAvlKind] = React.useState(initialAvlKind || "all")
const [searchHtDivision, setSearchHtDivision] = React.useState(initialHtDivision || "all")
// 데이터 로드 함수
const loadData = React.useCallback(async (searchParams: Partial<GetStandardAvlSchema>) => {
try {
setLoading(true)
const params: GetStandardAvlSchema = {
page: searchParams.page ?? 1,
perPage: searchParams.perPage ?? 10,
sort: searchParams.sort ?? [{ id: "no", desc: false }],
constructionSector: searchConstructionSector === "all" ? "" : searchConstructionSector || "",
shipType: searchShipType === "all" ? "" : searchShipType || "",
avlKind: searchAvlKind === "all" ? "" : searchAvlKind || "",
htDivision: searchHtDivision === "all" ? "" : searchHtDivision || "",
search: "",
...searchParams,
}
const result = await getStandardAvlVendorInfo(params)
setData(result.data)
setPageCount(result.pageCount)
} catch (error) {
console.error("선종별 표준 AVL 데이터 로드 실패:", error)
setData([])
setPageCount(0)
} finally {
setLoading(false)
}
}, [searchConstructionSector, searchShipType, searchAvlKind, searchHtDivision])
// 검색 핸들러
const handleSearch = React.useCallback(() => {
loadData({})
}, [loadData])
// 검색 초기화 핸들러
const handleResetSearch = React.useCallback(() => {
setSearchConstructionSector("all")
setSearchShipType("all")
setSearchAvlKind("all")
setSearchHtDivision("all")
loadData({})
}, [loadData])
// 초기 데이터 로드
React.useEffect(() => {
loadData({})
}, [loadData])
const table = useReactTable({
data,
columns: standardAvlColumns,
getCoreRowModel: getCoreRowModel(),
getPaginationRowModel: getPaginationRowModel(),
getSortedRowModel: getSortedRowModel(),
getFilteredRowModel: getFilteredRowModel(),
manualPagination: true,
pageCount,
initialState: {
pagination: {
pageSize: 10,
},
},
onPaginationChange: (updater) => {
const newState = typeof updater === 'function' ? updater(table.getState().pagination) : updater
loadData({
page: newState.pageIndex + 1,
perPage: newState.pageSize,
})
},
})
// 선택 상태 변경 시 콜백 호출
React.useEffect(() => {
onSelectionChange?.(table.getFilteredSelectedRowModel().rows.length)
}, [table.getFilteredSelectedRowModel().rows.length, onSelectionChange])
// 선택 해제 요청이 오면 모든 선택 해제
React.useEffect(() => {
if (resetCounter && resetCounter > 0) {
table.toggleAllPageRowsSelected(false)
}
}, [resetCounter, table])
return (
<div className="h-full flex flex-col">
<div className="mb-2">
<div className="flex items-center justify-between mb-2">
<h4 className="font-medium">선종별 표준 AVL</h4>
<div className="flex gap-1">
<Button variant="outline" size="sm" onClick={() => toast.info("개발 중입니다.")}>
신규업체 추가
</Button>
<Button variant="outline" size="sm" onClick={() => toast.info("개발 중입니다.")}>
파일 업로드
</Button>
<Button variant="outline" size="sm" onClick={() => toast.info("개발 중입니다.")}>
일괄입력
</Button>
<Button variant="outline" size="sm" onClick={() => toast.info("개발 중입니다.")}>
항목삭제
</Button>
<Button variant="outline" size="sm" onClick={() => toast.info("개발 중입니다.")}>
저장
</Button>
<Button variant="outline" size="sm" onClick={() => toast.info("개발 중입니다.")}>
최종 확정
</Button>
</div>
</div>
</div>
{/* 검색 UI */}
<div className="mb-4 p-4 border rounded-lg bg-muted/50">
<div className="grid grid-cols-1 md:grid-cols-3 lg:grid-cols-5 gap-4">
{/* 공사부문 */}
<div className="space-y-2">
<label className="text-sm font-medium">공사부문</label>
<Select value={searchConstructionSector} onValueChange={setSearchConstructionSector}>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
{constructionSectorOptions.map((option) => (
<SelectItem key={option.value} value={option.value}>
{option.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
{/* 선종 */}
<div className="space-y-2">
<label className="text-sm font-medium">선종</label>
<Select value={searchShipType} onValueChange={setSearchShipType}>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
{shipTypeOptions.map((option) => (
<SelectItem key={option.value} value={option.value}>
{option.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
{/* AVL종류 */}
<div className="space-y-2">
<label className="text-sm font-medium">AVL종류</label>
<Select value={searchAvlKind} onValueChange={setSearchAvlKind}>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
{avlKindOptions.map((option) => (
<SelectItem key={option.value} value={option.value}>
{option.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
{/* H/T */}
<div className="space-y-2">
<label className="text-sm font-medium">H/T 구분</label>
<Select value={searchHtDivision} onValueChange={setSearchHtDivision}>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
{htDivisionOptions.map((option) => (
<SelectItem key={option.value} value={option.value}>
{option.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
{/* 검색 버튼들 */}
<div className="space-y-2">
<label className="text-sm font-medium opacity-0">버튼</label>
<div className="flex gap-1">
<Button
onClick={handleSearch}
disabled={loading}
size="sm"
className="px-3"
>
<Search className="w-4 h-4 mr-1" />
조회
</Button>
<Button
onClick={handleResetSearch}
variant="outline"
size="sm"
className="px-3"
>
초기화
</Button>
</div>
</div>
</div>
</div>
<div className="flex-1">
<DataTable table={table} />
</div>
</div>
)
}
|