제어관리 개선판
This commit is contained in:
@@ -15,7 +15,18 @@ export interface ButtonExecutionContext {
|
||||
formData: Record<string, any>;
|
||||
selectedRows?: any[];
|
||||
selectedRowsData?: Record<string, any>[];
|
||||
controlDataSource?: "form" | "table-selection" | "both";
|
||||
controlDataSource?: "form" | "table-selection" | "table-all" | "flow-selection" | "flow-step-all" | "both" | "all-sources";
|
||||
|
||||
// 🆕 테이블 전체 데이터 (table-all 모드용)
|
||||
tableAllData?: Record<string, any>[];
|
||||
|
||||
// 🆕 플로우 스텝 전체 데이터 (flow-step-all 모드용)
|
||||
flowStepAllData?: Record<string, any>[];
|
||||
flowStepId?: number;
|
||||
|
||||
// 🆕 플로우 선택 데이터 (flow-selection 모드용)
|
||||
flowSelectedData?: Record<string, any>[];
|
||||
|
||||
onRefresh?: () => void;
|
||||
onClose?: () => void;
|
||||
}
|
||||
@@ -141,15 +152,134 @@ export async function executeButtonWithFlow(
|
||||
* 컨텍스트 데이터 준비
|
||||
*/
|
||||
function prepareContextData(context: ButtonExecutionContext): Record<string, any> {
|
||||
return {
|
||||
// 🔥 controlDataSource 자동 감지 (명시적으로 설정되지 않은 경우)
|
||||
let dataSource = context.controlDataSource;
|
||||
|
||||
if (!dataSource) {
|
||||
// 1. 플로우 선택 데이터가 있으면 flow-selection
|
||||
if (context.flowSelectedData && context.flowSelectedData.length > 0) {
|
||||
dataSource = "flow-selection";
|
||||
logger.info("🔄 자동 판단: flow-selection 모드 사용", {
|
||||
flowSelectedDataLength: context.flowSelectedData.length,
|
||||
});
|
||||
}
|
||||
// 2. 플로우 스텝 전체 데이터가 있으면 flow-step-all
|
||||
else if (context.flowStepAllData && context.flowStepAllData.length > 0) {
|
||||
dataSource = "flow-step-all";
|
||||
logger.info("🔄 자동 판단: flow-step-all 모드 사용", {
|
||||
flowStepAllDataLength: context.flowStepAllData.length,
|
||||
});
|
||||
}
|
||||
// 3. 테이블 선택 데이터가 있으면 table-selection
|
||||
else if (context.selectedRowsData && context.selectedRowsData.length > 0) {
|
||||
dataSource = "table-selection";
|
||||
logger.info("🔄 자동 판단: table-selection 모드 사용", {
|
||||
selectedRowsDataLength: context.selectedRowsData.length,
|
||||
});
|
||||
}
|
||||
// 4. 테이블 전체 데이터가 있으면 table-all
|
||||
else if (context.tableAllData && context.tableAllData.length > 0) {
|
||||
dataSource = "table-all";
|
||||
logger.info("🔄 자동 판단: table-all 모드 사용", {
|
||||
tableAllDataLength: context.tableAllData.length,
|
||||
});
|
||||
}
|
||||
// 5. 폼 데이터만 있으면 form
|
||||
else {
|
||||
dataSource = "form";
|
||||
logger.info("🔄 자동 판단: form 모드 사용");
|
||||
}
|
||||
}
|
||||
|
||||
const baseContext = {
|
||||
buttonId: context.buttonId,
|
||||
screenId: context.screenId,
|
||||
companyCode: context.companyCode,
|
||||
userId: context.userId,
|
||||
formData: context.formData || {},
|
||||
selectedRowsData: context.selectedRowsData || [],
|
||||
controlDataSource: context.controlDataSource || "form",
|
||||
controlDataSource: dataSource,
|
||||
};
|
||||
|
||||
// 데이터 소스에 따라 데이터 준비
|
||||
|
||||
switch (dataSource) {
|
||||
case "form":
|
||||
return {
|
||||
...baseContext,
|
||||
formData: context.formData || {},
|
||||
sourceData: [context.formData || {}], // 배열로 통일
|
||||
};
|
||||
|
||||
case "table-selection":
|
||||
return {
|
||||
...baseContext,
|
||||
formData: context.formData || {},
|
||||
selectedRowsData: context.selectedRowsData || [],
|
||||
sourceData: context.selectedRowsData || [],
|
||||
};
|
||||
|
||||
case "table-all":
|
||||
return {
|
||||
...baseContext,
|
||||
formData: context.formData || {},
|
||||
tableAllData: context.tableAllData || [],
|
||||
sourceData: context.tableAllData || [],
|
||||
};
|
||||
|
||||
case "flow-selection":
|
||||
return {
|
||||
...baseContext,
|
||||
formData: context.formData || {},
|
||||
flowSelectedData: context.flowSelectedData || [],
|
||||
sourceData: context.flowSelectedData || [],
|
||||
};
|
||||
|
||||
case "flow-step-all":
|
||||
return {
|
||||
...baseContext,
|
||||
formData: context.formData || {},
|
||||
flowStepAllData: context.flowStepAllData || [],
|
||||
flowStepId: context.flowStepId,
|
||||
sourceData: context.flowStepAllData || [],
|
||||
};
|
||||
|
||||
case "both":
|
||||
// 폼 + 테이블 선택
|
||||
return {
|
||||
...baseContext,
|
||||
formData: context.formData || {},
|
||||
selectedRowsData: context.selectedRowsData || [],
|
||||
sourceData: [
|
||||
context.formData || {},
|
||||
...(context.selectedRowsData || []),
|
||||
],
|
||||
};
|
||||
|
||||
case "all-sources":
|
||||
// 모든 소스 결합
|
||||
return {
|
||||
...baseContext,
|
||||
formData: context.formData || {},
|
||||
selectedRowsData: context.selectedRowsData || [],
|
||||
tableAllData: context.tableAllData || [],
|
||||
flowSelectedData: context.flowSelectedData || [],
|
||||
flowStepAllData: context.flowStepAllData || [],
|
||||
sourceData: [
|
||||
context.formData || {},
|
||||
...(context.selectedRowsData || []),
|
||||
...(context.tableAllData || []),
|
||||
...(context.flowSelectedData || []),
|
||||
...(context.flowStepAllData || []),
|
||||
].filter(item => Object.keys(item).length > 0), // 빈 객체 제거
|
||||
};
|
||||
|
||||
default:
|
||||
logger.warn(`알 수 없는 데이터 소스: ${dataSource}, 기본값(form) 사용`);
|
||||
return {
|
||||
...baseContext,
|
||||
formData: context.formData || {},
|
||||
sourceData: [context.formData || {}],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user