"use client"; import React, { useState, useMemo, useEffect } from "react"; import { Label } from "@/components/ui/label"; import { Input } from "@/components/ui/input"; import { Switch } from "@/components/ui/switch"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Slider } from "@/components/ui/slider"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem } from "@/components/ui/command"; import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; import { Button } from "@/components/ui/button"; import { Check, ChevronsUpDown, ArrowRight } from "lucide-react"; import { cn } from "@/lib/utils"; import { SplitPanelLayoutConfig } from "./types"; import { TableInfo } from "@/types/screen"; interface SplitPanelLayoutConfigPanelProps { config: SplitPanelLayoutConfig; onChange: (config: SplitPanelLayoutConfig) => void; tables?: TableInfo[]; // 전체 테이블 목록 (선택적) screenTableName?: string; // 현재 화면의 테이블명 (좌측 패널에서 사용) } /** * SplitPanelLayout 설정 패널 */ export const SplitPanelLayoutConfigPanel: React.FC = ({ config, onChange, tables = [], // 기본값 빈 배열 screenTableName, // 현재 화면의 테이블명 }) => { const [rightTableOpen, setRightTableOpen] = useState(false); const [leftColumnOpen, setLeftColumnOpen] = useState(false); const [rightColumnOpen, setRightColumnOpen] = useState(false); // screenTableName이 변경되면 leftPanel.tableName 자동 업데이트 useEffect(() => { if (screenTableName) { // 좌측 패널 테이블명 업데이트 if (config.leftPanel?.tableName !== screenTableName) { updateLeftPanel({ tableName: screenTableName }); } // 관계 타입이 detail이면 우측 패널도 동일한 테이블 사용 const relationshipType = config.rightPanel?.relation?.type || "detail"; if (relationshipType === "detail" && config.rightPanel?.tableName !== screenTableName) { updateRightPanel({ tableName: screenTableName }); } } // eslint-disable-next-line react-hooks/exhaustive-deps }, [screenTableName]); console.log("🔧 SplitPanelLayoutConfigPanel 렌더링"); console.log(" - config:", config); console.log(" - tables:", tables); console.log(" - tablesCount:", tables.length); console.log(" - screenTableName:", screenTableName); console.log(" - leftTable:", config.leftPanel?.tableName); console.log(" - rightTable:", config.rightPanel?.tableName); const updateConfig = (updates: Partial) => { const newConfig = { ...config, ...updates }; console.log("🔄 Config 업데이트:", newConfig); onChange(newConfig); }; const updateLeftPanel = (updates: Partial) => { const newConfig = { ...config, leftPanel: { ...config.leftPanel, ...updates }, }; console.log("🔄 Left Panel 업데이트:", newConfig); onChange(newConfig); }; const updateRightPanel = (updates: Partial) => { const newConfig = { ...config, rightPanel: { ...config.rightPanel, ...updates }, }; console.log("🔄 Right Panel 업데이트:", newConfig); onChange(newConfig); }; // 좌측 테이블은 현재 화면의 테이블 (screenTableName) 사용 const leftTableColumns = useMemo(() => { const tableName = screenTableName || config.leftPanel?.tableName; const table = tables.find((t) => t.tableName === tableName); return table?.columns || []; }, [tables, screenTableName, config.leftPanel?.tableName]); // 우측 테이블의 컬럼 목록 가져오기 const rightTableColumns = useMemo(() => { const table = tables.find((t) => t.tableName === config.rightPanel?.tableName); return table?.columns || []; }, [tables, config.rightPanel?.tableName]); // 테이블 데이터 로딩 상태 확인 if (!tables || tables.length === 0) { return (

⚠️ 테이블 데이터를 불러올 수 없습니다.

화면에 테이블이 연결되지 않았거나 테이블 목록이 로드되지 않았습니다.

); } // 관계 타입에 따라 우측 테이블을 자동으로 설정 const relationshipType = config.rightPanel?.relation?.type || "detail"; return (
{/* 테이블 정보 표시 */}

📊 사용 가능한 테이블: {tables.length}개

{/* 관계 타입 선택 (최상단) */}
1

패널 관계 타입 선택

좌측과 우측 패널 간의 데이터 관계를 선택하세요

{/* 좌측 패널 설정 (마스터) */}
2

좌측 패널 설정 (마스터)

updateLeftPanel({ title: e.target.value })} placeholder="좌측 패널 제목" />

{screenTableName || "테이블이 지정되지 않음"}

좌측 패널은 현재 화면의 테이블 데이터를 표시합니다

updateLeftPanel({ showSearch: checked })} />
updateLeftPanel({ showAdd: checked })} />
{/* 우측 패널 설정 */}
3

우측 패널 설정 ({relationshipType === "detail" ? "상세" : relationshipType === "join" ? "조인" : "커스텀"})

updateRightPanel({ title: e.target.value })} placeholder="우측 패널 제목" />
{/* 관계 타입에 따라 테이블 선택 UI 변경 */} {relationshipType === "detail" ? ( // 상세 모드: 좌측과 동일한 테이블 (비활성화)

{screenTableName || "테이블이 지정되지 않음"}

상세 모드에서는 좌측과 동일한 테이블을 사용합니다

) : ( // 조인/커스텀 모드: 전체 테이블에서 선택 가능
테이블을 찾을 수 없습니다. {tables.map((table) => ( { updateRightPanel({ tableName: value }); setRightTableOpen(false); }} > {table.tableName} ({table.tableLabel || ""}) ))}
)} {/* 컬럼 매핑 - 조인/커스텀 모드에서만 표시 */} {relationshipType !== "detail" && (

좌측 테이블의 컬럼을 우측 테이블의 컬럼과 연결합니다

컬럼을 찾을 수 없습니다. {leftTableColumns.map((column) => ( { updateRightPanel({ relation: { ...config.rightPanel?.relation, leftColumn: value }, }); setLeftColumnOpen(false); }} > {column.columnName} ({column.columnLabel || ""}) ))}
컬럼을 찾을 수 없습니다. {rightTableColumns.map((column) => ( { updateRightPanel({ relation: { ...config.rightPanel?.relation, foreignKey: value }, }); setRightColumnOpen(false); }} > {column.columnName} ({column.columnLabel || ""}) ))}
)}
updateRightPanel({ showSearch: checked })} />
updateRightPanel({ showAdd: checked })} />
{/* 레이아웃 설정 */}
4

레이아웃 설정

updateConfig({ splitRatio: value[0] })} min={20} max={80} step={5} />
updateConfig({ resizable: checked })} />
updateConfig({ autoLoad: checked })} />
); };