#8113 create arrayDataStore map #979

Open
jorgep wants to merge 16 commits from 8113-preventDuplicateRecords into dev
2 changed files with 23 additions and 3 deletions
Showing only changes of commit 99600f995d - Show all commits

View File

@ -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();
}

View File

@ -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()),
});
}