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
|
"use client"
import * as React from "react"
import { useEffect, useState } from "react"
import { Copy } from "lucide-react"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import {
Sheet,
SheetContent,
SheetDescription,
SheetHeader,
SheetTitle
} from "@/components/ui/sheet"
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow
} from "@/components/ui/table"
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
CardFooter
} from "@/components/ui/card"
import { Separator } from "@/components/ui/separator"
import { ViewTagSubfields } from "@/db/schema/vendorData"
import { fetchTagSubfieldOptions } from "../service"
interface TagOption {
id: number
attributesId: string
code: string
label: string
createdAt?: Date
updatedAt?: Date
}
interface ViewTagOptionsProps {
open: boolean
onOpenChange: (open: boolean) => void
tagSubfield: ViewTagSubfields | null
}
export function ViewTagOptions({
open,
onOpenChange,
tagSubfield
}: ViewTagOptionsProps) {
const [options, setOptions] = useState<TagOption[]>([])
const [loading, setLoading] = useState(false)
const [copied, setCopied] = useState<string | null>(null)
// 옵션 데이터 가져오기
useEffect(() => {
async function fetchOptions() {
if (!tagSubfield || !open) return
setLoading(true)
try {
// 서버 액션 호출 - attributesId와 일치하는 모든 옵션 가져오기
const optionsData = await fetchTagSubfieldOptions(tagSubfield.attributesId)
setOptions(optionsData || [])
} catch (error) {
console.error("Error fetching tag options:", error)
setOptions([])
} finally {
setLoading(false)
}
}
fetchOptions()
}, [tagSubfield, open])
// 코드 복사 기능
const copyToClipboard = (text: string, type: string) => {
navigator.clipboard.writeText(text).then(() => {
setCopied(type)
setTimeout(() => setCopied(null), 2000)
})
}
if (!tagSubfield) return null
return (
<Sheet open={open} onOpenChange={onOpenChange}>
<SheetContent className="sm:max-w-xl md:max-w-3xl lg:max-w-4xl xl:max-w-5xl overflow-y-auto">
<SheetHeader className="mb-6">
<SheetTitle className="text-xl flex items-center gap-2">
Field Options
<Badge variant="outline" className="ml-2">
{options.length} options
</Badge>
</SheetTitle>
<SheetDescription className="mb-4">
Field information and available options
</SheetDescription>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 mt-4">
<div className="space-y-2">
<div className="flex items-center justify-between">
<span className="text-sm font-medium">Attributes ID:</span>
<div className="flex items-center gap-1">
<Badge variant="secondary">
{tagSubfield.attributesId}
</Badge>
<Button
variant="ghost"
size="icon"
className="h-6 w-6"
onClick={() => copyToClipboard(tagSubfield.attributesId, 'attributesId')}
>
<Copy className="h-3 w-3" />
</Button>
{copied === 'attributesId' && (
<span className="text-xs text-green-600">Copied</span>
)}
</div>
</div>
<div className="flex items-center justify-between">
<span className="text-sm font-medium">Tag Type:</span>
<Badge>{tagSubfield.tagTypeCode}</Badge>
</div>
</div>
<div className="space-y-2">
<div className="flex items-center justify-between">
<span className="text-sm font-medium">Description:</span>
<span className="text-sm">{tagSubfield.attributesDescription}</span>
</div>
<div className="flex items-center justify-between">
<span className="text-sm font-medium">Expression:</span>
<code className="bg-muted px-2 py-1 rounded text-xs">
{tagSubfield.expression || 'N/A'}
</code>
</div>
</div>
</div>
{tagSubfield.tagTypeDescription && (
<div className="mt-4 text-sm bg-muted p-2 rounded">
<span className="font-medium">Type Description: </span>
{tagSubfield.tagTypeDescription}
</div>
)}
</SheetHeader>
<Separator className="my-4" />
{loading ? (
<div className="flex items-center justify-center h-40">
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-primary"></div>
</div>
) : options.length > 0 ? (
<Card>
<CardHeader>
<CardTitle>Available Options</CardTitle>
<CardDescription>
All available options for field {tagSubfield.attributesId}
</CardDescription>
</CardHeader>
<CardContent>
<Table>
<TableHeader>
<TableRow>
<TableHead className="w-24">Code</TableHead>
<TableHead>Label</TableHead>
<TableHead className="text-right">Actions</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{options.map((option) => (
<TableRow key={option.id}>
<TableCell className="font-mono">
{option.code}
</TableCell>
<TableCell>{option.label}</TableCell>
<TableCell className="text-right">
<Button
variant="ghost"
size="sm"
className="h-8 w-8 p-0"
onClick={() => copyToClipboard(`${option.code} - ${option.label}`, `option-${option.id}`)}
>
<Copy className="h-4 w-4" />
{copied === `option-${option.id}` && (
<span className="absolute -top-2 -right-2 text-xs text-green-600 bg-white px-1 rounded-sm">
Copied
</span>
)}
</Button>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</CardContent>
<CardFooter className="flex justify-between text-sm text-muted-foreground">
<div>
{options.length} options found for {tagSubfield.attributesId}
</div>
{tagSubfield.delimiter && (
<div>
Delimiter: <code className="bg-muted px-2 py-1 rounded text-xs">{tagSubfield.delimiter}</code>
</div>
)}
</CardFooter>
</Card>
) : (
<div className="text-center py-8">
<div className="text-lg font-medium">No options found</div>
<p className="text-muted-foreground mt-2">
This field ({tagSubfield.attributesId}) has no defined options.
</p>
</div>
)}
</SheetContent>
</Sheet>
)
}
|