From e4bac3edab0821c8bf3317e820b4c0e2970de9dd Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 25 Nov 2024 16:48:49 +0100 Subject: [PATCH] refactor: refs #8113 fine tunning processData --- src/composables/useArrayData.js | 53 ++++++++++++++---------------- src/pages/Ticket/TicketAdvance.vue | 1 + 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/composables/useArrayData.js b/src/composables/useArrayData.js index 14d5e5b98..25943b2ac 100644 --- a/src/composables/useArrayData.js +++ b/src/composables/useArrayData.js @@ -120,21 +120,11 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) { const { limit } = filter; store.hasMoreData = limit && response.data.length >= limit; - if (append) { - if (!store.data) { - store.data = []; - store.map = new Map(); - } - mapData(response.data); - } else { - store.data = []; - mapData(response.data); - if (!isDialogOpened()) updateRouter && updateStateParams(); - } - + processData(response.data, { map: !!store.mapKey, append }); + if (!append && !isDialogOpened()) updateRouter && updateStateParams(); store.isLoading = false; - canceller = null; + return response; } @@ -293,22 +283,29 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) { router.replace(newUrl); } - function mapData(data) { - data.forEach((row) => { - const key = row[store.mapKey]; - const val = { ...row, key }; + function processData(data, { map = true, append = true }) { + if (!store.data) { + store.data = []; + store.map = new Map(); + } - if (store.map.has(key)) { - const { position } = store.map.get(key); - val.position = position; - store.map.set(key, val); - store.data[position] = val; - } else { - val.position = store.map.size; - store.map.set(key, val); - store.data.push(val); - } - }); + if (!map && !append) store.data = data; + else if (!map && append) store.data.push(...data); + else + data.forEach((row) => { + const key = row[store.mapKey]; + const val = { ...row, key }; + if (store.map.has(key)) { + const { position } = store.map.get(key); + val.position = position; + store.map.set(key, val); + store.data[position] = val; + } else { + val.position = store.map.size; + store.map.set(key, val); + store.data.push(val); + } + }); } const totalRows = computed(() => (store.data && store.data.length) || 0); diff --git a/src/pages/Ticket/TicketAdvance.vue b/src/pages/Ticket/TicketAdvance.vue index 71e3926ac..1b706922e 100644 --- a/src/pages/Ticket/TicketAdvance.vue +++ b/src/pages/Ticket/TicketAdvance.vue @@ -441,6 +441,7 @@ watch(