ソースを参照

feat: support dot notation in variable blocks

Ahmad Kholid 2 年 前
コミット
c49536cb7e

+ 1 - 1
src/background/index.js

@@ -120,7 +120,7 @@ const workflow = {
         blockDetail,
         blockDetail,
       }) => {
       }) => {
         if (
         if (
-          workflowData.id.startsWith('team_') &&
+          workflowData.id.startsWith('team') &&
           workflowData.teamId &&
           workflowData.teamId &&
           status === 'error'
           status === 'error'
         ) {
         ) {

+ 9 - 4
src/background/workflowEngine/blocksHandler/handlerIncreaseVariable.js

@@ -1,20 +1,25 @@
-import { objectHasKey } from '@/utils/helper';
+import objectPath from 'object-path';
 
 
 export async function increaseVariable({ id, data }) {
 export async function increaseVariable({ id, data }) {
   const refVariables = this.engine.referenceData.variables;
   const refVariables = this.engine.referenceData.variables;
+  const variableExist = objectPath.has(refVariables, data.variableName);
 
 
-  if (!objectHasKey(refVariables, data.variableName)) {
+  if (!variableExist) {
     throw new Error(`Cant find "${data.variableName}" variable`);
     throw new Error(`Cant find "${data.variableName}" variable`);
   }
   }
 
 
-  const currentVar = +refVariables[data.variableName];
+  const currentVar = +objectPath.get(refVariables, data.variableName);
   if (Number.isNaN(currentVar)) {
   if (Number.isNaN(currentVar)) {
     throw new Error(
     throw new Error(
       `The "${data.variableName}" variable value is not a number`
       `The "${data.variableName}" variable value is not a number`
     );
     );
   }
   }
 
 
-  refVariables[data.variableName] += data.increaseBy;
+  objectPath.set(
+    this.engine.referenceData.variables,
+    data.variableName,
+    currentVar + data.increaseBy
+  );
 
 
   return {
   return {
     data: refVariables[data.variableName],
     data: refVariables[data.variableName],

+ 9 - 4
src/background/workflowEngine/blocksHandler/handlerRegexVariable.js

@@ -1,13 +1,14 @@
-import { objectHasKey } from '@/utils/helper';
+import objectPath from 'object-path';
 
 
 export async function regexVariable({ id, data }) {
 export async function regexVariable({ id, data }) {
   const refVariables = this.engine.referenceData.variables;
   const refVariables = this.engine.referenceData.variables;
+  const variableExist = objectPath.has(refVariables, data.variableName);
 
 
-  if (!objectHasKey(refVariables, data.variableName)) {
+  if (!variableExist) {
     throw new Error(`Cant find "${data.variableName}" variable`);
     throw new Error(`Cant find "${data.variableName}" variable`);
   }
   }
 
 
-  const str = refVariables[data.variableName];
+  const str = objectPath.get(refVariables, data.variableName);
   if (typeof str !== 'string') {
   if (typeof str !== 'string') {
     throw new Error(
     throw new Error(
       `The value of the "${data.variableName}" variable is not a string/text`
       `The value of the "${data.variableName}" variable is not a string/text`
@@ -26,7 +27,11 @@ export async function regexVariable({ id, data }) {
     newValue = str.replace(regex, data.replaceVal ?? '');
     newValue = str.replace(regex, data.replaceVal ?? '');
   }
   }
 
 
-  refVariables[data.variableName] = newValue;
+  objectPath.set(
+    this.engine.referenceData.variables,
+    data.variableName,
+    newValue
+  );
 
 
   return {
   return {
     data: newValue,
     data: newValue,

+ 11 - 2
src/background/workflowEngine/blocksHandler/handlerSliceVariable.js

@@ -1,5 +1,10 @@
+import objectPath from 'object-path';
+
 export async function sliceData({ id, data }) {
 export async function sliceData({ id, data }) {
-  const variable = this.engine.referenceData.variables[data.variableName];
+  const variable = objectPath.get(
+    this.engine.referenceData.variables,
+    data.variableName
+  );
   const payload = {
   const payload = {
     data: variable,
     data: variable,
     nextBlockId: this.getBlockConnections(id),
     nextBlockId: this.getBlockConnections(id),
@@ -19,7 +24,11 @@ export async function sliceData({ id, data }) {
 
 
   const slicedVariable = variable.slice(startIndex, endIndex);
   const slicedVariable = variable.slice(startIndex, endIndex);
   payload.data = slicedVariable;
   payload.data = slicedVariable;
-  this.engine.referenceData.variables[data.variableName] = slicedVariable;
+  objectPath.set(
+    this.engine.referenceData.variables,
+    data.variableName,
+    slicedVariable
+  );
 
 
   return payload;
   return payload;
 }
 }

+ 3 - 3
src/components/newtab/logs/LogsHistory.vue

@@ -220,9 +220,9 @@ function getBlockPath(blockId) {
   const { workflowId, teamId } = props.currentLog;
   const { workflowId, teamId } = props.currentLog;
   let path = `/workflows/${workflowId}`;
   let path = `/workflows/${workflowId}`;
 
 
-  if (workflowId.startsWith('team') && !teamId) return null;
-
-  path = `/teams/${teamId}/workflows/${workflowId}`;
+  if (workflowId.startsWith('team') && teamId) {
+    path = `/teams/${teamId}/workflows/${workflowId}`;
+  }
 
 
   return `${path}?blockId=${blockId}`;
   return `${path}?blockId=${blockId}`;
 }
 }

+ 0 - 6
src/components/newtab/workflow/edit/EditJavascriptCode.vue

@@ -61,12 +61,6 @@
                 t('workflow.blocks.javascript-code.availabeFuncs')
                 t('workflow.blocks.javascript-code.availabeFuncs')
               }}</span>
               }}</span>
               <span>
               <span>
-                <span
-                  class="underline cursor-pointer select-none"
-                  @click="store.statePrettier = Math.random()"
-                  >prettier</span
-                >
-                &bull;
                 <span
                 <span
                   class="underline cursor-pointer select-none"
                   class="underline cursor-pointer select-none"
                   @click="modifyWhiteSpace"
                   @click="modifyWhiteSpace"

+ 1 - 0
src/components/newtab/workflow/edit/EditRegexVariable.vue

@@ -24,6 +24,7 @@
       </option>
       </option>
     </ui-select>
     </ui-select>
     <ui-input
     <ui-input
+      v-if="data.method === 'replace'"
       :model-value="data.replaceVal"
       :model-value="data.replaceVal"
       label="Replace with"
       label="Replace with"
       placeholder="(empty)"
       placeholder="(empty)"