"use client"; import React, { useState, useEffect } from "react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Badge } from "@/components/ui/badge"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { ArrowLeft, Settings, CheckCircle, Eye } from "lucide-react"; // 타입 import import { DataConnectionState, DataConnectionActions } from "../types/redesigned"; import { ColumnInfo } from "@/lib/types/multiConnection"; import { getColumnsFromConnection } from "@/lib/api/multiConnection"; // 컴포넌트 import import ActionConditionBuilder from "./ActionConfig/ActionConditionBuilder"; import { DataflowVisualization } from "./DataflowVisualization"; interface ActionConfigStepProps { state: DataConnectionState; actions: DataConnectionActions; onBack: () => void; onComplete: () => void; onSave?: () => void; // UPDATE/DELETE인 경우 저장 버튼 showSaveButton?: boolean; // 저장 버튼 표시 여부 } /** * 🎯 4단계: 액션 설정 * - 액션 타입 선택 (INSERT/UPDATE/DELETE/UPSERT) * - 실행 조건 설정 * - 액션별 상세 설정 */ const ActionConfigStep: React.FC = ({ state, actions, onBack, onComplete, onSave, showSaveButton = false, }) => { const { actionType, actionConditions, fromTable, toTable, fromConnection, toConnection } = state; const [fromColumns, setFromColumns] = useState([]); const [toColumns, setToColumns] = useState([]); const [fieldMappings, setFieldMappings] = useState([]); const [isLoading, setIsLoading] = useState(false); const actionTypes = [ { value: "insert", label: "INSERT", description: "새 데이터 삽입" }, { value: "update", label: "UPDATE", description: "기존 데이터 수정" }, { value: "delete", label: "DELETE", description: "데이터 삭제" }, { value: "upsert", label: "UPSERT", description: "있으면 수정, 없으면 삽입" }, ]; // 컬럼 정보 로드 useEffect(() => { const loadColumns = async () => { if (!fromConnection || !toConnection || !fromTable || !toTable) return; setIsLoading(true); try { const [fromCols, toCols] = await Promise.all([ getColumnsFromConnection(fromConnection.id, fromTable.tableName), getColumnsFromConnection(toConnection.id, toTable.tableName), ]); setFromColumns(fromCols); setToColumns(toCols); } catch (error) { console.error("컬럼 정보 로드 실패:", error); } finally { setIsLoading(false); } }; loadColumns(); }, [fromConnection, toConnection, fromTable, toTable]); const canComplete = actionType && (actionType === "insert" || ((actionConditions || []).length > 0 && (actionType === "delete" || fieldMappings.length > 0))); return ( <> 4단계: 액션 설정
액션 설정 설정 흐름 미리보기 미리보기
{/* 액션 설정 탭 */}
{/* 액션 타입 선택 */}

액션 타입

{actionType && (
{actionTypes.find((t) => t.value === actionType)?.label} {actionTypes.find((t) => t.value === actionType)?.description}
)}
{/* 상세 조건 설정 */} {actionType && !isLoading && fromColumns.length > 0 && toColumns.length > 0 && ( { // 액션 조건 배열 전체 업데이트 actions.setActionConditions(conditions); }} onFieldMappingsChange={setFieldMappings} /> )} {/* 로딩 상태 */} {isLoading && (
컬럼 정보를 불러오는 중...
)} {/* INSERT 액션 안내 */} {actionType === "insert" && (

INSERT 액션

INSERT 액션은 별도의 실행 조건이 필요하지 않습니다. 매핑된 모든 데이터가 새로운 레코드로 삽입됩니다.

)} {/* 액션 요약 */} {actionType && (

설정 요약

액션 타입: {actionType.toUpperCase()}
{actionType !== "insert" && ( <>
실행 조건: {actionConditions.length > 0 ? `${actionConditions.length}개 조건` : "조건 없음"}
{actionType !== "delete" && (
필드 매핑: {fieldMappings.length > 0 ? `${fieldMappings.length}개 필드` : "필드 없음"}
)} )}
)}
{/* 흐름 미리보기 탭 */} { // 편집 버튼 클릭 시 해당 단계로 이동하는 로직 추가 가능 console.log(`편집 요청: ${step}`); }} />
{/* 하단 네비게이션 */}
{showSaveButton && onSave && ( )} {!showSaveButton && ( )}
{!canComplete && (

{!actionType ? "액션 타입을 선택해주세요" : "실행 조건을 추가해주세요"}

)}
); }; export default ActionConfigStep;