"use client"; import React, { useState } from "react"; import { ArrowLeft, Save, CheckCircle, XCircle, AlertCircle } from "lucide-react"; import { TableInfo, FieldMapping, ColumnInfo } from "../types/redesigned"; interface FieldMappingStepProps { fromTable?: TableInfo; toTable?: TableInfo; fieldMappings: FieldMapping[]; onMappingsChange: (mappings: FieldMapping[]) => void; onBack: () => void; onSave: () => void; } export const FieldMappingStep: React.FC = ({ fromTable, toTable, fieldMappings, onMappingsChange, onBack, onSave, }) => { const [draggedField, setDraggedField] = useState(null); const createMapping = (fromField: ColumnInfo, toField: ColumnInfo) => { const mapping: FieldMapping = { id: `${fromField.name}-${toField.name}`, fromField, toField, isValid: fromField.type === toField.type, validationMessage: fromField.type !== toField.type ? "타입이 다릅니다" : undefined }; const newMappings = [...fieldMappings, mapping]; onMappingsChange(newMappings); }; const removeMapping = (mappingId: string) => { const newMappings = fieldMappings.filter(m => m.id !== mappingId); onMappingsChange(newMappings); }; const handleDragStart = (field: ColumnInfo) => { setDraggedField(field); }; const handleDragOver = (e: React.DragEvent) => { e.preventDefault(); }; const handleDrop = (e: React.DragEvent, toField: ColumnInfo) => { e.preventDefault(); if (draggedField) { createMapping(draggedField, toField); setDraggedField(null); } }; const getMappedFromField = (toFieldName: string) => { return fieldMappings.find(m => m.toField.name === toFieldName)?.fromField; }; const isFieldMapped = (fieldName: string) => { return fieldMappings.some(m => m.fromField.name === fieldName || m.toField.name === fieldName); }; return (

필드 매핑

소스 테이블의 필드를 대상 테이블의 필드에 드래그하여 매핑하세요

{/* 매핑 통계 */}
{fieldMappings.length}
총 매핑
{fieldMappings.filter(m => m.isValid).length}
유효한 매핑
{fieldMappings.filter(m => !m.isValid).length}
오류 매핑
{(toTable?.columns.length || 0) - fieldMappings.length}
미매핑 필드
{/* 매핑 영역 */}
{/* FROM 테이블 필드들 */}

FROM
{fromTable?.name} 필드들

{fromTable?.columns.map((field) => (
handleDragStart(field)} className={`p-3 rounded-lg border-2 cursor-move transition-all duration-200 ${ isFieldMapped(field.name) ? "border-green-300 bg-green-50 opacity-60" : "border-blue-200 bg-blue-50 hover:border-blue-400 hover:bg-blue-100" }`} >
{field.name}
{field.type}
{field.primaryKey && ( PK )}
{isFieldMapped(field.name) && ( )}
))}
{/* TO 테이블 필드들 */}

TO
{toTable?.name} 필드들

{toTable?.columns.map((field) => { const mappedFromField = getMappedFromField(field.name); return (
handleDrop(e, field)} className={`p-3 rounded-lg border-2 transition-all duration-200 ${ mappedFromField ? "border-green-300 bg-green-50" : "border-gray-200 bg-gray-50 hover:border-green-300 hover:bg-green-25" }`} >
{field.name}
{field.type}
{field.primaryKey && ( PK )} {mappedFromField && (
← {mappedFromField.name} ({mappedFromField.type})
)}
{mappedFromField && ( )} {mappedFromField && (
{fieldMappings.find(m => m.toField.name === field.name)?.isValid ? ( ) : ( )}
)}
); })}
{/* 버튼들 */}
); };