refactor: refs #8113 use a fn
gitea/salix-front/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Jorge Penadés 2024-11-25 11:27:28 +01:00
parent ed8c124bc7
commit a9cc6952d0
1 changed files with 20 additions and 30 deletions

View File

@ -124,38 +124,10 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
store.data = [];
store.map = new Map();
}
const totalRows = store.data.length;
response.data.forEach((row, position) => {
const key = row.clientFk;
const val = { ...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, val);
});
mapData(response.data);
} else {
store.data = [];
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);
}
});
mapData(response.data);
if (!isDialogOpened()) updateRouter && updateStateParams();
}
@ -320,6 +292,24 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
router.replace(newUrl);
}
function mapData(data) {
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);
}
});
}
const totalRows = computed(() => (store.data && store.data.length) || 0);
const isLoading = computed(() => store.isLoading || false);