From b36ea51e13b8d4f03b03baae4e3fe81be775988e Mon Sep 17 00:00:00 2001 From: Nitwel Date: Mon, 12 Sep 2022 23:55:08 +0200 Subject: [PATCH] Fix duplicate indexes (#15500) * fix duplicate indexes * lint Co-authored-by: Azri Kahar <42867097+azrikahar@users.noreply.github.com> --- app/src/composables/use-relation-multiple.ts | 23 ++++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/app/src/composables/use-relation-multiple.ts b/app/src/composables/use-relation-multiple.ts index 8a035dde6c..6fe8d80307 100644 --- a/app/src/composables/use-relation-multiple.ts +++ b/app/src/composables/use-relation-multiple.ts @@ -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;