refactor: refs #8113 fine tunning processData
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jorge Penadés 2024-11-25 16:48:49 +01:00
parent d1684b4ae6
commit e4bac3edab
2 changed files with 26 additions and 28 deletions

View File

@ -120,21 +120,11 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
const { limit } = filter; const { limit } = filter;
store.hasMoreData = limit && response.data.length >= limit; store.hasMoreData = limit && response.data.length >= limit;
if (append) { processData(response.data, { map: !!store.mapKey, append });
if (!store.data) { if (!append && !isDialogOpened()) updateRouter && updateStateParams();
store.data = [];
store.map = new Map();
}
mapData(response.data);
} else {
store.data = [];
mapData(response.data);
if (!isDialogOpened()) updateRouter && updateStateParams();
}
store.isLoading = false; store.isLoading = false;
canceller = null; canceller = null;
return response; return response;
} }
@ -293,22 +283,29 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
router.replace(newUrl); router.replace(newUrl);
} }
function mapData(data) { function processData(data, { map = true, append = true }) {
data.forEach((row) => { if (!store.data) {
const key = row[store.mapKey]; store.data = [];
const val = { ...row, key }; store.map = new Map();
}
if (store.map.has(key)) { if (!map && !append) store.data = data;
const { position } = store.map.get(key); else if (!map && append) store.data.push(...data);
val.position = position; else
store.map.set(key, val); data.forEach((row) => {
store.data[position] = val; const key = row[store.mapKey];
} else { const val = { ...row, key };
val.position = store.map.size; if (store.map.has(key)) {
store.map.set(key, val); const { position } = store.map.get(key);
store.data.push(val); 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); const totalRows = computed(() => (store.data && store.data.length) || 0);

View File

@ -441,6 +441,7 @@ watch(
<QPage class="column items-center q-pa-md"> <QPage class="column items-center q-pa-md">
<VnTable <VnTable
data-key="advanceTickets" data-key="advanceTickets"
:map-key="false"
ref="vnTableRef" ref="vnTableRef"
url="Tickets/getTicketsAdvance" url="Tickets/getTicketsAdvance"
search-url="advanceTickets" search-url="advanceTickets"