Fix duplicate indexes (#15500)

* fix duplicate indexes

* lint

Co-authored-by: Azri Kahar <42867097+azrikahar@users.noreply.github.com>
This commit is contained in:
Nitwel
2022-09-12 23:55:08 +02:00
committed by GitHub
parent e72ae3b2a7
commit b36ea51e13

View File

@@ -91,8 +91,16 @@ export function useRelationMultiple(
const info = relation.value;
if (info?.type === undefined) return [];
if (info.type === 'o2m') return _value.value.create;
return _value.value.create.filter((item) => item[info.reverseJunctionField.field] === undefined);
const items = _value.value.create.map((item, index) => {
return {
...item,
$type: 'created',
$index: index,
} as DisplayItem;
});
if (info.type === 'o2m') return items;
return items.filter((item) => item[info.reverseJunctionField.field] === undefined);
});
const displayItems = computed(() => {
@@ -159,16 +167,7 @@ export function useRelationMultiple(
const newItems = getPage(existingItemCount.value + selected.value.length, createdItems.value);
items.push(
...selectedOnPage,
...newItems.map((item, index) => {
return {
...item,
$type: 'created',
$index: index,
} as DisplayItem;
})
);
items.push(...selectedOnPage, ...newItems);
const sortField = relation.value.sortField;