summaryrefslogtreecommitdiff
path: root/lib/tech-vendor-possible-items/table/possible-items-data-table.tsx
blob: 28b9774f466dd32e36f26bb994396100fa4e8fd4 (plain)
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
"use client";

import * as React from "react";

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 { getColumns } from "./possible-items-table-columns";
import { PossibleItemsTableToolbarActions } from "./possible-items-table-toolbar-actions";

// 타입만 import
type TechVendorPossibleItemsData = {
  id: number;
  vendorId: number;
  vendorCode: string | null;
  vendorName: string;
  techVendorType: string;
  itemCode: string;
  itemList: string | null;
  workType: string | null;
  shipTypes: string | null;
  subItemList: string | null;
  createdAt: Date;
  updatedAt: Date;
};
import type { DataTableAdvancedFilterField } from "@/types/table";

interface PossibleItemsDataTableProps {
  promises: Promise<[{
    data: TechVendorPossibleItemsData[];
    pageCount: number;
    totalCount: number;
  }, string[]]>;
}

export function PossibleItemsDataTable({ promises }: PossibleItemsDataTableProps) {
  const [{ data, pageCount }, vendorTypes] = React.use(promises);

  const columns = React.useMemo(() => getColumns(), []);

  const filterFields: DataTableAdvancedFilterField<TechVendorPossibleItemsData>[] = [
    {
      id: "vendorCode",
      label: "벤더코드",
      type: "text",
    },
    {
      id: "vendorName",
      label: "벤더명", 
      type: "text",
    },
    {
      id: "itemCode",
      label: "아이템코드",
      type: "text",
    },
    {
      id: "itemList",
      label: "아이템리스트",
      type: "text",
    },
    {
      id: "workType",
      label: "공종",
      type: "text",
    },
    {
      id: "shipTypes",
      label: "선종",
      type: "text",
    },
    {
      id: "subItemList",
      label: "서브아이템리스트",
      type: "text",
    },
    {
      id: "techVendorType",
      label: "벤더타입",
      type: "multi-select",
      options: Array.isArray(vendorTypes) ? vendorTypes.map((type: string) => ({
        label: type,
        value: type,
        count: 0,
      })) : [],
    },
  ];

  const { table } = useDataTable({
    data,
    columns,
    pageCount,
    filterFields,
    enableAdvancedFilter: true,
    initialState: {
      sorting: [{ id: "createdAt", desc: true }],
      pagination: { pageIndex: 0, pageSize: 10 },
    },
    getRowId: (originalRow) => `${originalRow.vendorId}-${originalRow.itemCode}-${originalRow.id}`,
    shallow: false,
    clearOnDefault: true,
  });

  return (
    <>
      <DataTable table={table}>
        <DataTableAdvancedToolbar table={table} filterFields={filterFields}>
          <PossibleItemsTableToolbarActions table={table} />
        </DataTableAdvancedToolbar>
      </DataTable>
    </>
  );
}