Browse Source

fix: duplicate input value in condition builder

Ahmad Kholid 3 years ago
parent
commit
57486db3d1

+ 1 - 1
src/components/newtab/shared/SharedConditionBuilder/ConditionBuilderInputs.vue

@@ -23,7 +23,7 @@
           </option>
         </optgroup>
       </ui-select>
-      <template v-for="(_, name) in item.data" :key="item.id + name + index">
+      <template v-for="(_, name) in item.data" :key="item.id + name">
         <v-remixicon
           v-if="name === 'code'"
           :title="t('workflow.conditionBuilder.topAwait')"

+ 11 - 5
src/components/newtab/shared/SharedConditionBuilder/index.vue

@@ -47,7 +47,7 @@
                     </p>
                     <v-remixicon
                       name="riDeleteBin7Line"
-                      class="ml-4 group-hover:visible invisibl"
+                      class="ml-4 group-hover:visible invisible"
                       @click.stop="deleteCondition(index, inputsIndex)"
                     />
                     <v-remixicon
@@ -128,17 +128,23 @@ const conditions = ref(cloneDeep(props.modelValue));
 function getDefaultValues(items = ['value', 'compare', 'value']) {
   const defaultValues = {
     value: {
-      id: nanoid(),
       type: 'value',
       category: 'value',
       data: { value: '' },
     },
-    compare: { id: nanoid(), category: 'compare', type: 'eq' },
+    compare: { category: 'compare', type: 'eq' },
   };
+  const selectValue = (type) =>
+    cloneDeep({
+      ...defaultValues[type],
+      id: nanoid(),
+    });
 
-  if (typeof items === 'string') return defaultValues[items];
+  if (typeof items === 'string') {
+    return selectValue(items);
+  }
 
-  return items.map((item) => defaultValues[item]);
+  return items.map((item) => selectValue(item));
 }
 function getConditionText({ category, type, data }) {
   if (category === 'compare') {