fix: refs #8113 improve logic wip
gitea/salix-front/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Jorge Penadés 2024-11-22 10:13:50 +01:00
parent 1df23b1b10
commit 683940cc24
1 changed files with 14 additions and 10 deletions

View File

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