#8113 create arrayDataStore map #979

Closed
jorgep wants to merge 17 commits from 8113-preventDuplicateRecords into dev
1 changed files with 14 additions and 10 deletions
Showing only changes of commit 683940cc24 - Show all commits

View File

@ -124,24 +124,28 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
store.data = []; store.data = [];
store.map = new Map(); store.map = new Map();
} }
const totalRows = store.data.length;
response.data.forEach((row) => { response.data.forEach((row, position) => {
const key = row.id; const key = row.id;
const val = { ...row, key };
if (!store.map.has(key)) store.data.push({ ...row, key }); if (!store.map.has(key)) {
else { store.data.push({ ...val, position: totalRows + position });
const dataIndex = store.data.findIndex((item) => item.key === key); } else {
store.data[dataIndex] = { ...row, key }; 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 { } else {
store.data = []; store.data = [];
response.data.forEach((row) => { response.data.forEach((row, position) => {
const key = row.id; const key = row.id;
store.data.push({ ...row, key }); const val = { ...row, key, position };
store.map.set(key, row); store.data.push(val);
store.map.set(key, val);
}); });
if (!isDialogOpened()) updateRouter && updateStateParams(); if (!isDialogOpened()) updateRouter && updateStateParams();
} }