Browse Source

feat: add "save log" setting

Ahmad Kholid 3 years ago
parent
commit
b24a893bed

+ 4 - 1
src/background/workflow-engine/engine.js

@@ -103,6 +103,8 @@ class WorkflowEngine {
     this.childWorkflow = null;
     this.workflowTimeout = null;
 
+    this.saveLog = workflow.settings?.saveLog ?? true;
+
     this.googleSheets = {};
 
     this.tabUpdatedListeners = {};
@@ -186,6 +188,7 @@ class WorkflowEngine {
 
   addLog(detail) {
     if (
+      !this.saveLog &&
       (this.logs.length >= 1001 || detail.name === 'blocks-group') &&
       detail.type !== 'error'
     )
@@ -237,7 +240,7 @@ class WorkflowEngine {
       this.isDestroyed = true;
       this.endedTimestamp = Date.now();
 
-      if (!this.workflow.isTesting) {
+      if (!this.workflow.isTesting && this.saveLog) {
         const { logs } = await browser.storage.local.get('logs');
         const { name, icon, id } = this.workflow;
         const jsonData = generateJSON(Object.keys(this.data), this.data);

+ 29 - 11
src/components/newtab/workflow/WorkflowSettings.vue

@@ -6,10 +6,10 @@
         <ui-radio
           v-for="item in onError"
           :key="item.id"
-          :model-value="workflow.settings.onError"
+          :model-value="settings.onError"
           :value="item.id"
           class="mr-4"
-          @change="updateWorkflow({ onError: $event })"
+          @change="settings.onError = $event"
         >
           {{ item.name }}
         </ui-radio>
@@ -18,10 +18,9 @@
     <div class="mb-6">
       <p class="mb-1">{{ t('workflow.settings.timeout.title') }}</p>
       <ui-input
-        :model-value="workflow.settings.timeout"
+        v-model="settings.timeout"
         type="number"
         class="w-full max-w-sm"
-        @change="updateWorkflow({ timeout: +$event })"
       />
     </div>
     <div>
@@ -32,15 +31,19 @@
         </span>
       </p>
       <ui-input
-        :model-value="workflow.settings.blockDelay"
+        v-model.number="settings.blockDelay"
         type="number"
         class="w-full max-w-sm"
-        @change="updateWorkflow({ blockDelay: +$event })"
       />
     </div>
+    <div class="flex mt-6">
+      <ui-switch v-model="settings.saveLog" class="mr-4" />
+      <p>Save log</p>
+    </div>
   </div>
 </template>
 <script setup>
+import { onMounted, reactive, watch } from 'vue';
 import { useI18n } from 'vue-i18n';
 
 const props = defineProps({
@@ -64,9 +67,24 @@ const onError = [
   },
 ];
 
-function updateWorkflow(data) {
-  emit('update', {
-    settings: { ...props.workflow.settings, ...data },
-  });
-}
+const settings = reactive({
+  blockDelay: 0,
+  saveLog: true,
+  timeout: 120000,
+  onError: 'stop-workflow',
+});
+
+watch(
+  settings,
+  (newSettings) => {
+    emit('update', {
+      settings: newSettings,
+    });
+  },
+  { deep: true }
+);
+
+onMounted(() => {
+  Object.assign(settings, props.workflow.settings);
+});
 </script>

+ 81 - 0
src/components/ui/UiSwitch.vue

@@ -0,0 +1,81 @@
+<template>
+  <div
+    class="ui-switch relative inline-flex h-6 w-12 justify-center items-center bg-input p-1 rounded-full"
+    :class="{ 'pointer-events-none opacity-50': disabled }"
+  >
+    <input
+      :checked="modelValue"
+      type="checkbox"
+      class="absolute h-full w-full opacity-0 cursor-pointer left-0 top-0 z-50"
+      v-bind="{ disabled, readonly: disabled || null }"
+      @input="emitEvent"
+    />
+    <div
+      class="ui-switch__ball z-40 rounded-full absolute h-4 w-4 shadow-xl bg-white flex justify-center items-center"
+    >
+      <slot v-if="$slots.ball" name="ball"></slot>
+    </div>
+    <div
+      class="ui-switch__background absolute h-full rounded-md w-full left-0 top-0 bg-accent"
+    ></div>
+  </div>
+</template>
+<script>
+export default {
+  props: {
+    modelValue: {
+      type: Boolean,
+      default: false,
+    },
+    disabled: Boolean,
+  },
+  emits: ['update:modelValue', 'change'],
+  setup(props, { emit }) {
+    return {
+      emitEvent: () => {
+        const newValue = !props.modelValue;
+
+        emit('change', newValue);
+        emit('update:modelValue', newValue);
+      },
+    };
+  },
+};
+</script>
+<style scoped>
+.ui-switch {
+  overflow: hidden;
+  transition: all 250ms ease;
+}
+
+.ui-switch:active {
+  transform: scale(0.93);
+}
+
+.ui-switch__ball {
+  transition: all 250ms ease;
+  left: 6px;
+}
+
+.ui-switch__background {
+  transition: all 250ms ease;
+  margin-left: -100%;
+}
+
+.ui-switch:hover .ui-switch__ball {
+  transform: scale(1.1);
+}
+
+.ui-switch input:focus ~ .ui-switch__ball {
+  transform: scale(1.1);
+}
+
+.ui-switch input:checked ~ .ui-switch__ball {
+  background-color: white;
+  left: calc(100% - 21px);
+}
+
+.ui-switch input:checked ~ .ui-switch__background {
+  margin-left: 0;
+}
+</style>

+ 1 - 0
src/models/workflow.js

@@ -25,6 +25,7 @@ class Workflow extends Model {
       isDisabled: this.boolean(false),
       settings: this.attr({
         blockDelay: 0,
+        saveLog: true,
         timeout: 120000,
         onError: 'stop-workflow',
       }),