"use client"; /** * 집계 노드 (Aggregate Node) * SUM, COUNT, AVG, MIN, MAX 등 집계 연산을 수행 */ import { memo } from "react"; import { Handle, Position, NodeProps } from "reactflow"; import { Calculator, Layers } from "lucide-react"; import type { AggregateNodeData, AggregateFunction } from "@/types/node-editor"; // 집계 함수별 아이콘/라벨 const AGGREGATE_FUNCTION_LABELS: Record = { SUM: "합계", COUNT: "개수", AVG: "평균", MIN: "최소", MAX: "최대", FIRST: "첫번째", LAST: "마지막", }; export const AggregateNode = memo(({ data, selected }: NodeProps) => { const groupByCount = data.groupByFields?.length || 0; const aggregationCount = data.aggregations?.length || 0; return (
{/* 헤더 */}
{data.displayName || "집계"}
{groupByCount > 0 ? `${groupByCount}개 그룹` : "전체"} / {aggregationCount}개 집계
{/* 본문 */}
{/* 그룹 기준 */} {groupByCount > 0 && (
그룹 기준
{data.groupByFields.slice(0, 3).map((field, idx) => ( {field.fieldLabel || field.field} ))} {data.groupByFields.length > 3 && ( +{data.groupByFields.length - 3} )}
)} {/* 집계 연산 */} {aggregationCount > 0 ? (
{data.aggregations.slice(0, 4).map((agg, idx) => (
{AGGREGATE_FUNCTION_LABELS[agg.function] || agg.function} {agg.outputFieldLabel || agg.outputField}
{agg.sourceFieldLabel || agg.sourceField}
))} {data.aggregations.length > 4 && (
... 외 {data.aggregations.length - 4}개
)}
) : (
집계 연산 없음
)}
{/* 핸들 */}
); }); AggregateNode.displayName = "AggregateNode";