From 99600f995d62fac707db1cf596025cafdecec594 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 20 Nov 2024 17:27:52 +0100 Subject: [PATCH 01/12] fix: refs #8113 create arrayData store map wip --- src/composables/useArrayData.js | 25 ++++++++++++++++++++++--- src/stores/useArrayDataStore.js | 1 + 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/composables/useArrayData.js b/src/composables/useArrayData.js index ac0c1da08..418c1f99c 100644 --- a/src/composables/useArrayData.js +++ b/src/composables/useArrayData.js @@ -120,10 +120,29 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) { store.hasMoreData = limit && response.data.length >= limit; if (append) { - if (!store.data) store.data = []; - for (const row of response.data) store.data.push(row); + if (!store.data) { + store.data = []; + store.map = new Map(); + } + + response.data.forEach((row) => { + const key = row.id; + + if (!store.map.has(key)) store.data.push({ ...row, key }); + else { + const dataIndex = store.data.findIndex((item) => item.key === key); + store.data[dataIndex] = { ...row, key }; + } + + store.map.set(key, row); + }); } else { - store.data = response.data; + store.data = []; + response.data.forEach((row) => { + const key = row.id; + store.data.push({ ...row, key }); + store.map.set(key, row); + }); if (!isDialogOpened()) updateRouter && updateStateParams(); } diff --git a/src/stores/useArrayDataStore.js b/src/stores/useArrayDataStore.js index 6a0e7dfa8..8301f3a6f 100644 --- a/src/stores/useArrayDataStore.js +++ b/src/stores/useArrayDataStore.js @@ -46,6 +46,7 @@ export const useArrayDataStore = defineStore('arrayDataStore', () => { function getDefaultState() { return Object.assign(JSON.parse(JSON.stringify(defaultOpts)), { data: ref(), + map: ref(new Map()), }); } -- 2.40.1 From 683940cc24d6e5bfdaa96e57d13cf1777c8efd46 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 22 Nov 2024 10:13:50 +0100 Subject: [PATCH 02/12] fix: refs #8113 improve logic wip --- src/composables/useArrayData.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/composables/useArrayData.js b/src/composables/useArrayData.js index 418c1f99c..d08307171 100644 --- a/src/composables/useArrayData.js +++ b/src/composables/useArrayData.js @@ -124,24 +124,28 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) { store.data = []; store.map = new Map(); } - - response.data.forEach((row) => { + const totalRows = store.data.length; + response.data.forEach((row, position) => { const key = row.id; + const val = { ...row, key }; - if (!store.map.has(key)) store.data.push({ ...row, key }); - else { - const dataIndex = store.data.findIndex((item) => item.key === key); - store.data[dataIndex] = { ...row, key }; + if (!store.map.has(key)) { + store.data.push({ ...val, position: totalRows + position }); + } else { + const record = store.map.get(key); + const curPosition = record.position; + store.data[curPosition] = { ...val, position: curPosition }; } - store.map.set(key, row); + store.map.set(key, val); }); } else { store.data = []; - response.data.forEach((row) => { + response.data.forEach((row, position) => { const key = row.id; - store.data.push({ ...row, key }); - store.map.set(key, row); + const val = { ...row, key, position }; + store.data.push(val); + store.map.set(key, val); }); if (!isDialogOpened()) updateRouter && updateStateParams(); } -- 2.40.1 From ed8c124bc771fb240b9a3c67f12005a5a86fb1ac Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 22 Nov 2024 18:16:11 +0100 Subject: [PATCH 03/12] fix: refs #8113 load map logic --- src/composables/useArrayData.js | 21 +++++++++++++++------ src/pages/Monitor/Ticket/MonitorTickets.vue | 1 + 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/composables/useArrayData.js b/src/composables/useArrayData.js index 999998983..8547f0a2f 100644 --- a/src/composables/useArrayData.js +++ b/src/composables/useArrayData.js @@ -126,7 +126,7 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) { } const totalRows = store.data.length; response.data.forEach((row, position) => { - const key = row.id; + const key = row.clientFk; const val = { ...row, key }; if (!store.map.has(key)) { @@ -141,11 +141,20 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) { }); } else { store.data = []; - response.data.forEach((row, position) => { - const key = row.id; - const val = { ...row, key, position }; - store.data.push(val); - store.map.set(key, val); + response.data.forEach((row) => { + const key = row.clientFk; + 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); + } }); if (!isDialogOpened()) updateRouter && updateStateParams(); } diff --git a/src/pages/Monitor/Ticket/MonitorTickets.vue b/src/pages/Monitor/Ticket/MonitorTickets.vue index e6bf242ac..67601a32c 100644 --- a/src/pages/Monitor/Ticket/MonitorTickets.vue +++ b/src/pages/Monitor/Ticket/MonitorTickets.vue @@ -341,6 +341,7 @@ const openTab = (id) => :row-click="({ id }) => openTab(id)" :disable-option="{ card: true }" :user-params="{ from, to, scopeDays: 1 }" + :limit="3" >