From 9daffdfa22d95949065044b4d3e48758fea62546 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 16 Jan 2024 08:40:03 +0100 Subject: [PATCH] refs #6704: posible fix --- src/components/ui/VnFilterPanel.vue | 37 ++++++++++++++++------------- src/components/ui/VnPaginate.vue | 11 ++++----- src/composables/useArrayData.js | 8 +++++-- src/stores/useArrayDataStore.js | 2 ++ 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/components/ui/VnFilterPanel.vue b/src/components/ui/VnFilterPanel.vue index 0a306dc5f..9cb558467 100644 --- a/src/components/ui/VnFilterPanel.vue +++ b/src/components/ui/VnFilterPanel.vue @@ -65,18 +65,6 @@ onMounted(() => { const isLoading = ref(false); -async function search() { - isLoading.value = true; - const params = { ...userParams.value }; - const { params: newParams } = await arrayData.addFilter({ params }); - userParams.value = newParams; - - if (!props.showAll && !Object.values(params).length) store.data = []; - - isLoading.value = false; - emit('search'); -} - async function reload() { isLoading.value = true; const params = Object.values(userParams.value).filter((param) => param); @@ -87,6 +75,25 @@ async function reload() { emit('refresh'); } +async function search() { + isLoading.value = true; + const params = { ...userParams.value }; + store.pagination = true; + store.filter.skip = 0; + store.skip = 0; + const { params: newParams } = await arrayData.addFilter({ params }); + userParams.value = newParams; + + if (!props.showAll && !Object.values(params).length) store.data = []; + + isLoading.value = false; + emit('search'); +} +async function remove(key) { + userParams.value[key] = null; + await search(); + emit('remove', key); +} async function clearFilters() { isLoading.value = true; @@ -126,11 +133,7 @@ const customTags = computed(() => tagsList.value.filter((tag) => (props.customTags || []).includes(tag.label)) ); -async function remove(key) { - userParams.value[key] = null; - await search(); - emit('remove', key); -} + function formatValue(value) { if (typeof value === 'boolean') { diff --git a/src/components/ui/VnPaginate.vue b/src/components/ui/VnPaginate.vue index ecebf8933..ea52a2943 100644 --- a/src/components/ui/VnPaginate.vue +++ b/src/components/ui/VnPaginate.vue @@ -81,14 +81,13 @@ const store = arrayData.store; onMounted(() => { if (props.autoLoad) fetch(); }); -onUnmounted(async ()=>{ - arrayData.destroy() -}); -watch( - () => props.data, + +watch(()=>[props.data, store], () => { // store.skip = 0; store.data = props.data; + if(store.pagination) + paginate() } ); @@ -187,7 +186,7 @@ async function onLoad(...params) { v-if="store.data" @load="onLoad" :offset="offset" - class="full-width full-height overflow-auto" + class="full-width full-height" >
diff --git a/src/composables/useArrayData.js b/src/composables/useArrayData.js index d5c564373..7ed15baf3 100644 --- a/src/composables/useArrayData.js +++ b/src/composables/useArrayData.js @@ -99,7 +99,10 @@ export function useArrayData(key, userOptions) { const { limit } = filter; hasMoreData.value = response.data.length === limit; - + if (store.pagination) { + // await loadMore(); + store.pagination = false; + } if (append) { if (!store.data) store.data = []; for (const row of response.data) store.data.push(row); @@ -143,7 +146,8 @@ export function useArrayData(key, userOptions) { store.userParams = userParams; store.skip = 0; - await fetch({ append: false }); + store.filter.skip = 0; + await fetch({ append: false, loadMore: true }); return { filter, params }; } async function removeFilter({ filter, params }) { diff --git a/src/stores/useArrayDataStore.js b/src/stores/useArrayDataStore.js index 223406a33..94e772a87 100644 --- a/src/stores/useArrayDataStore.js +++ b/src/stores/useArrayDataStore.js @@ -19,6 +19,8 @@ export const useArrayDataStore = defineStore('arrayDataStore', () => { order: '', data: ref(), isLoading: false, + loadMore: false, + pagination: false, exprBuilder: null, }; }