From 9b0736c96fd9877c44a1749971ed07a3882dc761 Mon Sep 17 00:00:00 2001 From: Alexandre Vryghem Date: Thu, 30 May 2024 16:55:35 +0200 Subject: [PATCH] 115046: Fixed issue where store operations would sometimes be performed in incorrect order --- .../object-updates/object-updates.service.ts | 17 +++++++++++++++-- .../edit-relationship-list.component.ts | 8 +++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/app/core/data/object-updates/object-updates.service.ts b/src/app/core/data/object-updates/object-updates.service.ts index 1f036ddfb1d..75b554d87b1 100644 --- a/src/app/core/data/object-updates/object-updates.service.ts +++ b/src/app/core/data/object-updates/object-updates.service.ts @@ -15,6 +15,7 @@ import { filter, map, switchMap, + take, } from 'rxjs/operators'; import { @@ -212,8 +213,14 @@ export class ObjectUpdatesService { * @param url The page's URL for which the changes are saved * @param field An updated field for the page's object */ - saveAddFieldUpdate(url: string, field: Identifiable) { + saveAddFieldUpdate(url: string, field: Identifiable): Observable { + const update$: Observable = this.getFieldUpdatesExclusive(url, [field]).pipe( + filter((fieldUpdates: FieldUpdates) => fieldUpdates[field.uuid].changeType === FieldChangeType.ADD), + take(1), + map(() => true), + ); this.saveFieldUpdate(url, field, FieldChangeType.ADD); + return update$; } /** @@ -221,8 +228,14 @@ export class ObjectUpdatesService { * @param url The page's URL for which the changes are saved * @param field An updated field for the page's object */ - saveRemoveFieldUpdate(url: string, field: Identifiable) { + saveRemoveFieldUpdate(url: string, field: Identifiable): Observable { + const update$: Observable = this.getFieldUpdatesExclusive(url, [field]).pipe( + filter((fieldUpdates: FieldUpdates) => fieldUpdates[field.uuid].changeType === FieldChangeType.REMOVE), + take(1), + map(() => true), + ); this.saveFieldUpdate(url, field, FieldChangeType.REMOVE); + return update$; } /** diff --git a/src/app/item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.ts b/src/app/item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.ts index 15fec857668..e396c5ee927 100644 --- a/src/app/item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.ts +++ b/src/app/item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.ts @@ -342,7 +342,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { const relatedItem: Item = searchResult.indexableObject; if (type === 'add') { return this.relationshipService.getNameVariant(this.listId, relatedItem.uuid).pipe( - map((nameVariant) => { + switchMap((nameVariant) => { const update = { uuid: `${this.relationshipType.id}-${relatedItem.uuid}`, nameVariant, @@ -351,8 +351,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { originalItem: this.item, relatedItem, } as RelationshipIdentifiable; - this.objectUpdatesService.saveAddFieldUpdate(this.url, update); - return update; + return this.objectUpdatesService.saveAddFieldUpdate(this.url, update); }), take(1), ); @@ -369,8 +368,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { originalItem: this.item, relationship, } as RelationshipIdentifiable; - this.objectUpdatesService.saveRemoveFieldUpdate(this.url,update); - return update; + return this.objectUpdatesService.saveRemoveFieldUpdate(this.url,update); }), ); }),