diff --git a/frontend/lib/utils/buttonActions.ts b/frontend/lib/utils/buttonActions.ts index 264bd039..154df0fb 100644 --- a/frontend/lib/utils/buttonActions.ts +++ b/frontend/lib/utils/buttonActions.ts @@ -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 { + 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("저장은 완료되었으나 연결된 제어 실행 중 오류가 발생했습니다."); + } + } + } + /** * 관계도에서 가져온 액션들을 실행 */