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);