From c23d372bcd2a28baf0e0233cd33f4b333bffbe01 Mon Sep 17 00:00:00 2001 From: dohyeons Date: Thu, 2 Oct 2025 13:52:19 +0900 Subject: [PATCH] =?UTF-8?q?=EC=BA=94=EB=B2=84=EC=8A=A4=EC=97=90=20?= =?UTF-8?q?=EC=BB=B4=ED=8F=AC=EB=84=8C=ED=8A=B8=EA=B0=80=20=EB=B0=B0?= =?UTF-8?q?=EC=B9=98=20=EC=95=88=EB=90=98=EB=8A=94=20=EB=AC=B8=EC=A0=9C=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/contexts/ReportDesignerContext.tsx | 101 ++++++++++---------- frontend/types/report.ts | 1 + 2 files changed, 50 insertions(+), 52 deletions(-) diff --git a/frontend/contexts/ReportDesignerContext.tsx b/frontend/contexts/ReportDesignerContext.tsx index 301a66c5..f3bd68dc 100644 --- a/frontend/contexts/ReportDesignerContext.tsx +++ b/frontend/contexts/ReportDesignerContext.tsx @@ -1016,49 +1016,54 @@ export function ReportDesignerProvider({ reportId, children }: { reportId: strin const layoutData = layoutResponse.data; setLayout(layoutData); - // 자동 마이그레이션: 기존 단일 페이지 구조 → 다중 페이지 구조 - const oldComponents = layoutData.components || []; - - // 기존 구조 감지 - if (oldComponents.length > 0) { - const migratedPageId = uuidv4(); - const migratedPage: ReportPage = { - page_id: migratedPageId, - page_name: "페이지 1", - page_order: 0, - width: layoutData.canvas_width || 210, - height: layoutData.canvas_height || 297, - orientation: (layoutData.page_orientation as "portrait" | "landscape") || "portrait", - margins: { - top: layoutData.margin_top || 20, - bottom: layoutData.margin_bottom || 20, - left: layoutData.margin_left || 20, - right: layoutData.margin_right || 20, - }, - background_color: "#ffffff", - components: oldComponents, - }; - - setLayoutConfig({ pages: [migratedPage] }); - setCurrentPageId(migratedPageId); - - console.log("✅ 기존 레이아웃을 페이지 구조로 자동 마이그레이션", migratedPage); + // layoutData가 이미 pages를 가지고 있는지 확인 + if (layoutData.pages && Array.isArray(layoutData.pages) && layoutData.pages.length > 0) { + // 이미 새 구조 (pages 배열) + setLayoutConfig({ pages: layoutData.pages }); + setCurrentPageId(layoutData.pages[0].page_id); } else { - // 빈 레이아웃 - 기본 페이지 생성 - const defaultPageId = uuidv4(); - const defaultPage: ReportPage = { - page_id: defaultPageId, - page_name: "페이지 1", - page_order: 0, - width: 210, - height: 297, - orientation: "portrait", - margins: { top: 20, bottom: 20, left: 20, right: 20 }, - background_color: "#ffffff", - components: [], - }; - setLayoutConfig({ pages: [defaultPage] }); - setCurrentPageId(defaultPageId); + // 자동 마이그레이션: 기존 단일 페이지 구조 → 다중 페이지 구조 + const oldComponents = layoutData.components || []; + + // 기존 구조 감지 + if (oldComponents.length > 0) { + const migratedPageId = uuidv4(); + const migratedPage: ReportPage = { + page_id: migratedPageId, + page_name: "페이지 1", + page_order: 0, + width: layoutData.canvas_width || 210, + height: layoutData.canvas_height || 297, + orientation: (layoutData.page_orientation as "portrait" | "landscape") || "portrait", + margins: { + top: layoutData.margin_top || 20, + bottom: layoutData.margin_bottom || 20, + left: layoutData.margin_left || 20, + right: layoutData.margin_right || 20, + }, + background_color: "#ffffff", + components: oldComponents, + }; + + setLayoutConfig({ pages: [migratedPage] }); + setCurrentPageId(migratedPageId); + } else { + // 빈 레이아웃 - 기본 페이지 생성 + const defaultPageId = uuidv4(); + const defaultPage: ReportPage = { + page_id: defaultPageId, + page_name: "페이지 1", + page_order: 0, + width: 210, + height: 297, + orientation: "portrait", + margins: { top: 20, bottom: 20, left: 20, right: 20 }, + background_color: "#ffffff", + components: [], + }; + setLayoutConfig({ pages: [defaultPage] }); + setCurrentPageId(defaultPageId); + } } } } catch { @@ -1077,7 +1082,6 @@ export function ReportDesignerProvider({ reportId, children }: { reportId: strin }; setLayoutConfig({ pages: [defaultPage] }); setCurrentPageId(defaultPageId); - console.log("레이아웃 없음, 기본 페이지 생성"); } } catch (error) { const errorMessage = error instanceof Error ? error.message : "리포트를 불러오는데 실패했습니다."; @@ -1146,19 +1150,12 @@ export function ReportDesignerProvider({ reportId, children }: { reportId: strin [queryResults], ); - // 컴포넌트 추가 // 컴포넌트 추가 (현재 페이지에) const addComponent = useCallback( (component: ComponentConfig) => { - if (!currentPageId) return; - - setLayoutConfig((prev) => ({ - pages: prev.pages.map((page) => - page.page_id === currentPageId ? { ...page, components: [...page.components, component] } : page, - ), - })); + setComponents((prev) => [...prev, component]); }, - [currentPageId], + [setComponents], ); // 컴포넌트 업데이트 (현재 페이지에서) diff --git a/frontend/types/report.ts b/frontend/types/report.ts index 90532717..2c720d77 100644 --- a/frontend/types/report.ts +++ b/frontend/types/report.ts @@ -49,6 +49,7 @@ export interface ReportLayout { margin_left: number; margin_right: number; components: ComponentConfig[]; + pages?: ReportPage[]; // 새 페이지 구조 (옵셔널, 하위 호환성) created_at: string; created_by: string | null; updated_at: string | null;