فهرست منبع

feat: merge all data from all workflows

siykt 1 سال پیش
والد
کامیت
5b6d229744
2فایلهای تغییر یافته به همراه15 افزوده شده و 8 حذف شده
  1. 6 0
      src/workflowEngine/WorkflowEngine.js
  2. 9 8
      src/workflowEngine/blocksHandler/handlerExecuteWorkflow.js

+ 6 - 0
src/workflowEngine/WorkflowEngine.js

@@ -480,6 +480,12 @@ class WorkflowEngine {
       const { table, variables } = this.referenceData;
       const tableId = this.workflow.connectedTable;
 
+      // Merge all table and variables from all workflows
+      Object.values(this.referenceData.workflow).forEach((data) => {
+        Object.assign(table, data.table);
+        Object.assign(variables, data.variables);
+      });
+
       await dbStorage.transaction(
         'rw',
         dbStorage.tablesItems,

+ 9 - 8
src/workflowEngine/blocksHandler/handlerExecuteWorkflow.js

@@ -2,6 +2,7 @@ import browser from 'webextension-polyfill';
 import { isWhitespace, parseJSON } from '@/utils/helper';
 import decryptFlow, { getWorkflowPass } from '@/utils/decryptFlow';
 import convertWorkflowData from '@/utils/convertWorkflowData';
+import { nanoid } from 'nanoid';
 import WorkflowEngine from '../WorkflowEngine';
 
 function workflowListener(workflow, options) {
@@ -115,14 +116,14 @@ async function executeWorkflow({ id: blockId, data }, { refData }) {
         this.childWorkflowId = engine.id;
       },
       onDestroyed: (engine) => {
-        if (data.executeId) {
-          const { variables, table } = engine.referenceData;
-
-          this.engine.referenceData.workflow[data.executeId] = {
-            table,
-            variables,
-          };
-        }
+        const { variables, table } = engine.referenceData;
+
+        this.engine.referenceData.workflow[
+          data.executeId || `${engine.id}-${nanoid(8)}`
+        ] = {
+          table,
+          variables,
+        };
       },
     },
     states: this.engine.states,