"use client"; /** * 필드 매핑 노드 속성 편집 */ import { useEffect, useState } from "react"; import { Plus, Trash2, ArrowRight } from "lucide-react"; import { Label } from "@/components/ui/label"; import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; import { ScrollArea } from "@/components/ui/scroll-area"; import { useFlowEditorStore } from "@/lib/stores/flowEditorStore"; import type { FieldMappingNodeData } from "@/types/node-editor"; interface FieldMappingPropertiesProps { nodeId: string; data: FieldMappingNodeData; } export function FieldMappingProperties({ nodeId, data }: FieldMappingPropertiesProps) { const { updateNode } = useFlowEditorStore(); const [displayName, setDisplayName] = useState(data.displayName || "데이터 매핑"); const [mappings, setMappings] = useState(data.mappings || []); // 데이터 변경 시 로컬 상태 업데이트 useEffect(() => { setDisplayName(data.displayName || "데이터 매핑"); setMappings(data.mappings || []); }, [data]); const handleAddMapping = () => { setMappings([ ...mappings, { id: `mapping_${Date.now()}`, sourceField: "", targetField: "", transform: undefined, staticValue: undefined, }, ]); }; const handleRemoveMapping = (id: string) => { setMappings(mappings.filter((m) => m.id !== id)); }; const handleMappingChange = (id: string, field: string, value: any) => { const newMappings = mappings.map((m) => (m.id === id ? { ...m, [field]: value } : m)); setMappings(newMappings); }; const handleSave = () => { updateNode(nodeId, { displayName, mappings, }); }; return (
{/* 기본 정보 */}

기본 정보

setDisplayName(e.target.value)} className="mt-1" placeholder="노드 표시 이름" />
{/* 매핑 규칙 */}

매핑 규칙

{mappings.length > 0 ? (
{mappings.map((mapping, index) => (
규칙 #{index + 1}
{/* 소스 → 타겟 */}
handleMappingChange(mapping.id, "sourceField", e.target.value)} placeholder="입력 필드" className="mt-1 h-8 text-xs" />
handleMappingChange(mapping.id, "targetField", e.target.value)} placeholder="출력 필드" className="mt-1 h-8 text-xs" />
{/* 변환 함수 */}
handleMappingChange(mapping.id, "transform", e.target.value)} placeholder="예: UPPER(), TRIM(), CONCAT()" className="mt-1 h-8 text-xs" />
{/* 정적 값 */}
handleMappingChange(mapping.id, "staticValue", e.target.value)} placeholder="고정 값 (소스 필드 대신 사용)" className="mt-1 h-8 text-xs" />
))}
) : (
매핑 규칙이 없습니다. "추가" 버튼을 클릭하세요.
)}
{/* 저장 버튼 */}
{/* 안내 */}
💡 소스 필드: 입력 데이터의 필드명
💡 타겟 필드: 출력 데이터의 필드명
💡 변환 함수: 데이터 변환 로직 (SQL 함수 형식)
); }