fix: SplitPanelLayout 그룹 삭제 시 groupByColumns 기준 삭제 및 멀티테넌시 보호 추가(영업관리_거래처별 품목 등록 등에서,,)
This commit is contained in:
@@ -1613,47 +1613,89 @@ export const SplitPanelLayoutComponent: React.FC<SplitPanelLayoutComponentProps>
|
||||
try {
|
||||
console.log("🗑️ 데이터 삭제:", { tableName, primaryKey });
|
||||
|
||||
// 🔍 중복 제거 설정 디버깅
|
||||
console.log("🔍 중복 제거 디버깅:", {
|
||||
// 🔍 그룹 삭제 설정 확인 (editButton.groupByColumns 또는 deduplication)
|
||||
const groupByColumns = componentConfig.rightPanel?.editButton?.groupByColumns || [];
|
||||
const deduplication = componentConfig.rightPanel?.dataFilter?.deduplication;
|
||||
|
||||
console.log("🔍 삭제 설정 디버깅:", {
|
||||
panel: deleteModalPanel,
|
||||
dataFilter: componentConfig.rightPanel?.dataFilter,
|
||||
deduplication: componentConfig.rightPanel?.dataFilter?.deduplication,
|
||||
enabled: componentConfig.rightPanel?.dataFilter?.deduplication?.enabled,
|
||||
groupByColumns,
|
||||
deduplication,
|
||||
deduplicationEnabled: deduplication?.enabled,
|
||||
});
|
||||
|
||||
let result;
|
||||
|
||||
// 🔧 중복 제거가 활성화된 경우, groupByColumn 기준으로 모든 관련 레코드 삭제
|
||||
if (deleteModalPanel === "right" && componentConfig.rightPanel?.dataFilter?.deduplication?.enabled) {
|
||||
const deduplication = componentConfig.rightPanel.dataFilter.deduplication;
|
||||
const groupByColumn = deduplication.groupByColumn;
|
||||
|
||||
if (groupByColumn && deleteModalItem[groupByColumn]) {
|
||||
const groupValue = deleteModalItem[groupByColumn];
|
||||
console.log(`🔗 중복 제거 활성화: ${groupByColumn} = ${groupValue} 기준으로 모든 레코드 삭제`);
|
||||
|
||||
// groupByColumn 값으로 필터링하여 삭제
|
||||
const filterConditions: Record<string, any> = {
|
||||
[groupByColumn]: groupValue,
|
||||
};
|
||||
|
||||
// 좌측 패널의 선택된 항목 정보도 포함 (customer_id 등)
|
||||
if (selectedLeftItem && componentConfig.rightPanel?.mode === "join") {
|
||||
const leftColumn = componentConfig.rightPanel.join.leftColumn;
|
||||
const rightColumn = componentConfig.rightPanel.join.rightColumn;
|
||||
filterConditions[rightColumn] = selectedLeftItem[leftColumn];
|
||||
// 🔧 우측 패널 삭제 시 그룹 삭제 조건 확인
|
||||
if (deleteModalPanel === "right") {
|
||||
// 1. groupByColumns가 설정된 경우 (패널 설정에서 선택된 컬럼들)
|
||||
if (groupByColumns.length > 0) {
|
||||
const filterConditions: Record<string, any> = {};
|
||||
|
||||
// 선택된 컬럼들의 값을 필터 조건으로 추가
|
||||
for (const col of groupByColumns) {
|
||||
if (deleteModalItem[col] !== undefined && deleteModalItem[col] !== null) {
|
||||
filterConditions[col] = deleteModalItem[col];
|
||||
}
|
||||
}
|
||||
|
||||
console.log("🗑️ 그룹 삭제 조건:", filterConditions);
|
||||
// 🔒 안전장치: 조인 모드에서 좌측 패널의 키 값도 필터 조건에 포함
|
||||
// (다른 거래처의 같은 품목이 삭제되는 것을 방지)
|
||||
if (selectedLeftItem && componentConfig.rightPanel?.mode === "join") {
|
||||
const leftColumn = componentConfig.rightPanel.join?.leftColumn;
|
||||
const rightColumn = componentConfig.rightPanel.join?.rightColumn;
|
||||
if (leftColumn && rightColumn && selectedLeftItem[leftColumn]) {
|
||||
// rightColumn이 filterConditions에 없으면 추가
|
||||
if (!filterConditions[rightColumn]) {
|
||||
filterConditions[rightColumn] = selectedLeftItem[leftColumn];
|
||||
console.log(`🔒 안전장치: ${rightColumn} = ${selectedLeftItem[leftColumn]} 추가`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 그룹 삭제 API 호출
|
||||
result = await dataApi.deleteGroupRecords(tableName, filterConditions);
|
||||
} else {
|
||||
// 단일 레코드 삭제
|
||||
// 필터 조건이 있으면 그룹 삭제
|
||||
if (Object.keys(filterConditions).length > 0) {
|
||||
console.log(`🔗 그룹 삭제 (groupByColumns): ${groupByColumns.join(", ")} 기준`);
|
||||
console.log("🗑️ 그룹 삭제 조건:", filterConditions);
|
||||
|
||||
result = await dataApi.deleteGroupRecords(tableName, filterConditions);
|
||||
} else {
|
||||
// 필터 조건이 없으면 단일 삭제
|
||||
console.log("⚠️ groupByColumns 값이 없어 단일 삭제로 전환");
|
||||
result = await dataApi.deleteRecord(tableName, primaryKey);
|
||||
}
|
||||
}
|
||||
// 2. 중복 제거(deduplication)가 활성화된 경우
|
||||
else if (deduplication?.enabled && deduplication?.groupByColumn) {
|
||||
const groupByColumn = deduplication.groupByColumn;
|
||||
const groupValue = deleteModalItem[groupByColumn];
|
||||
|
||||
if (groupValue) {
|
||||
console.log(`🔗 중복 제거 활성화: ${groupByColumn} = ${groupValue} 기준으로 모든 레코드 삭제`);
|
||||
|
||||
const filterConditions: Record<string, any> = {
|
||||
[groupByColumn]: groupValue,
|
||||
};
|
||||
|
||||
// 좌측 패널의 선택된 항목 정보도 포함 (customer_id 등)
|
||||
if (selectedLeftItem && componentConfig.rightPanel?.mode === "join") {
|
||||
const leftColumn = componentConfig.rightPanel.join.leftColumn;
|
||||
const rightColumn = componentConfig.rightPanel.join.rightColumn;
|
||||
filterConditions[rightColumn] = selectedLeftItem[leftColumn];
|
||||
}
|
||||
|
||||
console.log("🗑️ 그룹 삭제 조건:", filterConditions);
|
||||
result = await dataApi.deleteGroupRecords(tableName, filterConditions);
|
||||
} else {
|
||||
result = await dataApi.deleteRecord(tableName, primaryKey);
|
||||
}
|
||||
}
|
||||
// 3. 그 외: 단일 레코드 삭제
|
||||
else {
|
||||
result = await dataApi.deleteRecord(tableName, primaryKey);
|
||||
}
|
||||
} else {
|
||||
// 단일 레코드 삭제
|
||||
// 좌측 패널: 단일 레코드 삭제
|
||||
result = await dataApi.deleteRecord(tableName, primaryKey);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user