diff --git a/src/app/core/data/relationship-data.service.ts b/src/app/core/data/relationship-data.service.ts index 8514ab3e2ad..0ab9a0a3a2e 100644 --- a/src/app/core/data/relationship-data.service.ts +++ b/src/app/core/data/relationship-data.service.ts @@ -574,13 +574,18 @@ export class RelationshipDataService extends IdentifiableDataService>> = this.searchBy( 'byItemsAndType', { searchParams: searchParams, }, ) as Observable>>; + arrayOfItemIds.forEach((itemId: string) => { + this.addDependency(searchRD$, this.itemService.getIDHrefObs(encodeURIComponent(itemId))); + }); + + return searchRD$; } /** diff --git a/src/app/item-page/edit-item-page/item-relationships/edit-item-relationships.service.spec.ts b/src/app/item-page/edit-item-page/item-relationships/edit-item-relationships.service.spec.ts index f9694167838..82bda28db7e 100644 --- a/src/app/item-page/edit-item-page/item-relationships/edit-item-relationships.service.spec.ts +++ b/src/app/item-page/edit-item-page/item-relationships/edit-item-relationships.service.spec.ts @@ -185,6 +185,7 @@ describe('EditItemRelationshipsService', () => { expect(itemService.invalidateByHref).toHaveBeenCalledWith(currentItem.self); expect(itemService.invalidateByHref).toHaveBeenCalledWith(relationshipItem1.self); + expect(itemService.invalidateByHref).toHaveBeenCalledWith(relationshipItem2.self); expect(notificationsService.success).toHaveBeenCalledTimes(1); }); diff --git a/src/app/item-page/edit-item-page/item-relationships/edit-item-relationships.service.ts b/src/app/item-page/edit-item-page/item-relationships/edit-item-relationships.service.ts index 14fa226bf41..f598e96e3be 100644 --- a/src/app/item-page/edit-item-page/item-relationships/edit-item-relationships.service.ts +++ b/src/app/item-page/edit-item-page/item-relationships/edit-item-relationships.service.ts @@ -70,7 +70,15 @@ export class EditItemRelationshipsService { // process each update one by one, while waiting for the previous to finish concatMap((update: FieldUpdate) => { if (update.changeType === FieldChangeType.REMOVE) { - return this.deleteRelationship(update.field as DeleteRelationship).pipe(take(1)); + return this.deleteRelationship(update.field as DeleteRelationship).pipe( + take(1), + switchMap((deleteRD: RemoteData) => { + if (deleteRD.hasSucceeded) { + this.itemService.invalidateByHref((update.field as DeleteRelationship).relatedItem._links.self.href); + } + return [deleteRD]; + }), + ); } else if (update.changeType === FieldChangeType.ADD) { return this.addRelationship(update.field as RelationshipIdentifiable).pipe( take(1), 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 e396c5ee927..ef2f575c730 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 @@ -59,6 +59,7 @@ import { Relationship } from '../../../../core/shared/item-relationships/relatio import { RelationshipType } from '../../../../core/shared/item-relationships/relationship-type.model'; import { getAllSucceededRemoteData, + getFirstCompletedRemoteData, getFirstSucceededRemoteData, getFirstSucceededRemoteDataPayload, getRemoteDataPayload, @@ -366,6 +367,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { type: this.relationshipType, originalIsLeft: isLeft, originalItem: this.item, + relatedItem, relationship, } as RelationshipIdentifiable; return this.objectUpdatesService.saveRemoveFieldUpdate(this.url,update); @@ -533,10 +535,23 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { this.relationshipService.isLeftItem(relationship, this.item).pipe( // emit an array containing both the relationship and whether it's the left item, // as we'll need both - map((isLeftItem: boolean) => [relationship, isLeftItem]), - ), + switchMap((isLeftItem: boolean) => { + if (isLeftItem) { + return relationship.rightItem.pipe( + getFirstCompletedRemoteData(), + getRemoteDataPayload(), + map((relatedItem: Item) => [relationship, isLeftItem, relatedItem]), + ); + } else { + return relationship.leftItem.pipe( + getFirstCompletedRemoteData(), + getRemoteDataPayload(), + map((relatedItem: Item) => [relationship, isLeftItem, relatedItem]), + ); + } + }), ), ), - map(([relationship, isLeftItem]: [Relationship, boolean]) => { + map(([relationship, isLeftItem, relatedItem]: [Relationship, boolean, Item]) => { // turn it into a RelationshipIdentifiable, an const nameVariant = isLeftItem ? relationship.rightwardValue : relationship.leftwardValue; @@ -546,6 +561,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { relationship, originalIsLeft: isLeftItem, originalItem: this.item, + relatedItem: relatedItem, nameVariant, } as RelationshipIdentifiable; }),