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
|
"use client"
import { type DataTableRowAction } from "@/types/table"
import { type ColumnDef } from "@tanstack/react-table"
import { MoreHorizontal } from "lucide-react"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { integrations } from "@/db/schema/integration"
interface GetColumnsProps {
setRowAction: React.Dispatch<React.SetStateAction<DataTableRowAction<typeof integrations.$inferSelect> | null>>;
}
/**
* tanstack table 컬럼 정의
*/
export function getColumns({ setRowAction }: GetColumnsProps): ColumnDef<typeof integrations.$inferSelect>[] {
// ----------------------------------------------------------------
// 1) select 컬럼 (체크박스)
// ----------------------------------------------------------------
const selectColumn: ColumnDef<typeof integrations.$inferSelect> = {
id: "select",
header: ({ table }) => (
<input
type="checkbox"
checked={table.getIsAllPageRowsSelected()}
onChange={(value) => table.toggleAllPageRowsSelected(!!value.target.checked)}
aria-label="Select all"
className="translate-y-[2px]"
/>
),
cell: ({ row }) => (
<input
type="checkbox"
checked={row.getIsSelected()}
onChange={(value) => row.toggleSelected(!!value.target.checked)}
aria-label="Select row"
className="translate-y-[2px]"
/>
),
enableSorting: false,
enableHiding: false,
}
// ----------------------------------------------------------------
// 3) 데이터 컬럼들
// ----------------------------------------------------------------
const dataColumns: ColumnDef<typeof integrations.$inferSelect>[] = [
{
accessorKey: "code",
header: "코드",
filterFn: "includesString",
enableSorting: true,
enableHiding: false,
cell: ({ row }) => {
const code = row.getValue("code") as string;
return <div className="font-medium">{code}</div>;
},
minSize: 100
},
{
accessorKey: "name",
header: "이름",
filterFn: "includesString",
enableSorting: true,
enableHiding: false,
cell: ({ row }) => {
const name = row.getValue("name") as string;
return <div>{name}</div>;
},
minSize: 150
},
{
accessorKey: "type",
header: "타입",
filterFn: "includesString",
enableSorting: true,
enableHiding: false,
cell: ({ row }) => {
const type = row.getValue("type") as string;
return getTypeBadge(type);
},
minSize: 100
},
{
accessorKey: "sourceSystem",
header: "소스 시스템",
filterFn: "includesString",
enableSorting: true,
enableHiding: false,
cell: ({ row }) => {
const sourceSystem = row.getValue("sourceSystem") as string;
return <div>{sourceSystem}</div>;
},
minSize: 120
},
{
accessorKey: "targetSystem",
header: "타겟 시스템",
filterFn: "includesString",
enableSorting: true,
enableHiding: false,
cell: ({ row }) => {
const targetSystem = row.getValue("targetSystem") as string;
return <div>{targetSystem}</div>;
},
minSize: 120
},
{
accessorKey: "status",
header: "상태",
filterFn: "includesString",
enableSorting: true,
enableHiding: false,
cell: ({ row }) => {
const status = row.getValue("status") as string;
return getStatusBadge(status);
},
minSize: 80
},
{
accessorKey: "description",
header: "설명",
filterFn: "includesString",
enableSorting: true,
enableHiding: false,
cell: ({ row }) => {
const description = row.getValue("description") as string;
return <div className="max-w-xs truncate">{description || "-"}</div>;
},
minSize: 150
},
{
accessorKey: "createdAt",
header: "생성일",
filterFn: "includesString",
enableSorting: true,
enableHiding: false,
cell: ({ row }) => {
const createdAt = row.getValue("createdAt") as string;
return <div>{new Date(createdAt).toLocaleDateString()}</div>;
},
minSize: 80
},
]
// ----------------------------------------------------------------
// 4) 컬럼 조합
// ----------------------------------------------------------------
const actionsColumn: ColumnDef<typeof integrations.$inferSelect> = {
id: "actions",
header: "",
enableSorting: false,
enableHiding: false,
cell: function Cell({ row }) {
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" className="h-8 w-8 p-0">
<span className="sr-only">Open menu</span>
<MoreHorizontal className="h-4 w-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-40">
<DropdownMenuItem onClick={() => setRowAction({ type: "update", row })}>
Edit
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem onClick={() => setRowAction({ type: "delete", row })}>
Delete
<span className="ml-auto text-xs text-muted-foreground">⌘⌫</span>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
);
},
}
return [selectColumn, ...dataColumns, actionsColumn]
}
const getStatusBadge = (status: string) => {
switch (status) {
case "active":
return <Badge variant="default">활성</Badge>;
case "inactive":
return <Badge variant="secondary">비활성</Badge>;
case "deprecated":
return <Badge variant="destructive">사용중단</Badge>;
default:
return <Badge variant="outline">{status}</Badge>;
}
};
const getTypeBadge = (type: string) => {
switch (type) {
case "rest_api":
return <Badge variant="outline">REST API</Badge>;
case "soap":
return <Badge variant="outline">SOAP</Badge>;
case "db_to_db":
return <Badge variant="outline">DB to DB</Badge>;
default:
return <Badge variant="outline">{type}</Badge>;
}
};
|