feat: 버튼 저장 후 제어 자동 실행 기능 추가

문제:
- 버튼에 제어를 연결했지만 실행되지 않음
- ButtonActionExecutor가 제어 실행 로직이 없었음

수정:
1. buttonActions.ts:
   - executeAfterSaveControl() 메서드 추가
   - handleSave()에서 저장 성공 후 제어 실행
   - dataflowTiming='after'일 때만 실행
   - ImprovedButtonActionExecutor 통해 관계 기반 제어 실행

2. ButtonActionConfig 타입 확장:
   - dataflowTiming 필드 추가

3. ButtonActionContext 타입 확장:
   - buttonId, userId, companyCode 필드 추가

4. Import 추가:
   - ExtendedControlContext 타입 import

동작 흐름:
save 버튼 클릭
→ handleSave() 실행
→ 데이터 저장 (INSERT/UPDATE)
→  저장 성공
→ executeAfterSaveControl() 자동 호출
→ ImprovedButtonActionExecutor로 관계 실행
→ 연결된 제어 액션들 순차 실행

결과:
-  저장 후 연결된 제어 자동 실행
-  제어 실패 시 에러 처리
-  기존 기능 영향 없음
This commit is contained in:
kjs 2025-10-01 15:31:31 +09:00
parent 352d4c3126
commit cb1a6ad672
1 changed files with 75 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import { toast } from "sonner";
import { screenApi } from "@/lib/api/screen";
import { DynamicFormApi } from "@/lib/api/dynamicForm";
import { ImprovedButtonActionExecutor } from "@/lib/utils/improvedButtonActionExecutor";
import type { ExtendedControlContext } from "@/types/control-management";
/**
*
@ -51,6 +52,7 @@ export interface ButtonActionConfig {
// 제어관리 관련
enableDataflowControl?: boolean;
dataflowConfig?: any; // ButtonDataflowConfig 타입 (순환 참조 방지를 위해 any 사용)
dataflowTiming?: "before" | "after" | "replace"; // 제어 실행 타이밍
}
/**
@ -68,6 +70,11 @@ export interface ButtonActionContext {
// 테이블 선택된 행 정보 (다중 선택 액션용)
selectedRows?: any[];
selectedRowsData?: any[];
// 제어 실행을 위한 추가 정보
buttonId?: string;
userId?: string;
companyCode?: string;
}
/**
@ -226,6 +233,12 @@ export class ButtonActionExecutor {
}
console.log("✅ 저장 성공:", saveResult);
// 🔥 저장 성공 후 연결된 제어 실행 (dataflowTiming이 'after'인 경우)
if (config.enableDataflowControl && config.dataflowConfig) {
console.log("🎯 저장 후 제어 실행 시작:", config.dataflowConfig);
await this.executeAfterSaveControl(config, context);
}
} else {
throw new Error("저장에 필요한 정보가 부족합니다. (테이블명 또는 화면ID 누락)");
}
@ -853,6 +866,68 @@ export class ButtonActionExecutor {
}
}
/**
* (After Timing)
*/
private static async executeAfterSaveControl(config: ButtonActionConfig, context: ButtonActionContext): Promise<void> {
console.log("🎯 저장 후 제어 실행:", {
enableDataflowControl: config.enableDataflowControl,
dataflowConfig: config.dataflowConfig,
dataflowTiming: config.dataflowTiming,
});
// dataflowTiming이 'after'가 아니면 실행하지 않음
if (config.dataflowTiming && config.dataflowTiming !== "after") {
console.log("⏭️ dataflowTiming이 'after'가 아니므로 제어 실행 건너뜀:", config.dataflowTiming);
return;
}
// 제어 데이터 소스 결정
let controlDataSource = config.dataflowConfig?.controlDataSource;
if (!controlDataSource) {
controlDataSource = "form"; // 저장 후에는 기본적으로 form 데이터 사용
}
const extendedContext: ExtendedControlContext = {
formData: context.formData || {},
selectedRows: context.selectedRows || [],
selectedRowsData: context.selectedRowsData || [],
controlDataSource,
};
// 관계 기반 제어 실행
if (config.dataflowConfig?.controlMode === "relationship" && config.dataflowConfig?.relationshipConfig) {
console.log("🔗 저장 후 관계 기반 제어 실행:", config.dataflowConfig.relationshipConfig);
const buttonConfig = {
actionType: config.type,
dataflowConfig: config.dataflowConfig,
enableDataflowControl: true,
};
const executionResult = await ImprovedButtonActionExecutor.executeButtonAction(
buttonConfig,
context.formData || {},
{
buttonId: context.buttonId || "unknown",
screenId: context.screenId || "unknown",
userId: context.userId || "unknown",
companyCode: context.companyCode || "*",
startTime: Date.now(),
contextData: context,
}
);
if (executionResult.success) {
console.log("✅ 저장 후 제어 실행 완료:", executionResult);
// 성공 토스트는 save 액션에서 이미 표시했으므로 추가로 표시하지 않음
} else {
console.error("❌ 저장 후 제어 실행 실패:", executionResult);
toast.error("저장은 완료되었으나 연결된 제어 실행 중 오류가 발생했습니다.");
}
}
}
/**
*
*/