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 2fb6d47d31..c3746f0283 100644 --- a/src/app/core/data/object-updates/object-updates.service.ts +++ b/src/app/core/data/object-updates/object-updates.service.ts @@ -19,7 +19,7 @@ import { SetEditableFieldUpdateAction, SetValidFieldUpdateAction } from './object-updates.actions'; -import { distinctUntilChanged, filter, map, switchMap } from 'rxjs/operators'; +import { distinctUntilChanged, filter, map, switchMap, take } from 'rxjs/operators'; import { hasNoValue, hasValue, @@ -198,8 +198,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$; } /** @@ -207,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 */ - 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 57f8116b9c..c4b2bba36f 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 @@ -305,29 +305,28 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { modalComp.submitEv = () => { modalComp.isPending = true; const isLeft = this.currentItemIsLeftItem$.getValue(); - const addOperations = modalComp.toAdd.map((searchResult: any) => ({ type: 'add', searchResult })); - const removeOperations = modalComp.toRemove.map((searchResult: any) => ({ type: 'remove', searchResult })); + const addOperations = modalComp.toAdd.map((searchResult: ItemSearchResult) => ({ type: 'add', searchResult })); + const removeOperations = modalComp.toRemove.map((searchResult: ItemSearchResult) => ({ type: 'remove', searchResult })); observableFrom([...addOperations, ...removeOperations]).pipe( - concatMap(({ type, searchResult }: { type: string, searchResult: any }) => { + concatMap(({ type, searchResult }: { type: string, searchResult: ItemSearchResult }) => { + const relatedItem: Item = searchResult.indexableObject; if (type === 'add') { - const relatedItem = searchResult.indexableObject; return this.relationshipService.getNameVariant(this.listId, relatedItem.uuid).pipe( - map((nameVariant) => { + switchMap((nameVariant) => { const update = { - uuid: this.relationshipType.id + '-' + searchResult.indexableObject.uuid, + uuid: `${this.relationshipType.id}-${relatedItem.uuid}`, nameVariant, type: this.relationshipType, originalIsLeft: isLeft, originalItem: this.item, relatedItem, } as RelationshipIdentifiable; - this.objectUpdatesService.saveAddFieldUpdate(this.url, update); - return update; + return this.objectUpdatesService.saveAddFieldUpdate(this.url, update); }), take(1) ); } else if (type === 'remove') { - return this.relationshipService.getNameVariant(this.listId, searchResult.indexableObjectuuid).pipe( + return this.relationshipService.getNameVariant(this.listId, relatedItem.uuid).pipe( switchMap((nameVariant) => { return this.getRelationFromId(searchResult.indexableObject).pipe( map( (relationship: Relationship) => { @@ -339,9 +338,8 @@ 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); + }), ); }), take(1) diff --git a/src/app/item-page/edit-item-page/virtual-metadata/virtual-metadata.component.html b/src/app/item-page/edit-item-page/virtual-metadata/virtual-metadata.component.html index b83b93d8f1..927f7dbb48 100644 --- a/src/app/item-page/edit-item-page/virtual-metadata/virtual-metadata.component.html +++ b/src/app/item-page/edit-item-page/virtual-metadata/virtual-metadata.component.html @@ -5,9 +5,9 @@