"use client"; import React from "react"; 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 { Plus, Trash2 } from "lucide-react"; import { TableInfo, ColumnInfo } from "@/lib/api/dataflow"; import { DataSaveSettings } from "@/types/connectionTypes"; import { InsertFieldMappingPanel } from "./InsertFieldMappingPanel"; interface ActionFieldMappingsProps { action: DataSaveSettings["actions"][0]; actionIndex: number; settings: DataSaveSettings; onSettingsChange: (settings: DataSaveSettings) => void; availableTables: TableInfo[]; tableColumnsCache: { [tableName: string]: ColumnInfo[] }; fromTableColumns?: ColumnInfo[]; toTableColumns?: ColumnInfo[]; fromTableName?: string; toTableName?: string; } export const ActionFieldMappings: React.FC = ({ action, actionIndex, settings, onSettingsChange, availableTables, tableColumnsCache, fromTableColumns = [], toTableColumns = [], fromTableName, toTableName, }) => { // INSERT 액션일 때는 새로운 패널 사용 if (action.actionType === "insert" && fromTableColumns.length > 0 && toTableColumns.length > 0) { return ( ); } const addFieldMapping = () => { const newActions = [...settings.actions]; newActions[actionIndex].fieldMappings.push({ sourceTable: "", sourceField: "", targetTable: "", targetField: "", defaultValue: "", transformFunction: "", }); onSettingsChange({ ...settings, actions: newActions }); }; const updateFieldMapping = (mappingIndex: number, field: string, value: string) => { const newActions = [...settings.actions]; (newActions[actionIndex].fieldMappings[mappingIndex] as any)[field] = value; onSettingsChange({ ...settings, actions: newActions }); }; const removeFieldMapping = (mappingIndex: number) => { const newActions = [...settings.actions]; newActions[actionIndex].fieldMappings = newActions[actionIndex].fieldMappings.filter((_, i) => i !== mappingIndex); onSettingsChange({ ...settings, actions: newActions }); }; return (
(필수)
{action.fieldMappings.map((mapping, mappingIndex) => (
{/* 컴팩트한 매핑 표시 */}
{/* 소스 */}
{mapping.sourceTable && ( )} .
{/* 타겟 */}
.
{/* 기본값 (인라인) */} { updateFieldMapping(mappingIndex, "defaultValue", e.target.value); if (e.target.value.trim()) { updateFieldMapping(mappingIndex, "sourceTable", ""); updateFieldMapping(mappingIndex, "sourceField", ""); } }} disabled={!!mapping.sourceTable} className="h-6 w-20 text-xs" placeholder="기본값" /> {/* 삭제 버튼 */}
))} {/* 필드 매핑이 없을 때 안내 메시지 */} {action.fieldMappings.length === 0 && (
⚠️
필드 매핑이 필요합니다
{action.actionType.toUpperCase()} 액션은 어떤 데이터를 어떻게 처리할지 결정하는 필드 매핑이 필요합니다.
)}
); };