From 1680163c612c6a4e13375ec61b4d19be49c8e834 Mon Sep 17 00:00:00 2001 From: SeongHyun Kim Date: Fri, 12 Dec 2025 11:10:51 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20ModalRepeaterTable=20=EB=B9=88=20?= =?UTF-8?q?=ED=96=89=20=EC=9E=90=EB=8F=99=20=ED=91=9C=EC=8B=9C=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 신규 등록 모달 오픈 시 빈 객체 필터링 기능 추가 - isEmptyRow 함수로 안전한 빈 객체 판단 (id 필드 체크) - useState 초기화 및 useEffect 동기화에 필터링 적용 - 수정 모달의 실제 데이터는 id 필드로 보호 --- .../ModalRepeaterTableComponent.tsx | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/frontend/lib/registry/components/modal-repeater-table/ModalRepeaterTableComponent.tsx b/frontend/lib/registry/components/modal-repeater-table/ModalRepeaterTableComponent.tsx index 92eb4bb7..64c9e95f 100644 --- a/frontend/lib/registry/components/modal-repeater-table/ModalRepeaterTableComponent.tsx +++ b/frontend/lib/registry/components/modal-repeater-table/ModalRepeaterTableComponent.tsx @@ -198,14 +198,43 @@ export function ModalRepeaterTableComponent({ const columnName = component?.columnName; const externalValue = (columnName && formData?.[columnName]) || componentConfig?.value || propValue || []; + // 빈 객체 판단 함수 (수정 모달의 실제 데이터는 유지) + const isEmptyRow = (item: any): boolean => { + if (!item || typeof item !== 'object') return true; + + // id가 있으면 실제 데이터 (수정 모달) + if (item.id) return false; + + // 모든 값이 비어있는지 확인 (계산 필드 제외) + const hasValue = Object.entries(item).some(([key, value]) => { + // 계산 필드나 메타데이터는 제외 + if (key.startsWith('_') || key === 'total_amount') return false; + + // 실제 값이 있는지 확인 + return value !== undefined && + value !== null && + value !== '' && + value !== 0 && + value !== '0' && + value !== '0.00'; + }); + + return !hasValue; + }; + // 🆕 내부 상태로 데이터 관리 (즉시 UI 반영을 위해) - const [localValue, setLocalValue] = useState(externalValue); + const [localValue, setLocalValue] = useState(() => { + return externalValue.filter((item) => !isEmptyRow(item)); + }); // 🆕 외부 값(formData, propValue) 변경 시 내부 상태 동기화 useEffect(() => { + // 빈 객체 필터링 + const filteredValue = externalValue.filter((item) => !isEmptyRow(item)); + // 외부 값이 변경되었고, 내부 값과 다른 경우에만 동기화 - if (JSON.stringify(externalValue) !== JSON.stringify(localValue)) { - setLocalValue(externalValue); + if (JSON.stringify(filteredValue) !== JSON.stringify(localValue)) { + setLocalValue(filteredValue); } }, [externalValue]);