Browse Source

fix: mustache tag

Ahmad Kholid 2 years ago
parent
commit
becac2ad0b

+ 4 - 3
src/newtab/workflowEngine/WorkflowEngine.js

@@ -1,5 +1,6 @@
-import browser from 'webextension-polyfill';
 import { nanoid } from 'nanoid';
+import browser from 'webextension-polyfill';
+import cloneDeep from 'lodash.clonedeep';
 import { getBlocks } from '@/utils/getSharedData';
 import { clearCache, sleep, parseJSON, isObject } from '@/utils/helper';
 import dbStorage from '@/db/storage';
@@ -290,7 +291,7 @@ class WorkflowEngine {
           activeTabUrl,
           prevBlockData: detail.prevBlockData || '',
         },
-        replacedValue: detail.replacedValue,
+        replacedValue: cloneDeep(detail.replacedValue),
       };
 
       delete detail.replacedValue;
@@ -455,7 +456,7 @@ class WorkflowEngine {
 
       if (!this.workflow?.isTesting) {
         const { name, id, teamId } = this.workflow;
-
+        console.log(this.historyCtxData);
         await this.logger.add({
           detail: {
             name,

+ 19 - 2
src/newtab/workflowEngine/templating/renderString.js

@@ -1,12 +1,29 @@
 import { messageSandbox } from '../helper';
 import mustacheReplacer from './mustacheReplacer';
 
+const isFirefox = BROWSER_TYPE === 'firefox';
+
 export default async function (str, data) {
   if (!str || typeof str !== 'string') return '';
 
+  const hasMustacheTag = /\{\{(.*?)\}\}/.test(str);
+  if (!hasMustacheTag) {
+    return {
+      list: {},
+      value: str,
+    };
+  }
+
   let renderedValue = {};
-  if (str.startsWith('!#')) {
-    renderedValue = await messageSandbox('blockExpression', { str, data });
+  if (str.startsWith('!!') && !isFirefox) {
+    const refKeysRegex =
+      /(variables|table|secrets|loopData|workflow|googleSheets|globalData)@/g;
+    const strToRender = str.replace(refKeysRegex, '$1.');
+
+    renderedValue = await messageSandbox('blockExpression', {
+      str: strToRender,
+      data,
+    });
   } else {
     renderedValue = mustacheReplacer(str, data);
   }