"use client"; import React, { useState, useEffect } from "react"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Textarea } from "@/components/ui/textarea"; import { ArrowRight, Database, Link } from "lucide-react"; // 연결 정보 타입 interface ConnectionInfo { fromNode: { id: string; screenName: string; tableName: string; }; toNode: { id: string; screenName: string; tableName: string; }; fromField?: string; toField?: string; selectedFieldsData?: { [screenId: string]: { screenName: string; fields: string[]; }; }; orderedScreenIds?: string[]; // 선택 순서 정보 } // 연결 설정 타입 interface ConnectionConfig { relationshipName: string; relationshipType: "one-to-one" | "one-to-many" | "many-to-one" | "many-to-many"; connectionType: "simple-key" | "data-save" | "external-call"; fromFieldName: string; toFieldName: string; settings?: Record; description?: string; } interface ConnectionSetupModalProps { isOpen: boolean; connection: ConnectionInfo | null; onConfirm: (config: ConnectionConfig) => void; onCancel: () => void; } export const ConnectionSetupModal: React.FC = ({ isOpen, connection, onConfirm, onCancel, }) => { const [relationshipName, setRelationshipName] = useState(""); const [relationshipType, setRelationshipType] = useState("one-to-one"); const [connectionType, setConnectionType] = useState("simple-key"); const [fromFieldName, setFromFieldName] = useState(""); const [toFieldName, setToFieldName] = useState(""); const [description, setDescription] = useState(""); // 모달이 열릴 때마다 초기화 useEffect(() => { if (isOpen && connection) { // 기본 관계명 생성 const defaultName = `${connection.fromNode.screenName}_${connection.toNode.screenName}`; setRelationshipName(defaultName); setRelationshipType("one-to-one"); setConnectionType("simple-key"); // 시작/대상 필드는 비워둠 (다음 기능에서 사용) setFromFieldName(""); setToFieldName(""); setDescription(""); } }, [isOpen, connection]); const handleConfirm = () => { if (!relationshipName.trim()) { alert("관계명을 입력해주세요."); return; } const config: ConnectionConfig = { relationshipName: relationshipName.trim(), relationshipType, connectionType, fromFieldName, toFieldName, description: description.trim() || undefined, }; onConfirm(config); }; const getRelationshipTypeDescription = (type: string) => { switch (type) { case "one-to-one": return "1:1 - 한 레코드가 다른 테이블의 한 레코드와 연결"; case "one-to-many": return "1:N - 한 레코드가 다른 테이블의 여러 레코드와 연결"; case "many-to-one": return "N:1 - 여러 레코드가 다른 테이블의 한 레코드와 연결"; case "many-to-many": return "N:N - 여러 레코드가 다른 테이블의 여러 레코드와 연결 (중계 테이블 생성)"; default: return ""; } }; const getConnectionTypeDescription = (type: string) => { switch (type) { case "simple-key": return "단순 키값 연결 - 기본 참조 관계"; case "data-save": return "데이터 저장 - 필드 매핑을 통한 데이터 저장"; case "external-call": return "외부 호출 - API, 이메일, 웹훅 등을 통한 외부 시스템 연동"; default: return ""; } }; if (!connection) return null; return ( 필드 연결 설정
{/* 연결 정보 표시 */} 연결 정보 {connection.selectedFieldsData && connection.orderedScreenIds ? (
{/* orderedScreenIds 순서대로 표시 */} {connection.orderedScreenIds.map((screenId, index) => { const screenData = connection.selectedFieldsData[screenId]; if (!screenData) return null; return (
{screenData.screenName}
ID: {screenId}
{index === 0 ? connection.fromNode.tableName : connection.toNode.tableName}
{screenData.fields.map((field) => ( {field} ))}
{/* 첫 번째 화면 다음에 화살표 표시 */} {index === 0 && connection.orderedScreenIds.length > 1 && (
)}
); })}
) : (
{connection.fromNode.screenName}
{connection.fromNode.tableName}
{connection.toNode.screenName}
{connection.toNode.tableName}
)}
{/* 기본 설정 */}

기본 설정

setRelationshipName(e.target.value)} placeholder="관계를 설명하는 이름을 입력하세요" />
setFromFieldName(e.target.value)} placeholder="시작 테이블의 필드명" />
setToFieldName(e.target.value)} placeholder="대상 테이블의 필드명" />