From b9ef900b8a1c55913da2d60e80f736c7851d4bcf Mon Sep 17 00:00:00 2001 From: Alexandre Vryghem Date: Tue, 28 May 2024 12:02:16 +0200 Subject: [PATCH 1/2] 115046: Fixed related item not invalidating on relationship deletion & automatically invalidate the isSelected value after updating relationship on item --- .../core/data/relationship-data.service.ts | 7 +++++- .../edit-item-relationships.service.spec.ts | 1 + .../edit-item-relationships.service.ts | 10 +++++++- .../edit-relationship-list.component.ts | 24 ++++++++++++++++--- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/app/core/data/relationship-data.service.ts b/src/app/core/data/relationship-data.service.ts index a7ab4eb31c3..e3776d9bcab 100644 --- a/src/app/core/data/relationship-data.service.ts +++ b/src/app/core/data/relationship-data.service.ts @@ -555,13 +555,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 2cecd878b7f..966499a3aa1 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 @@ -58,7 +58,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 57f8116b9cc..7ef3e5969ab 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 @@ -33,6 +33,7 @@ import { } from '../../../../core/shared/item-relationships/relationship-type.model'; import { getAllSucceededRemoteData, + getFirstCompletedRemoteData, getFirstSucceededRemoteData, getFirstSucceededRemoteDataPayload, getRemoteDataPayload, @@ -309,12 +310,12 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { const removeOperations = modalComp.toRemove.map((searchResult: any) => ({ type: 'remove', searchResult })); observableFrom([...addOperations, ...removeOperations]).pipe( concatMap(({ type, searchResult }: { type: string, searchResult: any }) => { + const relatedItem: Item = searchResult.indexableObject; if (type === 'add') { - const relatedItem = searchResult.indexableObject; return this.relationshipService.getNameVariant(this.listId, relatedItem.uuid).pipe( map((nameVariant) => { const update = { - uuid: this.relationshipType.id + '-' + searchResult.indexableObject.uuid, + uuid: `${this.relationshipType.id}-${searchResult.indexableObject.uuid}`, nameVariant, type: this.relationshipType, originalIsLeft: isLeft, @@ -337,6 +338,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { type: this.relationshipType, originalIsLeft: isLeft, originalItem: this.item, + relatedItem, relationship, } as RelationshipIdentifiable; this.objectUpdatesService.saveRemoveFieldUpdate(this.url,update); @@ -508,7 +510,22 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { map((isLeftItem: boolean) => [relationship, isLeftItem]) ) ), - map(([relationship, isLeftItem]: [Relationship, boolean]) => { + switchMap(([relationship, isLeftItem]: [Relationship, 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, relatedItem]: [Relationship, boolean, Item]) => { // turn it into a RelationshipIdentifiable, an const nameVariant = isLeftItem ? relationship.rightwardValue : relationship.leftwardValue; @@ -518,6 +535,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { relationship, originalIsLeft: isLeftItem, originalItem: this.item, + relatedItem: relatedItem, nameVariant, } as RelationshipIdentifiable; }), From 557dfbab6a6921379d98351de821a54e7451d663 Mon Sep 17 00:00:00 2001 From: Alexandre Vryghem Date: Tue, 28 May 2024 13:38:23 +0200 Subject: [PATCH 2/2] 115046: Fixed incorrect name variant being saved in the store when marking relationship ready for deletion --- .../edit-relationship-list.component.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 7ef3e5969ab..d56370cee96 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 @@ -306,16 +306,16 @@ 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') { return this.relationshipService.getNameVariant(this.listId, relatedItem.uuid).pipe( map((nameVariant) => { const update = { - uuid: `${this.relationshipType.id}-${searchResult.indexableObject.uuid}`, + uuid: `${this.relationshipType.id}-${relatedItem.uuid}`, nameVariant, type: this.relationshipType, originalIsLeft: isLeft, @@ -328,7 +328,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { 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) => {