From 0ac83b1551d85764546a056552d8f92047d0630b Mon Sep 17 00:00:00 2001 From: leeheejin Date: Thu, 15 Jan 2026 12:07:26 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B6=84=ED=95=A0=ED=8C=A8=EB=84=90=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=88=98=EC=A0=95=ED=95=B4=EB=8F=84=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EC=97=90=EC=84=9C=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=EA=B0=80=20=EC=95=88=EB=90=98=EB=8D=98=20=EB=AC=B8=EC=A0=9C=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UniversalFormModalComponent.tsx | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/frontend/lib/registry/components/universal-form-modal/UniversalFormModalComponent.tsx b/frontend/lib/registry/components/universal-form-modal/UniversalFormModalComponent.tsx index 57c50c58..939bb5d5 100644 --- a/frontend/lib/registry/components/universal-form-modal/UniversalFormModalComponent.tsx +++ b/frontend/lib/registry/components/universal-form-modal/UniversalFormModalComponent.tsx @@ -427,10 +427,17 @@ export function UniversalFormModalComponent({ } // 🆕 테이블 섹션 데이터 병합 (품목 리스트 등) + // 참고: initializeForm에서 DB 로드 시 __tableSection_ (더블), + // handleTableDataChange에서 수정 시 _tableSection_ (싱글) 사용 for (const [key, value] of Object.entries(formData)) { - if (key.startsWith("_tableSection_") && Array.isArray(value)) { - event.detail.formData[key] = value; - console.log(`[UniversalFormModal] 테이블 섹션 병합: ${key}, ${value.length}개 항목`); + // 싱글/더블 언더스코어 모두 처리 + if ((key.startsWith("_tableSection_") || key.startsWith("__tableSection_")) && Array.isArray(value)) { + // 저장 시에는 _tableSection_ 키로 통일 (buttonActions.ts에서 이 키를 기대) + const normalizedKey = key.startsWith("__tableSection_") + ? key.replace("__tableSection_", "_tableSection_") + : key; + event.detail.formData[normalizedKey] = value; + console.log(`[UniversalFormModal] 테이블 섹션 병합: ${key} → ${normalizedKey}, ${value.length}개 항목`); } } @@ -920,6 +927,19 @@ export function UniversalFormModalComponent({ const tableSectionKey = `__tableSection_${section.id}`; newFormData[tableSectionKey] = items; console.log(`[initializeForm] 테이블 섹션 ${section.id}: formData[${tableSectionKey}]에 저장됨`); + + // 🆕 원본 그룹 데이터 저장 (삭제 추적용) + // groupedDataInitializedRef가 false일 때만 설정 (true면 _groupedData useEffect에서 이미 처리됨) + // DB에서 로드한 데이터를 originalGroupedData에 저장해야 삭제 시 비교 가능 + if (!groupedDataInitializedRef.current) { + setOriginalGroupedData((prev) => { + const newOriginal = [...prev, ...JSON.parse(JSON.stringify(items))]; + console.log(`[initializeForm] 테이블 섹션 ${section.id}: originalGroupedData에 ${items.length}건 추가 (총 ${newOriginal.length}건)`); + return newOriginal; + }); + } else { + console.log(`[initializeForm] 테이블 섹션 ${section.id}: _groupedData로 이미 초기화됨, originalGroupedData 설정 스킵`); + } } } catch (error) { console.error(`[initializeForm] 테이블 섹션 ${section.id}: 디테일 데이터 로드 실패`, error);