瀏覽代碼

Merge pull request #1367 from Siykt/feat/insert-all-global-data

Feat: Use all current workflow globalData
Ahmad Kholid 1 年之前
父節點
當前提交
e452652af3

+ 7 - 0
src/components/newtab/workflow/edit/EditExecuteWorkflow.vue

@@ -43,6 +43,13 @@
     <p class="mt-4 ml-1 mb-1 text-sm text-gray-600 dark:text-gray-200">
       {{ t('common.globalData') }}
     </p>
+    <ui-checkbox
+      :model-value="data.insertAllGlobalData"
+      class="mb-4 leading-tight text-sm"
+      @change="updateData({ insertAllGlobalData: $event })"
+    >
+      {{ t('workflow.blocks.execute-workflow.insertAllGlobalData') }}
+    </ui-checkbox>
     <pre
       v-if="!state.showGlobalData"
       class="max-h-80 overflow-auto rounded-lg bg-gray-900 p-4 text-gray-200"

+ 2 - 1
src/locales/en/blocks.json

@@ -393,7 +393,8 @@
         "description": "",
         "insertAllVars": "Use all current workflow variables",
         "insertVars": "Insert current workflow variables",
-        "useCommas": "Use commas to separate the variable name"
+        "useCommas": "Use commas to separate the variable name",
+        "insertAllGlobalData": "Use all current workflow globalData"
       },
       "google-sheets-drive": {
         "name": "@:workflow.blocks.google-sheets.name (GDrive)",

+ 2 - 1
src/locales/it/blocks.json

@@ -393,7 +393,8 @@
         "description": "",
         "insertAllVars": "Usa tutte le variabili del workflow corrente",
         "insertVars": "Inserisci le variabili del workflow corrente",
-        "useCommas": "Usa le virgole per separare i nomi delle variabili"
+        "useCommas": "Usa le virgole per separare i nomi delle variabili",
+        "insertAllGlobalData": "Utilizza tutto il flusso di lavoro corrente globalData"
       },
       "google-sheets": {
         "name": "Google Sheets",

+ 4 - 1
src/locales/uk/blocks.json

@@ -774,7 +774,10 @@
             "iframe": "Iframe"
           }
         }
+      },
+      "execute-workflow": {
+        "insertAllGlobalData": "Використовувати весь поточний робочий процес globalData"
       }
     }
   }
-}
+}

+ 13 - 6
src/locales/vi/blocks.json

@@ -380,9 +380,10 @@
         "description": "",
         "insertAllVars": "Chèn tất cả các biến quy trình làm việc hiện tại",
         "insertVars": "Chèn các biến quy trình công việc hiện tại",
-        "useCommas": "Sử dụng dấu phẩy để phân tách tên biến"
+        "useCommas": "Sử dụng dấu phẩy để phân tách tên biến",
+        "insertAllGlobalData": "Sử dụng tất cả quy trình công việc hiện tại GlobalData"
       },
-       "google-sheets": {
+      "google-sheets": {
         "name": "Google sheets",
         "description": "Đọc hoặc cập nhật dữ liệu Google Trang tính",
         "previewData": "Xem trước dữ liệu",
@@ -571,9 +572,15 @@
             "label": "Nhập độ trễ (mili giây)(0 là vô hiệu hóa)"
           }
         },
-        "select": { "name": "Select" },
-        "radio": { "name": "Radio" },
-        "checkbox": { "name": "Checkbox" }
+        "select": {
+          "name": "Select"
+        },
+        "radio": {
+          "name": "Radio"
+        },
+        "checkbox": {
+          "name": "Checkbox"
+        }
       },
       "repeat-task": {
         "name": "Nhiệm vụ lặp lại",
@@ -682,7 +689,7 @@
         "name": "Dữ liệu vòng lặp",
         "description": "Lặp lại qua các cột dữ liệu hoặc dữ liệu tùy chỉnh của bạn",
         "loopId": "ID Vòng lặp",
-         "refKey": "Khóa liên kết",
+        "refKey": "Khóa liên kết",
         "startIndex": "Bắt đầu từ chỉ mục",
         "resumeLastWorkflow": "Tiếp tục quy trình làm việc cuối cùng",
         "reverse": "Thứ tự vòng lặp đảo ngược",

+ 12 - 3
src/locales/zh-TW/blocks.json

@@ -163,9 +163,15 @@
             "label": "設定執行文字輸入前的等待時間; 單位: ms(0為停用)"
           }
         },
-        "select": { "name": "下拉式選單" },
-        "radio": { "name": "單選框" },
-        "checkbox": { "name": "複選框" }
+        "select": {
+          "name": "下拉式選單"
+        },
+        "radio": {
+          "name": "單選框"
+        },
+        "checkbox": {
+          "name": "複選框"
+        }
       },
       "repeat-task": {
         "name": "重新執行任務",
@@ -279,6 +285,9 @@
           "main": "主視窗",
           "iframe": "iframe"
         }
+      },
+      "execute-workflow": {
+        "insertAllGlobalData": "插入當前工作流的 GlobalData"
       }
     }
   }

+ 3 - 2
src/locales/zh/blocks.json

@@ -17,7 +17,7 @@
         "timeout": "超时 (毫秒)",
         "noPermission": "Automa 没有足够的权限执行此操作",
         "grantPermission": "授予权限",
-	      "action": "操作",
+        "action": "操作",
         "element": {
           "select": "选择一个元素",
           "verify": "验证选择器"
@@ -393,7 +393,8 @@
         "description": "",
         "insertAllVars": "插入所有当前工作流变量",
         "insertVars": "插入当前工作流变量",
-        "useCommas": "使用逗号分隔变量名"
+        "useCommas": "使用逗号分隔变量名",
+        "insertAllGlobalData": "插入当前工作流的 GlobalData"
       },
       "google-sheets": {
         "name": "Google sheets",

+ 1 - 0
src/utils/shared.js

@@ -68,6 +68,7 @@ export const tasks = {
       globalData: '',
       description: '',
       insertAllVars: false,
+      insertAllGlobalData: false,
     },
   },
   'active-tab': {

+ 12 - 3
src/workflowEngine/blocksHandler/handlerExecuteWorkflow.js

@@ -44,7 +44,7 @@ function findWorkflow(workflows, workflowId) {
   return workflow;
 }
 
-async function executeWorkflow({ id: blockId, data }) {
+async function executeWorkflow({ id: blockId, data }, { refData }) {
   if (data.workflowId === '') throw new Error('empty-workflow');
 
   const { workflows, teamWorkflows } = await browser.storage.local.get([
@@ -74,8 +74,17 @@ async function executeWorkflow({ id: blockId, data }) {
 
   if (workflow.testingMode) workflow.testingMode = false;
 
-  if (!isWhitespace(data.globalData))
-    optionsParams.globalData = data.globalData;
+  if (data.insertAllGlobalData) {
+    optionsParams.globalData = refData.globalData;
+  }
+
+  if (!isWhitespace(data.globalData)) {
+    // shallow copy
+    optionsParams.globalData = {
+      ...optionsParams.globalData,
+      ...JSON.parse(data.globalData),
+    };
+  }
 
   if (data.insertAllVars) {
     optionsParams.variables = JSON.parse(