Browse Source

feat: add workflow public id

Ahmad Kholid 3 years ago
parent
commit
5ca9c86b52

+ 1 - 0
src/components/newtab/workflow/WorkflowSettings.vue

@@ -70,6 +70,7 @@ const tabs = [
 
 const activeTab = ref('general');
 const settings = reactive({
+  publicId: '',
   restartTimes: 3,
   tabLoadTimeout: 30000,
   inputAutocomplete: true,

+ 15 - 0
src/components/newtab/workflow/settings/SettingsGeneral.vue

@@ -74,6 +74,21 @@
       {{ t('workflow.settings.clearCache.btn') }}
     </ui-button>
   </div>
+  <div class="flex items-center pt-4">
+    <div class="mr-4 flex-1">
+      <p>
+        {{ t('workflow.settings.publicId.title') }}
+      </p>
+      <p class="text-gray-600 dark:text-gray-200 text-sm leading-tight">
+        {{ t('workflow.settings.publicId.description') }}
+      </p>
+    </div>
+    <ui-input
+      :model-value="settings.publicId"
+      placeholder="myWorkflowPublicId"
+      @change="updateSetting('publicId', $event)"
+    />
+  </div>
 </template>
 <script setup>
 import { useI18n } from 'vue-i18n';

+ 11 - 4
src/content/services/shortcutListener.js

@@ -10,9 +10,10 @@ function automaCustomEventListener(findWorkflow) {
   window.addEventListener(
     'automa:execute-workflow',
     ({ detail }) => {
-      if (!detail || !detail.id) return;
+      if (!detail || (!detail.id && !detail.publicId)) return;
 
-      const workflow = findWorkflow(detail.id);
+      const workflowId = detail.id || detail.publicId;
+      const workflow = findWorkflow(workflowId, Boolean(detail.publicId));
 
       if (!workflow) return;
 
@@ -64,8 +65,14 @@ export default async function () {
         'workflows',
         'workflowHosts',
       ]);
-    const findWorkflow = (id) => {
-      let workflow = workflows.find((item) => item.id === id);
+    const findWorkflow = (id, publicId = false) => {
+      let workflow = workflows.find((item) => {
+        if (publicId) {
+          return item.settings.publicId === id;
+        }
+
+        return item.id === id;
+      });
 
       if (!workflow) {
         workflow = Object.values(workflowHosts || {}).find(

+ 4 - 0
src/locales/en/newtab.json

@@ -193,6 +193,10 @@
     "settings": {
       "saveLog": "Save workflow log",
       "executedBlockOnWeb": "Show executed block on web page",
+      "publicId": {
+        "title": "Workflow public Id",
+        "description": "Use this public id to execute workflow using JS custom event"
+      },
       "defaultColumn": {
         "title": "Insert into the default column",
         "description": "Insert data to the default column if there's no column selected in the block",

+ 1 - 0
src/models/workflow.js

@@ -31,6 +31,7 @@ class Workflow extends Model {
       isDisabled: this.boolean(false),
       isProtected: this.boolean(false),
       settings: this.attr({
+        publicId: '',
         blockDelay: 0,
         saveLog: true,
         debugMode: false,