Browse Source

fix: block fallback is not copied when it getting replaced

Ahmad Kholid 2 years ago
parent
commit
b61fd756de

+ 14 - 2
src/components/newtab/workflow/WorkflowBuilder.vue

@@ -87,7 +87,7 @@ import {
   getShortcut,
   getReadableShortcut,
 } from '@/composable/shortcut';
-import { tasks } from '@/utils/shared';
+import { tasks, excludeOnError } from '@/utils/shared';
 import { parseJSON } from '@/utils/helper';
 import { useGroupTooltip } from '@/composable/groupTooltip';
 import drawflow from '@/lib/drawflow';
@@ -248,6 +248,13 @@ export default {
           targetBlock = { ...tasks[block.id], id: block.id };
         }
 
+        const onErrorEnabled =
+          targetNode.data?.onError?.enable &&
+          !excludeOnError.includes(targetBlock.id);
+        const newNodeData = onErrorEnabled
+          ? { ...targetBlock.data, onError: targetNode.data.onError }
+          : targetBlock.data;
+
         const newNodeId = editor.value.addNode(
           targetBlock.id,
           targetBlock.inputs,
@@ -255,10 +262,15 @@ export default {
           targetNode.pos_x,
           targetNode.pos_y,
           targetBlock.id,
-          targetBlock.data,
+          newNodeData,
           targetBlock.component,
           'vue'
         );
+
+        if (onErrorEnabled && targetNode.data.onError.toDo === 'fallback') {
+          editor.value.addNodeOutput(newNodeId);
+        }
+
         const duplicateConnections = (nodeIO, type) => {
           if (block[type] === 0) return;
 

+ 1 - 10
src/components/newtab/workflow/WorkflowEditBlock.vue

@@ -54,7 +54,7 @@
 <script>
 import { computed, provide, ref, watch } from 'vue';
 import { useI18n } from 'vue-i18n';
-import { tasks } from '@/utils/shared';
+import { tasks, excludeOnError } from '@/utils/shared';
 import { parseJSON } from '@/utils/helper';
 import OnBlockError from './edit/OnBlockError.vue';
 
@@ -97,15 +97,6 @@ export default {
   },
   emits: ['close', 'update', 'update:autocomplete'],
   setup(props, { emit }) {
-    const excludeOnError = [
-      'delay',
-      'webhook',
-      'trigger',
-      'while-loop',
-      'conditions',
-      'element-exists',
-    ];
-
     const { t } = useI18n();
     const autocompleteData = ref({
       common: {

+ 9 - 0
src/utils/shared.js

@@ -1038,6 +1038,15 @@ export const workflowCategories = {
   productivity: 'Productivity',
 };
 
+export const excludeOnError = [
+  'delay',
+  'webhook',
+  'trigger',
+  'while-loop',
+  'conditions',
+  'element-exists',
+];
+
 export const contentTypes = [
   { name: 'application/json', value: 'json' },
   { name: 'application/x-www-form-urlencoded', value: 'form' },

+ 9 - 4
src/utils/workflowTrigger.js

@@ -10,7 +10,10 @@ export function registerContextMenu(workflowId, data) {
         ? ['all']
         : data.contextTypes;
 
-    browser.contextMenus.create(
+    const isFirefox = BROWSER_TYPE === 'firefox';
+    const browserContext = isFirefox ? browser.menus : browser.contextMenus;
+
+    browserContext.create(
       {
         id: workflowId,
         documentUrlPatterns,
@@ -23,7 +26,7 @@ export function registerContextMenu(workflowId, data) {
 
         if (error) {
           if (error.message.includes('automaContextMenu')) {
-            browser.contextMenus.create(
+            browserContext.create(
               {
                 documentUrlPatterns,
                 contexts: ['all'],
@@ -41,7 +44,7 @@ export function registerContextMenu(workflowId, data) {
 
           reject(error.message);
         } else {
-          if (browser.contextMenus.refresh) browser.contextMenus.refresh();
+          if (browserContext.refresh) browserContext.refresh();
           resolve();
         }
       }
@@ -95,7 +98,9 @@ export async function cleanWorkflowTriggers(workflowId) {
       onStartupTriggers: startupTriggers,
     });
 
-    browser.contextMenus.remove(workflowId);
+    (BROWSER_TYPE === 'firefox' ? browser.menus : browser.contextMenus)?.remove(
+      workflowId
+    );
   } catch (error) {
     console.error(error);
   }