Skip to content

Commit

Permalink
115046: Fixed related item not invalidating on relationship deletion …
Browse files Browse the repository at this point in the history
…& automatically invalidate the isSelected value after updating relationship on item
  • Loading branch information
alexandrevryghem committed May 30, 2024
1 parent 62e07e7 commit e7de540
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/app/core/data/relationship-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,13 +574,18 @@ export class RelationshipDataService extends IdentifiableDataService<Relationshi
);
});

return this.searchBy(
const searchRD$: Observable<RemoteData<PaginatedList<Relationship>>> = this.searchBy(
'byItemsAndType',
{
searchParams: searchParams,
},
) as Observable<RemoteData<PaginatedList<Relationship>>>;

arrayOfItemIds.forEach((itemId: string) => {
this.addDependency(searchRD$, this.itemService.getIDHrefObs(encodeURIComponent(itemId)));
});

return searchRD$;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<NoContent>) => {
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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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]),
);
}
}), ),

Check failure on line 552 in src/app/item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

Unexpected trailing comma

Check failure on line 552 in src/app/item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.ts

View workflow job for this annotation

GitHub Actions / tests (20.x)

Unexpected trailing comma
),
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;
Expand All @@ -546,6 +561,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
relationship,
originalIsLeft: isLeftItem,
originalItem: this.item,
relatedItem: relatedItem,
nameVariant,
} as RelationshipIdentifiable;
}),
Expand Down

0 comments on commit e7de540

Please sign in to comment.