From 972c340fad8043f67cfc33861d3dcc2f3052643d Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 15 Jan 2024 14:44:38 +0100 Subject: [PATCH 1/6] refs #6704: fix1 --- src/components/ui/VnPaginate.vue | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/components/ui/VnPaginate.vue b/src/components/ui/VnPaginate.vue index 1aa99ea0c..ecebf8933 100644 --- a/src/components/ui/VnPaginate.vue +++ b/src/components/ui/VnPaginate.vue @@ -1,10 +1,12 @@ @@ -183,6 +210,7 @@ async function onLoad(...params) { 0) { + hasMoreData.value = true; + } else if(store.userParamsChanged){ + hasMoreData.value = false; } + else */hasMoreData.value = response.data.length === limit; + // if (store.pagination) { + // console.error('Before-ArrayData', store.pagination, hasMoreData.value) + // hasMoreData.value = true; + // console.error('After-ArrayData', store.pagination, hasMoreData.value) + // } if (append) { if (!store.data) store.data = []; for (const row of response.data) store.data.push(row); @@ -182,6 +188,7 @@ export function useArrayData(key, userOptions) { async function loadMore() { if (!hasMoreData.value) return; + console.error('loadMore', hasMoreData.value); store.skip = store.limit * page.value; page.value += 1; @@ -200,7 +207,7 @@ export function useArrayData(key, userOptions) { if (store.skip) query.skip = store.skip; if (store.userParams && Object.keys(store.userParams).length !== 0) query.params = JSON.stringify(store.userParams); - + // hasMoreData.value = true; if (router) router.replace({ path: route.path, diff --git a/src/stores/useArrayDataStore.js b/src/stores/useArrayDataStore.js index 94e772a87..c8cd349e0 100644 --- a/src/stores/useArrayDataStore.js +++ b/src/stores/useArrayDataStore.js @@ -21,6 +21,7 @@ export const useArrayDataStore = defineStore('arrayDataStore', () => { isLoading: false, loadMore: false, pagination: false, + userParamsChanged: true, exprBuilder: null, }; } From a94fb6026a9bd20a295bb7c69e8b3230fe0b7379 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 16 Jan 2024 12:14:48 +0100 Subject: [PATCH 5/6] refs #6704: remove bad code --- src/components/ui/VnFilterPanel.vue | 47 ++++++++++++++--------------- src/components/ui/VnPaginate.vue | 46 ++-------------------------- src/composables/useArrayData.js | 30 +++--------------- src/pages/Claim/Card/ClaimNotes.vue | 2 +- src/stores/useArrayDataStore.js | 2 -- 5 files changed, 30 insertions(+), 97 deletions(-) diff --git a/src/components/ui/VnFilterPanel.vue b/src/components/ui/VnFilterPanel.vue index 6b6960243..dfe0e57ab 100644 --- a/src/components/ui/VnFilterPanel.vue +++ b/src/components/ui/VnFilterPanel.vue @@ -64,6 +64,20 @@ onMounted(() => { }); const isLoading = ref(false); +async function search() { + isLoading.value = true; + const params = { ...userParams.value }; + store.userParamsChanged = 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 reload() { isLoading.value = true; @@ -75,35 +89,14 @@ async function reload() { emit('refresh'); } -async function search() { - isLoading.value = true; - const params = { ...userParams.value }; - store.pagination = true; - store.userParamsChanged = 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; - // store.pagination = false; - - emit('search'); -} -async function remove(key) { - userParams.value[key] = null; - await search(); - emit('remove', key); -} async function clearFilters() { isLoading.value = true; store.userParamsChanged = true; - + store.filter.skip = 0; + store.skip = 0; // Filtrar los params no removibles const removableFilters = Object.keys(userParams.value).filter((param) => - props.unremovableParams.includes(param) + props.unremovableParams.includes(param) ); const newParams = {}; // Conservar solo los params que no son removibles @@ -137,7 +130,11 @@ 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 dfb19ed88..4c38c1c1a 100644 --- a/src/components/ui/VnPaginate.vue +++ b/src/components/ui/VnPaginate.vue @@ -1,19 +1,10 @@ @@ -210,7 +171,6 @@ async function onLoad(...params) { 0) { - hasMoreData.value = true; - } else if(store.userParamsChanged){ - hasMoreData.value = false; - } - else */hasMoreData.value = response.data.length === limit; - // if (store.pagination) { - // console.error('Before-ArrayData', store.pagination, hasMoreData.value) - // hasMoreData.value = true; - // console.error('After-ArrayData', store.pagination, hasMoreData.value) - // } + hasMoreData.value = response.data.length === limit; + if (append) { if (!store.data) store.data = []; for (const row of response.data) store.data.push(row); @@ -153,18 +144,7 @@ export function useArrayData(key, userOptions) { store.userParams = userParams; store.skip = 0; store.filter.skip = 0; - await fetch({ append: false, loadMore: true }); - return { filter, params }; - } - async function removeFilter({ filter, params }) { - if (filter) store.userFilter = Object.assign(store.userFilter, filter); - - let userParams = Object.assign({}, store.userParams, params); - userParams = sanitizerParams(userParams, store?.exprBuilder); - - store.userParams = userParams; - store.skip = 0; - await loadMore({ append: false }); + await fetch({ append: false }); return { filter, params }; } @@ -188,7 +168,6 @@ export function useArrayData(key, userOptions) { async function loadMore() { if (!hasMoreData.value) return; - console.error('loadMore', hasMoreData.value); store.skip = store.limit * page.value; page.value += 1; @@ -207,7 +186,7 @@ export function useArrayData(key, userOptions) { if (store.skip) query.skip = store.skip; if (store.userParams && Object.keys(store.userParams).length !== 0) query.params = JSON.stringify(store.userParams); - // hasMoreData.value = true; + if (router) router.replace({ path: route.path, @@ -222,7 +201,6 @@ export function useArrayData(key, userOptions) { fetch, applyFilter, addFilter, - removeFilter, refresh, destroy, loadMore, diff --git a/src/pages/Claim/Card/ClaimNotes.vue b/src/pages/Claim/Card/ClaimNotes.vue index 35ecb0451..eeaffc85a 100644 --- a/src/pages/Claim/Card/ClaimNotes.vue +++ b/src/pages/Claim/Card/ClaimNotes.vue @@ -30,7 +30,7 @@ const body = {