Revert "Fix update deduplication in useRelationMultiple (#18159)" (#18169)

This commit is contained in:
Nitwel
2023-04-13 18:14:29 +02:00
committed by GitHub
parent 3f2dfdcbc7
commit 4e1d3b72f4
2 changed files with 0 additions and 55 deletions

View File

@@ -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 },

View File

@@ -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') {