From b4dad7a29b94947915d8918ccbc89ae4ea8e28e7 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Sun, 2 Mar 2025 23:22:01 +0100 Subject: [PATCH] revert: filter logic moved to other branch --- src/components/ui/VnFilterPanel.vue | 31 ++----------------- src/components/ui/VnSearchbar.vue | 22 ++++---------- src/composables/useArrayData.js | 30 +++++-------------- src/pages/Ticket/TicketFilter.vue | 46 ++--------------------------- src/pages/Ticket/TicketList.vue | 21 ++++++++----- 5 files changed, 30 insertions(+), 120 deletions(-) diff --git a/src/components/ui/VnFilterPanel.vue b/src/components/ui/VnFilterPanel.vue index c6bc11e2b..d6b525dc8 100644 --- a/src/components/ui/VnFilterPanel.vue +++ b/src/components/ui/VnFilterPanel.vue @@ -61,14 +61,6 @@ const $props = defineProps({ type: Object, default: null, }, - validations: { - type: Array, - default: () => [], - }, - excludeParams: { - type: Object, - default: null, - }, }); const emit = defineEmits([ @@ -92,37 +84,18 @@ const arrayData = const store = arrayData.store; const userParams = ref(useFilterParams($props.dataKey).params); const userOrders = ref(useFilterParams($props.dataKey).orders); -const isLoading = ref(false); -const excludeParams = ref($props.excludeParams); defineExpose({ search, params: userParams, remove }); +const isLoading = ref(false); async function search(evt) { try { - const validations = $props.validations.every((validation) => { - return validation(userParams.value); - }); - - if (!validations) { - return; - } - - if (Object.keys(userParams.value).length) { - excludeParams.value = null; - } - if (evt && $props.disableSubmitEvent) return; store.filter.where = {}; isLoading.value = true; - const filter = { ...userParams.value, ...$props.modelValue, ...evt }; + const filter = { ...userParams.value, ...$props.modelValue }; store.userParamsChanged = true; - if (excludeParams.value) { - filter.params = { - ...filter.params, - exclude: excludeParams.value, - }; - } await arrayData.addFilter({ params: filter, }); diff --git a/src/components/ui/VnSearchbar.vue b/src/components/ui/VnSearchbar.vue index 064baec20..8607d9694 100644 --- a/src/components/ui/VnSearchbar.vue +++ b/src/components/ui/VnSearchbar.vue @@ -69,10 +69,6 @@ const props = defineProps({ type: Boolean, default: true, }, - filterPanel: { - type: Object, - default: true, - }, }); const searchText = ref(); @@ -89,7 +85,6 @@ if (props.redirect) }; let arrayData = useArrayData(props.dataKey, arrayDataProps); let store = arrayData.store; -const filterPanel = ref(props.filterPanel); const to = computed(() => { const url = { path: route.path, query: { ...(route.query ?? {}) } }; const searchUrl = arrayData.store.searchUrl; @@ -101,6 +96,7 @@ const to = computed(() => { if (searchUrl) url.query[searchUrl] = JSON.stringify(currentFilter); return url; }); + watch( () => props.dataKey, (val) => { @@ -108,12 +104,6 @@ watch( store = arrayData.store; }, ); -watch( - () => props.filterPanel, - (val) => { - filterPanel.value = val; - }, -); onMounted(() => { const params = store.userParams; @@ -126,10 +116,7 @@ async function search() { arrayData.resetPagination(); let filter = { params: { search: searchText.value } }; - if (filterPanel?.value?.filterPanelRef) { - filterPanel.value.filterPanelRef.search(filter); - return; - } + if (!props.searchRemoveParams || !searchText.value) { filter = { params: { @@ -217,8 +204,9 @@ async function search() { } :deep(.q-field--focused) { - .q-icon { - color: black; + .q-icon, + .q-placeholder { + color: var(--vn-black-text-color); } } diff --git a/src/composables/useArrayData.js b/src/composables/useArrayData.js index 1d86fc8e6..fcc61972a 100644 --- a/src/composables/useArrayData.js +++ b/src/composables/useArrayData.js @@ -75,13 +75,12 @@ export function useArrayData(key, userOptions) { } } - async function fetch(fetchOptions) { - let { append = false, updateRouter = true } = fetchOptions ?? {}; + async function fetch({ append = false, updateRouter = true }) { if (!store.url) return; cancelRequest(); canceller = new AbortController(); - let { params, limit } = setCurrentFilter(); + const { params, limit } = setCurrentFilter(); let exprFilter; if (store?.exprBuilder) { @@ -99,10 +98,7 @@ export function useArrayData(key, userOptions) { if (!params?.filter?.order?.length) delete params?.filter?.order; params.filter = JSON.stringify(params.filter); - if (fetchOptions?.exclude) { - delete params.exclude; - params = { ...params.params, ...fetchOptions.exclude }; - } + store.isLoading = true; const response = await axios.get(store.url, { signal: canceller.signal, @@ -154,30 +150,22 @@ export function useArrayData(key, userOptions) { async function applyFilter({ filter, params }, fetchOptions = {}) { if (filter) store.userFilter = filter; store.filter = {}; - if (params?.exclude) { - fetchOptions = { ...fetchOptions, exclude: params.exclude }; - delete params.exclude; - } if (params) store.userParams = { ...params }; + const response = await fetch(fetchOptions); return response; } async function addFilter({ filter, params }) { if (filter) store.filter = filter; - let exclude = {}; - if (params?.params?.exclude) { - exclude = params.params.exclude; - // params = { ...params, ...params.exclude }; - delete params.params.exclude; - } + let userParams = { ...store.userParams, ...params }; userParams = sanitizerParams(userParams, store?.exprBuilder); store.userParams = userParams; resetPagination(); - await fetch({ exclude }); + await fetch({}); return { filter, params }; } @@ -229,11 +217,7 @@ export function useArrayData(key, userOptions) { function sanitizerParams(params, exprBuilder) { for (const param in params) { - if ( - params[param] === '' || - params[param] === null || - !Object.keys(params[param]).length - ) { + if (params[param] === '' || params[param] === null) { delete store.userParams[param]; delete params[param]; if (store.filter?.where) { diff --git a/src/pages/Ticket/TicketFilter.vue b/src/pages/Ticket/TicketFilter.vue index a3193f352..5da2a858c 100644 --- a/src/pages/Ticket/TicketFilter.vue +++ b/src/pages/Ticket/TicketFilter.vue @@ -1,7 +1,6 @@