From 4e1d3b72f42e9c973acca7b25678974032324f06 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Thu, 13 Apr 2023 18:14:29 +0200 Subject: [PATCH] Revert "Fix update deduplication in useRelationMultiple (#18159)" (#18169) --- .../composables/use-relation-multiple.test.ts | 40 ------------------- app/src/composables/use-relation-multiple.ts | 15 ------- 2 files changed, 55 deletions(-) diff --git a/app/src/composables/use-relation-multiple.test.ts b/app/src/composables/use-relation-multiple.test.ts index b5d5fe18d9..807a8f4a83 100644 --- a/app/src/composables/use-relation-multiple.test.ts +++ b/app/src/composables/use-relation-multiple.test.ts @@ -223,46 +223,6 @@ describe('test o2m relation', () => { ]); }); - test('updating an item twice without $index', async () => { - const wrapper = mount(TestComponent, { - props: { relation: relationO2M, value: [], id: 1 }, - }); - - wrapper.vm.update({ id: 2, name: 'test2-edited' }); - wrapper.vm.update({ id: 2, name: 'test2-edited again' }); - - await flushPromises(); - - const changes = cloneDeep(workerData); - changes.splice(1, 1, { id: 2, name: 'test2-edited again', facility: 1, $edits: 0, $type: 'updated', $index: 0 }); - - expect(wrapper.vm.displayItems).toEqual(changes); - expect(wrapper.emitted()['update:value'][0]).toEqual([ - { - create: [], - update: [ - { - id: 2, - name: 'test2-edited', - }, - ], - delete: [], - }, - ]); - expect(wrapper.emitted()['update:value'][1]).toEqual([ - { - create: [], - update: [ - { - id: 2, - name: 'test2-edited again', - }, - ], - delete: [], - }, - ]); - }); - test('removing an item', async () => { const wrapper = mount(TestComponent, { props: { relation: relationO2M, value: [], id: 1 }, diff --git a/app/src/composables/use-relation-multiple.ts b/app/src/composables/use-relation-multiple.ts index a351555dde..9a9311d7b5 100644 --- a/app/src/composables/use-relation-multiple.ts +++ b/app/src/composables/use-relation-multiple.ts @@ -206,22 +206,7 @@ export function useRelationMultiple( function update(...items: DisplayItem[]) { if (!relation.value) return; - const targetPKField = - relation.value.type === 'o2m' - ? relation.value.relatedPrimaryKeyField.field - : relation.value.junctionPrimaryKeyField.field; - for (const item of items) { - const editsIndex = - item.$index ?? - target.value.update.findIndex( - (edit: any) => typeof edit === 'object' && edit[targetPKField] === item[targetPKField] - ); - if (item.$index === undefined && editsIndex !== -1) { - item.$index = editsIndex; - item.$type = 'updated'; - } - if (item.$type === undefined || item.$index === undefined) { target.value.update.push(cleanItem(item)); } else if (item.$type === 'created') {