"use client"; /** * 검증 기능이 포함된 노드 래퍼 * * 모든 노드에 경고/에러 아이콘을 표시하는 공통 래퍼 */ import { memo, ReactNode } from "react"; import { AlertTriangle, AlertCircle, Info } from "lucide-react"; import type { FlowValidation } from "@/lib/utils/flowValidation"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "@/components/ui/tooltip"; interface NodeWithValidationProps { nodeId: string; validations: FlowValidation[]; children: ReactNode; onClick?: () => void; } export const NodeWithValidation = memo( ({ nodeId, validations, children, onClick }: NodeWithValidationProps) => { // 이 노드와 관련된 검증 결과 필터링 const nodeValidations = validations.filter( (v) => v.nodeId === nodeId || v.affectedNodes?.includes(nodeId) ); // 가장 높은 심각도 결정 const hasError = nodeValidations.some((v) => v.severity === "error"); const hasWarning = nodeValidations.some((v) => v.severity === "warning"); const hasInfo = nodeValidations.some((v) => v.severity === "info"); if (nodeValidations.length === 0) { return <>{children}; } // 심각도별 아이콘 및 색상 const getIconAndColor = () => { if (hasError) { return { Icon: AlertCircle, bgColor: "bg-red-500", textColor: "text-red-700", borderColor: "border-red-500", hoverBgColor: "hover:bg-red-600", }; } if (hasWarning) { return { Icon: AlertTriangle, bgColor: "bg-yellow-500", textColor: "text-yellow-700", borderColor: "border-yellow-500", hoverBgColor: "hover:bg-yellow-600", }; } return { Icon: Info, bgColor: "bg-blue-500", textColor: "text-blue-700", borderColor: "border-blue-500", hoverBgColor: "hover:bg-blue-600", }; }; const { Icon, bgColor, textColor, borderColor, hoverBgColor } = getIconAndColor(); return (
{children} {/* 경고 배지 */}
{nodeValidations.length > 1 && ( {nodeValidations.length} )}
{hasError ? "오류" : hasWarning ? "경고" : "정보"} ({nodeValidations.length})
{nodeValidations.map((validation, index) => (
{validation.type}
{validation.message}
{validation.affectedNodes && validation.affectedNodes.length > 1 && (
영향받는 노드: {validation.affectedNodes.length}개
)}
))}
); } ); NodeWithValidation.displayName = "NodeWithValidation";