"use client"; import { useState, useEffect } from "react"; import { ScreenDefinition } from "@/types/screen"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Separator } from "@/components/ui/separator"; import { Database, Monitor, ArrowRight, Link2, Table, Columns, ExternalLink, Layers, GitBranch } from "lucide-react"; import { getFieldJoins, getDataFlows, getTableRelations, FieldJoin, DataFlow, TableRelation } from "@/lib/api/screenGroup"; import { screenApi } from "@/lib/api/screen"; interface ScreenRelationViewProps { screen: ScreenDefinition | null; } export function ScreenRelationView({ screen }: ScreenRelationViewProps) { const [loading, setLoading] = useState(false); const [fieldJoins, setFieldJoins] = useState([]); const [dataFlows, setDataFlows] = useState([]); const [tableRelations, setTableRelations] = useState([]); const [layoutInfo, setLayoutInfo] = useState(null); useEffect(() => { const loadRelations = async () => { if (!screen) { setFieldJoins([]); setDataFlows([]); setTableRelations([]); setLayoutInfo(null); return; } try { setLoading(true); // 병렬로 데이터 로드 const [joinsRes, flowsRes, relationsRes, layoutRes] = await Promise.all([ getFieldJoins(screen.screenId), getDataFlows(screen.screenId), getTableRelations(screen.screenId), screenApi.getLayout(screen.screenId).catch(() => null), ]); if (joinsRes.success && joinsRes.data) { setFieldJoins(joinsRes.data); } if (flowsRes.success && flowsRes.data) { setDataFlows(flowsRes.data); } if (relationsRes.success && relationsRes.data) { setTableRelations(relationsRes.data); } if (layoutRes) { setLayoutInfo(layoutRes); } } catch (error) { console.error("관계 정보 로드 실패:", error); } finally { setLoading(false); } }; loadRelations(); }, [screen?.screenId]); if (!screen) { return (

화면을 선택하세요

왼쪽 트리에서 화면을 선택하면 데이터 관계가 표시됩니다

); } if (loading) { return (
로딩 중...
); } // 컴포넌트에서 사용하는 테이블 분석 const getUsedTables = () => { const tables = new Set(); if (screen.tableName) { tables.add(screen.tableName); } if (layoutInfo?.components) { layoutInfo.components.forEach((comp: any) => { if (comp.properties?.tableName) { tables.add(comp.properties.tableName); } if (comp.properties?.dataSource?.tableName) { tables.add(comp.properties.dataSource.tableName); } }); } return Array.from(tables); }; const usedTables = getUsedTables(); return (
{/* 화면 기본 정보 */}

{screen.screenName}

{screen.screenCode} {screen.screenType}
{screen.description && (

{screen.description}

)}
{/* 연결된 테이블 */} 연결된 테이블 {usedTables.length > 0 ? (
{usedTables.map((tableName, index) => (
{tableName} {tableName === screen.tableName && ( 메인 )} ))} ) : (

연결된 테이블이 없습니다

)} {/* 필드 조인 관계 */} 필드 조인 관계 {fieldJoins.length > 0 && ( {fieldJoins.length} )} {fieldJoins.length > 0 ? (
{fieldJoins.map((join) => (
{join.sourceTable} . {join.sourceColumn}
{join.targetTable} . {join.targetColumn}
{join.joinType}
))}
) : (

설정된 조인이 없습니다

)}
{/* 데이터 흐름 */} 데이터 흐름 {dataFlows.length > 0 && ( {dataFlows.length} )} {dataFlows.length > 0 ? (
{dataFlows.map((flow) => (
{flow.flowName || "이름 없음"} 화면 #{flow.targetScreenId} {flow.flowType}
))}
) : (

설정된 데이터 흐름이 없습니다

)}
{/* 테이블 관계 */} 테이블 관계 {tableRelations.length > 0 && ( {tableRelations.length} )} {tableRelations.length > 0 ? (
{tableRelations.map((relation) => (
{relation.parentTable} {relation.childTable} {relation.relationType} ))} ) : (

설정된 테이블 관계가 없습니다

)} {/* 빠른 작업 */}

더블클릭하면 화면 디자이너로 이동합니다

); }