"use client"; import React from "react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Trash2 } from "lucide-react"; import { ConditionNode, ColumnInfo } from "@/lib/api/dataflow"; import { getInputTypeForDataType } from "@/utils/connectionUtils"; interface ConditionRendererProps { conditions: ConditionNode[]; fromTableColumns: ColumnInfo[]; onUpdateCondition: (index: number, field: keyof ConditionNode, value: string) => void; onRemoveCondition: (index: number) => void; getCurrentGroupLevel: (index: number) => number; } export const ConditionRenderer: React.FC = ({ conditions, fromTableColumns, onUpdateCondition, onRemoveCondition, getCurrentGroupLevel, }) => { const renderConditionValue = (condition: ConditionNode, index: number) => { const selectedColumn = fromTableColumns.find((col) => col.columnName === condition.field); const dataType = selectedColumn?.dataType?.toLowerCase() || "string"; const inputType = getInputTypeForDataType(dataType); if (dataType.includes("bool")) { return ( ); } else { return ( onUpdateCondition(index, "value", e.target.value)} className="h-8 flex-1 text-xs" /> ); } }; return (
{conditions.length === 0 ? (
조건을 추가하면 해당 조건을 만족할 때만 실행됩니다.
조건이 없으면 항상 실행됩니다.
) : ( {conditions.map((condition, index) => { // 그룹 시작 렌더링 if (condition.type === "group-start") { return (
{/* 그룹 시작 앞의 논리 연산자 - 이전 요소가 group-end가 아닌 경우에만 표시 */} {index > 0 && conditions[index - 1]?.type !== "group-end" && ( )} {/* 그룹 레벨에 따른 들여쓰기 */}
( 그룹 시작
); } // 그룹 끝 렌더링 if (condition.type === "group-end") { return (
) 그룹 끝
{/* 그룹 끝 다음에 다른 조건이나 그룹이 있으면 논리 연산자 표시 */} {index < conditions.length - 1 && ( )}
); } // 일반 조건 렌더링 return (
{/* 일반 조건 앞의 논리 연산자 - 이전 요소가 group-end가 아닌 경우에만 표시 */} {index > 0 && conditions[index - 1]?.type !== "group-start" && conditions[index - 1]?.type !== "group-end" && ( )} {/* 그룹 레벨에 따른 들여쓰기와 조건 필드들 */}
{/* 조건 필드 선택 */} {/* 연산자 선택 */} {/* 값 입력 */} {renderConditionValue(condition, index)} {/* 삭제 버튼 */}
); })}
)}
); };