"use client"; import React from "react"; import { Handle, Position } from "@xyflow/react"; import { Monitor, Database, FormInput, Table2, LayoutDashboard, MousePointer2, Key, Link2, Columns3, } from "lucide-react"; import { ScreenLayoutSummary } from "@/lib/api/screenGroup"; // ========== 타입 정의 ========== // 화면 노드 데이터 인터페이스 export interface ScreenNodeData { label: string; subLabel?: string; type: "screen" | "table" | "action"; tableName?: string; isMain?: boolean; // 레이아웃 요약 정보 (미리보기용) layoutSummary?: ScreenLayoutSummary; } // 테이블 노드 데이터 인터페이스 export interface TableNodeData { label: string; subLabel?: string; isMain?: boolean; columns?: Array<{ name: string; type: string; isPrimaryKey?: boolean; isForeignKey?: boolean; }>; } // ========== 유틸리티 함수 ========== // 화면 타입별 아이콘 const getScreenTypeIcon = (screenType?: string) => { switch (screenType) { case "grid": return ; case "dashboard": return ; case "action": return ; default: return ; } }; // 화면 타입별 색상 (헤더) const getScreenTypeColor = (screenType?: string, isMain?: boolean) => { if (!isMain) return "bg-slate-400"; switch (screenType) { case "grid": return "bg-violet-500"; case "dashboard": return "bg-amber-500"; case "action": return "bg-rose-500"; default: return "bg-blue-500"; } }; // 화면 타입별 라벨 const getScreenTypeLabel = (screenType?: string) => { switch (screenType) { case "grid": return "그리드"; case "dashboard": return "대시보드"; case "action": return "액션"; default: return "폼"; } }; // ========== 화면 노드 (상단) - 미리보기 표시 ========== export const ScreenNode: React.FC<{ data: ScreenNodeData }> = ({ data }) => { const { label, subLabel, isMain, tableName, layoutSummary } = data; const screenType = layoutSummary?.screenType || "form"; const headerColor = getScreenTypeColor(screenType, isMain); return (
{/* Handles */} {/* 헤더 (컬러) */}
{label} {isMain && }
{/* 화면 미리보기 영역 (컴팩트) */}
{layoutSummary ? ( ) : (
{getScreenTypeIcon(screenType)} 화면: {label}
)}
{/* 필드 매핑 영역 */}
필드 매핑 {layoutSummary?.layoutItems?.filter(i => i.label && !i.componentKind?.includes('button')).length || 0}개
{layoutSummary?.layoutItems ?.filter(item => item.label && !item.componentKind?.includes('button')) ?.slice(0, 6) ?.map((item, idx) => (
{item.label} {item.componentKind?.split('-')[0] || 'field'}
)) || (
필드 정보 없음
)}
{/* 푸터 (테이블 정보) */}
{tableName || "No Table"}
{getScreenTypeLabel(screenType)}
); }; // ========== 컴포넌트 종류별 미니어처 색상 ========== // componentKind는 더 정확한 컴포넌트 타입 (table-list, button-primary 등) const getComponentColor = (componentKind: string) => { // 테이블/그리드 관련 if (componentKind === "table-list" || componentKind === "data-grid") { return "bg-violet-200 border-violet-400"; } // 검색 필터 if (componentKind === "table-search-widget" || componentKind === "search-filter") { return "bg-pink-200 border-pink-400"; } // 버튼 관련 if (componentKind?.includes("button")) { return "bg-blue-300 border-blue-500"; } // 입력 필드 if (componentKind?.includes("input") || componentKind?.includes("text")) { return "bg-slate-200 border-slate-400"; } // 셀렉트/드롭다운 if (componentKind?.includes("select") || componentKind?.includes("dropdown")) { return "bg-amber-200 border-amber-400"; } // 차트 if (componentKind?.includes("chart")) { return "bg-emerald-200 border-emerald-400"; } // 커스텀 위젯 if (componentKind === "custom") { return "bg-pink-200 border-pink-400"; } return "bg-slate-100 border-slate-300"; }; // ========== 화면 미리보기 컴포넌트 - 화면 타입별 간단한 일러스트 ========== const ScreenPreview: React.FC<{ layoutSummary: ScreenLayoutSummary; screenType: string }> = ({ layoutSummary, screenType, }) => { const { totalComponents, widgetCounts } = layoutSummary; // 그리드 화면 일러스트 if (screenType === "grid") { return (
{/* 상단 툴바 */}
{/* 테이블 헤더 */}
{[...Array(5)].map((_, i) => (
))}
{/* 테이블 행들 */}
{[...Array(7)].map((_, i) => (
{[...Array(5)].map((_, j) => (
))}
))}
{/* 페이지네이션 */}
{/* 컴포넌트 수 */}
{totalComponents}개
); } // 폼 화면 일러스트 if (screenType === "form") { return (
{/* 폼 필드들 */} {[...Array(6)].map((_, i) => (
))} {/* 버튼 영역 */}
{/* 컴포넌트 수 */}
{totalComponents}개
); } // 대시보드 화면 일러스트 if (screenType === "dashboard") { return (
{/* 카드/차트들 */}
{[...Array(10)].map((_, i) => (
))}
{/* 컴포넌트 수 */}
{totalComponents}개
); } // 액션 화면 일러스트 (버튼 중심) if (screenType === "action") { return (
액션 화면
{/* 컴포넌트 수 */}
{totalComponents}개
); } // 기본 (알 수 없는 타입) return (
{getScreenTypeIcon(screenType)}
{totalComponents}개 컴포넌트
); }; // ========== 테이블 노드 (하단) - 컬럼 목록 표시 ========== export const TableNode: React.FC<{ data: TableNodeData }> = ({ data }) => { const { label, subLabel, isMain, columns } = data; return (
{/* Handles */} {/* 헤더 (초록색) */}
{label}
{subLabel &&
{subLabel}
}
{/* 컬럼 목록 */}
{columns && columns.length > 0 ? (
{columns.map((col, idx) => (
{/* PK/FK 아이콘 */} {col.isPrimaryKey && } {col.isForeignKey && !col.isPrimaryKey && } {!col.isPrimaryKey && !col.isForeignKey &&
} {/* 컬럼명 */} {col.name} {/* 타입 */} {col.type}
))} {columns.length > 8 && (
... 외 {columns.length - 8}개 컬럼
)}
) : (
컬럼 정보 없음
)}
{/* 푸터 */}
PostgreSQL {columns && ( {columns.length}개 컬럼 )}
); }; // ========== 기존 호환성 유지용 ========== export const LegacyScreenNode = ScreenNode; export const AggregateNode: React.FC<{ data: any }> = ({ data }) => { return (
{data.label || "Aggregate"}
); };