From e0dfb55c5457aec489fc084c4567e791b4c65eb1 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Wed, 26 Mar 2025 00:37:41 +0000 Subject: 3/25 까지의 대표님 작업사항 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/form-list/table/meta-sheet.tsx | 245 +++++++++++++++++++++++++++++++++++++ 1 file changed, 245 insertions(+) create mode 100644 lib/form-list/table/meta-sheet.tsx (limited to 'lib/form-list/table/meta-sheet.tsx') diff --git a/lib/form-list/table/meta-sheet.tsx b/lib/form-list/table/meta-sheet.tsx new file mode 100644 index 00000000..155e4f5a --- /dev/null +++ b/lib/form-list/table/meta-sheet.tsx @@ -0,0 +1,245 @@ +"use client" + +import * as React from "react" +import { useMemo } from "react" +import { Badge } from "@/components/ui/badge" +import { + Sheet, + SheetContent, + SheetDescription, + SheetHeader, + SheetTitle +} from "@/components/ui/sheet" +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow +} from "@/components/ui/table" +import { + Tabs, + TabsContent, + TabsList, + TabsTrigger +} from "@/components/ui/tabs" +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle +} from "@/components/ui/card" +import type { TagTypeClassFormMappings } from "@/db/schema/vendorData" // or your actual type +import { fetchFormMetadata, FormColumn } from "@/lib/forms/services" + + +interface ViewMetasProps { + open: boolean + onOpenChange: (open: boolean) => void + form: TagTypeClassFormMappings | null +} + +export function ViewMetas({ open, onOpenChange, form }: ViewMetasProps) { + // metadata & loading + const [metadata, setMetadata] = React.useState<{ + formName: string + formCode: string + columns: FormColumn[] + } | null>(null) + const [loading, setLoading] = React.useState(false) + + // Group columns by type for better organization + const groupedColumns = useMemo(() => { + if (!metadata?.columns) return {} + + return metadata.columns.reduce((acc, column) => { + const type = column.type + if (!acc[type]) { + acc[type] = [] + } + acc[type].push(column) + return acc + }, {} as Record) + }, [metadata]) + + // Types for the tabs + const columnTypes = useMemo(() => { + return Object.keys(groupedColumns) + }, [groupedColumns]) + + // Fetch metadata when form changes and dialog is opened + React.useEffect(() => { + async function fetchMeta() { + if (!form || !open) return + + setLoading(true) + try { + // 서버 액션 호출 + const metaData = await fetchFormMetadata(form.formCode) + if (metaData) { + setMetadata(metaData) + } else { + setMetadata(null) + } + } catch (error) { + console.error("Error fetching form metadata:", error) + setMetadata(null) + } finally { + setLoading(false) + } + } + + fetchMeta() + }, [form, open]) + + if (!form) return null + + return ( + + + + + Form Metadata + + + {loading ? ( +
Loading metadata...
+ ) : metadata ? ( +
+
+ Form Code: + {metadata.formCode} +
+
+ Form Name: + {metadata.formName} +
+
+ ) : ( +
+ No metadata found for form code: {form.formCode} +
+ )} + +
+ + {loading ? ( +
+
+
+ ) : metadata ? ( + + + All ({metadata.columns.length}) + {columnTypes.map((type) => ( + + {type} ({groupedColumns[type].length}) + + ))} + + + + + + All Fields + All form fields and their properties + + + + + + Key + Label + Type + Options + + + + {metadata.columns.map((column) => ( + + {column.key} + {column.label} + + {column.type} + + + {column.options ? ( +
+ {column.options.map((option) => ( + + {option} + + ))} +
+ ) : ( + "-" + )} +
+
+ ))} +
+
+
+
+
+ + {columnTypes.map((type) => ( + + + + {type.charAt(0).toUpperCase() + type.slice(1)} Fields + Fields with type "{type}" + + + + + + Key + Label + {type === "select" && Options} + + + + {groupedColumns[type].map((column) => ( + + {column.key} + {column.label} + {type === "select" && ( + + {column.options ? ( +
+ {column.options.map((option) => ( + + {option} + + ))} +
+ ) : ( + "-" + )} +
+ )} +
+ ))} +
+
+
+
+
+ ))} +
+ ) : ( +
+
No metadata found
+

+ Could not find metadata for form code: {form.formCode} +

+
+ )} + +
+
+ ) +} \ No newline at end of file -- cgit v1.2.3