리피터 데이터 저장 로직 개선 및 이벤트 처리 추가
- EditModal, InteractiveScreenViewer, SaveModal 컴포넌트에서 리피터 데이터(배열)를 마스터 저장에서 제외하고, 별도로 저장하는 로직을 추가하였습니다. - 리피터 데이터 저장 이벤트를 발생시켜 UnifiedRepeater 컴포넌트가 이를 리스닝하도록 개선하였습니다. - 각 컴포넌트에서 최종 저장 데이터 로그를 업데이트하여, 저장 과정에서의 데이터 흐름을 명확히 하였습니다. 이로 인해 데이터 저장의 효율성과 리피터 관리의 일관성이 향상되었습니다.
This commit is contained in:
@@ -90,6 +90,10 @@ export function SimpleRepeaterTableComponent({
|
||||
const newRowDefaults = componentConfig?.newRowDefaults || {};
|
||||
const summaryConfig = componentConfig?.summaryConfig;
|
||||
const maxHeight = componentConfig?.maxHeight || propMaxHeight || "240px";
|
||||
|
||||
// 🆕 컴포넌트 레벨의 저장 테이블 설정
|
||||
const componentTargetTable = componentConfig?.targetTable || componentConfig?.saveTable;
|
||||
const componentFkColumn = componentConfig?.fkColumn;
|
||||
|
||||
// value는 formData[columnName] 우선, 없으면 prop 사용
|
||||
const columnName = component?.columnName;
|
||||
@@ -289,7 +293,44 @@ export function SimpleRepeaterTableComponent({
|
||||
return;
|
||||
}
|
||||
|
||||
// 🆕 테이블별로 데이터 그룹화
|
||||
// 🆕 컴포넌트 레벨의 targetTable이 설정되어 있으면 우선 사용
|
||||
if (componentTargetTable) {
|
||||
console.log("✅ [SimpleRepeaterTable] 컴포넌트 레벨 저장 테이블 사용:", componentTargetTable);
|
||||
|
||||
// 모든 행을 해당 테이블에 저장
|
||||
const dataToSave = value.map((row: any) => {
|
||||
// 메타데이터 필드 제외 (_, _rowIndex 등)
|
||||
const cleanRow: Record<string, any> = {};
|
||||
Object.keys(row).forEach((key) => {
|
||||
if (!key.startsWith("_")) {
|
||||
cleanRow[key] = row[key];
|
||||
}
|
||||
});
|
||||
return {
|
||||
...cleanRow,
|
||||
_targetTable: componentTargetTable,
|
||||
};
|
||||
});
|
||||
|
||||
// CustomEvent의 detail에 데이터 추가
|
||||
if (event instanceof CustomEvent && event.detail) {
|
||||
const key = columnName || component?.id || "repeater_data";
|
||||
event.detail.formData[key] = dataToSave;
|
||||
console.log("✅ [SimpleRepeaterTable] 저장 데이터 준비:", {
|
||||
key,
|
||||
targetTable: componentTargetTable,
|
||||
itemCount: dataToSave.length,
|
||||
});
|
||||
}
|
||||
|
||||
// 기존 onFormDataChange도 호출 (호환성)
|
||||
if (onFormDataChange && columnName) {
|
||||
onFormDataChange(columnName, dataToSave);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 🆕 컬럼별 targetConfig가 있는 경우 기존 로직 사용
|
||||
const dataByTable: Record<string, any[]> = {};
|
||||
|
||||
for (const row of value) {
|
||||
@@ -318,6 +359,16 @@ export function SimpleRepeaterTableComponent({
|
||||
}
|
||||
}
|
||||
|
||||
// 컬럼별 설정도 없으면 기본 동작 (formData에 직접 추가)
|
||||
if (Object.keys(dataByTable).length === 0) {
|
||||
console.log("⚠️ [SimpleRepeaterTable] targetTable 설정 없음 - 기본 저장");
|
||||
if (event instanceof CustomEvent && event.detail) {
|
||||
const key = columnName || component?.id || "repeater_data";
|
||||
event.detail.formData[key] = value;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// _rowIndex 제거
|
||||
Object.keys(dataByTable).forEach((tableName) => {
|
||||
dataByTable[tableName] = dataByTable[tableName].map((row: any) => {
|
||||
@@ -360,7 +411,7 @@ export function SimpleRepeaterTableComponent({
|
||||
return () => {
|
||||
window.removeEventListener("beforeFormSave", handleSaveRequest as EventListener);
|
||||
};
|
||||
}, [value, columns, columnName, component?.id, onFormDataChange]);
|
||||
}, [value, columns, columnName, component?.id, onFormDataChange, componentTargetTable]);
|
||||
|
||||
const handleCellEdit = (rowIndex: number, field: string, cellValue: any) => {
|
||||
const newRow = { ...value[rowIndex], [field]: cellValue };
|
||||
|
||||
Reference in New Issue
Block a user