"use client"; import React from "react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Trash2 } from "lucide-react"; import { ConditionNode, ColumnInfo } from "@/lib/api/dataflow"; import { DataSaveSettings } from "@/types/connectionTypes"; import { getInputTypeForDataType } from "@/utils/connectionUtils"; interface ActionConditionRendererProps { condition: ConditionNode; condIndex: number; actionIndex: number; settings: DataSaveSettings; onSettingsChange: (settings: DataSaveSettings) => void; fromTableColumns: ColumnInfo[]; toTableColumns: ColumnInfo[]; fromTableName?: string; toTableName?: string; getActionCurrentGroupLevel: (conditions: ConditionNode[], conditionIndex: number) => number; } export const ActionConditionRenderer: React.FC = ({ condition, condIndex, actionIndex, settings, onSettingsChange, fromTableColumns, toTableColumns, fromTableName, toTableName, getActionCurrentGroupLevel, }) => { const removeConditionGroup = (groupId: string) => { const newActions = [...settings.actions]; newActions[actionIndex].conditions = newActions[actionIndex].conditions!.filter((c) => c.groupId !== groupId); onSettingsChange({ ...settings, actions: newActions }); }; const removeCondition = () => { const newActions = [...settings.actions]; newActions[actionIndex].conditions = newActions[actionIndex].conditions!.filter((_, i) => i !== condIndex); onSettingsChange({ ...settings, actions: newActions }); }; const updateCondition = (field: string, value: any) => { const newActions = [...settings.actions]; (newActions[actionIndex].conditions![condIndex] as any)[field] = value; onSettingsChange({ ...settings, actions: newActions }); }; const updateLogicalOperator = (targetIndex: number, value: "AND" | "OR") => { const newActions = [...settings.actions]; newActions[actionIndex].conditions![targetIndex].logicalOperator = value; onSettingsChange({ ...settings, actions: newActions }); }; const renderConditionValue = () => { // 선택된 테이블 타입에 따라 컬럼 찾기 const targetColumns = condition.tableType === "from" ? fromTableColumns : toTableColumns; const selectedColumn = targetColumns.find((col) => col.columnName === condition.field); const dataType = selectedColumn?.dataType?.toLowerCase() || "string"; const inputType = getInputTypeForDataType(dataType); if (dataType.includes("bool")) { return ( ); } else { return ( updateCondition("value", e.target.value)} className="h-6 flex-1 text-xs" /> ); } }; // 그룹 시작 렌더링 if (condition.type === "group-start") { return (
{/* 그룹 시작 앞의 논리 연산자 */} {condIndex > 0 && ( )}
( 그룹 시작
); } // 그룹 끝 렌더링 if (condition.type === "group-end") { return (
) 그룹 끝
); } // 일반 조건 렌더링 return (
{/* 그룹 내 첫 번째 조건이 아닐 때만 논리 연산자 표시 */} {condIndex > 0 && settings.actions[actionIndex].conditions![condIndex - 1]?.type !== "group-start" && ( )}
{/* 1단계: 테이블 선택 */} {/* 2단계: 선택된 테이블의 컬럼 선택 */} {renderConditionValue()}
); };