"use client"; import React, { useState, useEffect } from "react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { Label } from "@/components/ui/label"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Switch } from "@/components/ui/switch"; import { Button } from "@/components/ui/button"; import { Separator } from "@/components/ui/separator"; import { Settings, GitBranch, Clock, Zap, Info } from "lucide-react"; import { ComponentData, ButtonDataflowConfig } from "@/types/screen"; import { apiClient } from "@/lib/api/client"; interface ImprovedButtonControlConfigPanelProps { component: ComponentData; onUpdateProperty: (path: string, value: any) => void; } interface RelationshipOption { id: string; name: string; sourceTable: string; targetTable: string; category: string; } /** * ๐Ÿ”ฅ ๋‹จ์ˆœํ™”๋œ ๋ฒ„ํŠผ ์ œ์–ด ์„ค์ • ํŒจ๋„ * * ๊ด€๊ณ„ ์‹คํ–‰๋งŒ ์ง€์›: * - ๊ด€๊ณ„ ์„ ํƒ ๋ฐ ์‹คํ–‰ ํƒ€์ด๋ฐ ์„ค์ • * - ๊ด€๊ณ„ ๋‚ด๋ถ€์— ๋ฐ์ดํ„ฐ ์ €์žฅ/์™ธ๋ถ€ํ˜ธ์ถœ ๋กœ์ง ํฌํ•จ */ export const ImprovedButtonControlConfigPanel: React.FC = ({ component, onUpdateProperty, }) => { const config = component.webTypeConfig || {}; const dataflowConfig = config.dataflowConfig || {}; // ๐Ÿ”ฅ State ๊ด€๋ฆฌ const [relationships, setRelationships] = useState([]); const [loading, setLoading] = useState(false); // ๐Ÿ”ฅ ๊ด€๊ณ„ ๋ชฉ๋ก ๋กœ๋”ฉ useEffect(() => { if (config.enableDataflowControl) { loadRelationships(); } }, [config.enableDataflowControl]); /** * ๐Ÿ”ฅ ์ „์ฒด ๊ด€๊ณ„ ๋ชฉ๋ก ๋กœ๋“œ (๊ด€๊ณ„๋„๋ณ„ ๊ตฌ๋ถ„ ์—†์ด) */ const loadRelationships = async () => { try { setLoading(true); console.log("๐Ÿ” ์ „์ฒด ๊ด€๊ณ„ ๋ชฉ๋ก ๋กœ๋”ฉ..."); const response = await apiClient.get("/test-button-dataflow/relationships/all"); if (response.data.success && Array.isArray(response.data.data)) { const relationshipList = response.data.data.map((rel: any) => ({ id: rel.id, name: rel.name || `${rel.sourceTable} โ†’ ${rel.targetTable}`, sourceTable: rel.sourceTable, targetTable: rel.targetTable, category: rel.category || "๋ฐ์ดํ„ฐ ํ๋ฆ„", })); setRelationships(relationshipList); console.log(`โœ… ๊ด€๊ณ„ ${relationshipList.length}๊ฐœ ๋กœ๋”ฉ ์™„๋ฃŒ`); } } catch (error) { console.error("โŒ ๊ด€๊ณ„ ๋ชฉ๋ก ๋กœ๋”ฉ ์‹คํŒจ:", error); setRelationships([]); } finally { setLoading(false); } }; /** * ๐Ÿ”ฅ ๊ด€๊ณ„ ์„ ํƒ ํ•ธ๋“ค๋Ÿฌ */ const handleRelationshipSelect = (relationshipId: string) => { const selectedRelationship = relationships.find(r => r.id === relationshipId); if (selectedRelationship) { onUpdateProperty("webTypeConfig.dataflowConfig.relationshipConfig", { relationshipId: selectedRelationship.id, relationshipName: selectedRelationship.name, executionTiming: "after", // ๊ธฐ๋ณธ๊ฐ’ contextData: {}, }); } }; /** * ๐Ÿ”ฅ ์ œ์–ด ํƒ€์ž… ๋ณ€๊ฒฝ ํ•ธ๋“ค๋Ÿฌ */ const handleControlTypeChange = (controlType: string) => { // ๊ธฐ์กด ์„ค์ • ์ดˆ๊ธฐํ™” onUpdateProperty("webTypeConfig.dataflowConfig", { controlMode: controlType, relationshipConfig: controlType === "relationship" ? undefined : null, }); }; return (
{/* ๐Ÿ”ฅ ์ œ์–ด๊ด€๋ฆฌ ํ™œ์„ฑํ™” ์Šค์œ„์น˜ */}

๋ฒ„ํŠผ ํด๋ฆญ ์‹œ ์ถ”๊ฐ€ ์ž‘์—…์„ ์ž๋™์œผ๋กœ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค

onUpdateProperty("webTypeConfig.enableDataflowControl", checked)} />
{/* ๐Ÿ”ฅ ์ œ์–ด๊ด€๋ฆฌ๊ฐ€ ํ™œ์„ฑํ™”๋œ ๊ฒฝ์šฐ์—๋งŒ ์„ค์ • ํ‘œ์‹œ */} {config.enableDataflowControl && ( ๋ฒ„ํŠผ ์ œ์–ด ์„ค์ • ์ œ์–ด ์—†์Œ ๊ด€๊ณ„ ์‹คํ–‰

์ถ”๊ฐ€ ์ œ์–ด ์—†์ด ๊ธฐ๋ณธ ๋ฒ„ํŠผ ์•ก์…˜๋งŒ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

{dataflowConfig.relationshipConfig && (
onUpdateProperty("webTypeConfig.dataflowConfig.relationshipConfig.executionTiming", timing) } />

๊ด€๊ณ„ ์‹คํ–‰ ์ •๋ณด:

์„ ํƒํ•œ ๊ด€๊ณ„์— ์„ค์ •๋œ ๋ฐ์ดํ„ฐ ์ €์žฅ, ์™ธ๋ถ€ํ˜ธ์ถœ ๋“ฑ์˜ ๋ชจ๋“  ์•ก์…˜์ด ์ž๋™์œผ๋กœ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

)}
)}
); }; /** * ๐Ÿ”ฅ ๊ด€๊ณ„ ์„ ํƒ ์ปดํฌ๋„ŒํŠธ */ const RelationshipSelector: React.FC<{ relationships: RelationshipOption[]; selectedRelationshipId?: string; onSelect: (relationshipId: string) => void; loading: boolean; }> = ({ relationships, selectedRelationshipId, onSelect, loading }) => { return (
); }; /** * ๐Ÿ”ฅ ์‹คํ–‰ ํƒ€์ด๋ฐ ์„ ํƒ ์ปดํฌ๋„ŒํŠธ */ const ExecutionTimingSelector: React.FC<{ value: string; onChange: (timing: "before" | "after" | "replace") => void; }> = ({ value, onChange }) => { return (
); };