feat: added logic to avoid other filter params when searching on vnsearchbar
gitea/salix-front/pipeline/pr-master This commit looks good Details

This commit is contained in:
Jon Elias 2024-12-11 13:38:04 +01:00
parent 2cdc8916cc
commit c61ad16681
3 changed files with 15 additions and 31 deletions

View File

@ -63,10 +63,6 @@ const props = defineProps({
type: Function, type: Function,
default: undefined, default: undefined,
}, },
beforeSearch: {
type: Function,
default: undefined,
},
}); });
const searchText = ref(); const searchText = ref();
@ -102,12 +98,16 @@ onMounted(() => {
async function search() { async function search() {
const staticParams = Object.entries(store.userParams); const staticParams = Object.entries(store.userParams);
arrayData.reset(['skip', 'page']); arrayData.reset(['skip', 'page']);
let filter = { let filter = {
params: { params: {
...Object.fromEntries(staticParams),
search: searchText.value, search: searchText.value,
}, },
};
if (!(searchText.value && searchText.value !== '')) {
filter = {
params: {
...Object.fromEntries(staticParams),
},
...{ filter: props.filter }, ...{ filter: props.filter },
}; };
@ -117,7 +117,7 @@ async function search() {
}; };
delete filter.params.search; delete filter.params.search;
} }
if (props.beforeSearch) filter = props.beforeSearch(filter); }
await arrayData.applyFilter(filter); await arrayData.applyFilter(filter);
} }
</script> </script>

View File

@ -18,13 +18,6 @@ const { t } = useI18n();
url: 'Tickets/filter', url: 'Tickets/filter',
label: t('card.search'), label: t('card.search'),
info: t('card.searchInfo'), info: t('card.searchInfo'),
beforeSearch: (filter) => {
if (filter.params.search) {
delete filter.params.from;
delete filter.params.to;
}
return filter;
},
}" }"
/> />
</template> </template>

View File

@ -1,6 +1,6 @@
<script setup> <script setup>
import axios from 'axios'; import axios from 'axios';
import { computed, ref, onMounted } from 'vue'; import { computed, ref, onBeforeMount } from 'vue';
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
import { useStateStore } from 'stores/useStateStore'; import { useStateStore } from 'stores/useStateStore';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
@ -46,7 +46,7 @@ const userParams = {
from: null, from: null,
to: null, to: null,
}; };
onMounted(() => { onBeforeMount(() => {
initializeFromQuery(); initializeFromQuery();
stateStore.rightDrawer = true; stateStore.rightDrawer = true;
if (!route.query.createForm) return; if (!route.query.createForm) return;
@ -457,15 +457,6 @@ function setReference(data) {
:label="t('Search ticket')" :label="t('Search ticket')"
:info="t('You can search by ticket id or alias')" :info="t('You can search by ticket id or alias')"
data-cy="ticketListSearchBar" data-cy="ticketListSearchBar"
:before-search="
(filter) => {
if (filter.params.search) {
delete filter.params.from;
delete filter.params.to;
}
return filter;
}
"
/> />
<RightMenu> <RightMenu>
<template #right-panel> <template #right-panel>