From e775d922e85a77bd161e17c58869467ac57f737d Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 18 Jun 2024 10:48:34 +0200 Subject: [PATCH] perf: cleancode --- src/components/common/VnSelect.vue | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/components/common/VnSelect.vue b/src/components/common/VnSelect.vue index c7c694ca1..c12d81a89 100644 --- a/src/components/common/VnSelect.vue +++ b/src/components/common/VnSelect.vue @@ -103,14 +103,13 @@ const arrayData = useURL.value : ref(null); onMounted(async () => { setOptions(options.value); + if (!$props.options) fetchFilter($props.modelValue); if (useURL.value) { arrayData.store.userFilter = $props.where; arrayData.store.filter.where = $props.where; const { data } = await arrayData.fetch({ append: true }); setOptions(data); - return; } - if (!$props.options) fetchFilter($props.modelValue); }); watch(modelValue, (newValue) => { @@ -125,7 +124,7 @@ function filter(val, options) { if (!search) return options; - const optionsFiltered = options.filter((row) => { + return options.filter((row) => { if ($props.filterOptions.length) { return $props.filterOptions.some((prop) => { const propValue = String(row[prop]).toLowerCase(); @@ -138,16 +137,15 @@ function filter(val, options) { return id == search || optionLabel.includes(search); }); - - return optionsFiltered; } async function fetchFilter(val) { if (!useURL.value || !dataRef.value) return; const { fields, sortBy, limit } = $props; - let key = null; - if (new RegExp(/\d/g).test(val)) key = optionFilter.value ?? optionValue.value; + let key = new RegExp(/\d/g).test(val) + ? optionFilter.value ?? optionValue.value + : optionValue.value; const where = { ...{ [key]: { like: `%${val}%` } }, ...$props.where }; return dataRef.value.fetch({ fields, where, order: sortBy, limit });