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 e13334348c7..4809a4f7309 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 @@ -316,25 +316,44 @@ describe('EditItemRelationshipsService', () => { describe('relationshipMatchesBothSameTypes', () => { it('should return true if both left and right type of the relationship type are the same and match the provided itemtype', (done) => { const relationshipType = Object.assign(new RelationshipType(), { - leftType: createSuccessfulRemoteDataObject$({ id: 'sameType' }), + leftType: createSuccessfulRemoteDataObject$({ id: 'sameType' }), rightType: createSuccessfulRemoteDataObject$({ id:'sameType' }), + leftwardType: 'isDepartmentOfDivision', + rightwardType: 'isDivisionOfDepartment', }); const itemType = Object.assign(new ItemType(), { id: 'sameType' } ); - const result = service.relationshipMatchesBothSameTypes(relationshipType, itemType); + const result = service.shouldDisplayBothRelationshipSides(relationshipType, itemType); result.subscribe((resultValue) => { expect(resultValue).toBeTrue(); done(); }); }); + it('should return false if both left and right type of the relationship type are the same and match the provided itemtype but the leftwardType & rightwardType is identical', (done) => { + const relationshipType = Object.assign(new RelationshipType(), { + leftType: createSuccessfulRemoteDataObject$({ id: 'sameType' }), + rightType: createSuccessfulRemoteDataObject$({ id: 'sameType' }), + leftwardType: 'isOrgUnitOfOrgUnit', + rightwardType: 'isOrgUnitOfOrgUnit', + }); + const itemType = Object.assign(new ItemType(), { id: 'sameType' }); + + const result = service.shouldDisplayBothRelationshipSides(relationshipType, itemType); + result.subscribe((resultValue) => { + expect(resultValue).toBeFalse(); + done(); + }); + }); it('should return false if both left and right type of the relationship type are the same and do not match the provided itemtype', (done) => { const relationshipType = Object.assign(new RelationshipType(), { leftType: createSuccessfulRemoteDataObject$({ id: 'sameType' }), rightType: createSuccessfulRemoteDataObject$({ id: 'sameType' }), + leftwardType: 'isDepartmentOfDivision', + rightwardType: 'isDivisionOfDepartment', }); const itemType = Object.assign(new ItemType(), { id: 'something-else' } ); - const result = service.relationshipMatchesBothSameTypes(relationshipType, itemType); + const result = service.shouldDisplayBothRelationshipSides(relationshipType, itemType); result.subscribe((resultValue) => { expect(resultValue).toBeFalse(); done(); @@ -344,10 +363,12 @@ describe('EditItemRelationshipsService', () => { const relationshipType = Object.assign(new RelationshipType(), { leftType: createSuccessfulRemoteDataObject$({ id: 'leftType' }), rightType: createSuccessfulRemoteDataObject$({ id: 'rightType' }), + leftwardType: 'isAuthorOfPublication', + rightwardType: 'isPublicationOfAuthor', }); const itemType = Object.assign(new ItemType(), { id: 'leftType' } ); - const result = service.relationshipMatchesBothSameTypes(relationshipType, itemType); + const result = service.shouldDisplayBothRelationshipSides(relationshipType, itemType); result.subscribe((resultValue) => { expect(resultValue).toBeFalse(); done(); 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 29d0e7fe3a3..e66562fe19e 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 @@ -216,10 +216,16 @@ export class EditItemRelationshipsService { ); } - relationshipMatchesBothSameTypes(relationshipType: RelationshipType, itemType: ItemType): Observable { + /** + * Whether both side of the relationship need to be displayed on the edit relationship page or not. + * + * @param relationshipType The relationship type + * @param itemType The item type + */ + shouldDisplayBothRelationshipSides(relationshipType: RelationshipType, itemType: ItemType): Observable { return this.getRelationshipLeftAndRightType(relationshipType).pipe( map(([leftType, rightType]: [ItemType, ItemType]) => { - return leftType.id === itemType.id && rightType.id === itemType.id; + return leftType.id === itemType.id && rightType.id === itemType.id && relationshipType.leftwardType !== relationshipType.rightwardType; }), ); } diff --git a/src/app/item-page/edit-item-page/item-relationships/edit-relationship-list-wrapper/edit-relationship-list-wrapper.component.html b/src/app/item-page/edit-item-page/item-relationships/edit-relationship-list-wrapper/edit-relationship-list-wrapper.component.html index ec6aa6cef27..ed7fb190f2d 100644 --- a/src/app/item-page/edit-item-page/item-relationships/edit-relationship-list-wrapper/edit-relationship-list-wrapper.component.html +++ b/src/app/item-page/edit-item-page/item-relationships/edit-relationship-list-wrapper/edit-relationship-list-wrapper.component.html @@ -1,4 +1,4 @@ - + - + { editItemRelationshipsService = jasmine.createSpyObj('editItemRelationshipsService', { isProvidedItemTypeLeftType: observableOf(true), - relationshipMatchesBothSameTypes: observableOf(false), + shouldDisplayBothRelationshipSides: observableOf(false), }); @@ -82,10 +83,10 @@ describe('EditRelationshipListWrapperComponent', () => { }); it('should set currentItemIsLeftItem$ and bothItemsMatchType$ based on the provided relationshipType, itemType and item', () => { expect(editItemRelationshipsService.isProvidedItemTypeLeftType).toHaveBeenCalledWith(relationshipType, leftType, item); - expect(editItemRelationshipsService.relationshipMatchesBothSameTypes).toHaveBeenCalledWith(relationshipType, leftType); + expect(editItemRelationshipsService.shouldDisplayBothRelationshipSides).toHaveBeenCalledWith(relationshipType, leftType); expect(comp.currentItemIsLeftItem$.getValue()).toEqual(true); - expect(comp.bothItemsMatchType$.getValue()).toEqual(false); + expect(comp.shouldDisplayBothRelationshipSides$).toBeObservable(cold('(a|)', { a: false })); }); }); @@ -109,7 +110,7 @@ describe('EditRelationshipListWrapperComponent', () => { describe('when the current item is both left and right', () => { it('should render two relationship list sections', () => { - (editItemRelationshipsService.relationshipMatchesBothSameTypes as jasmine.Spy).and.returnValue(observableOf(true)); + (editItemRelationshipsService.shouldDisplayBothRelationshipSides as jasmine.Spy).and.returnValue(observableOf(true)); comp.ngOnInit(); fixture.detectChanges(); diff --git a/src/app/item-page/edit-item-page/item-relationships/edit-relationship-list-wrapper/edit-relationship-list-wrapper.component.ts b/src/app/item-page/edit-item-page/item-relationships/edit-relationship-list-wrapper/edit-relationship-list-wrapper.component.ts index f2cb790ff8d..943a1475462 100644 --- a/src/app/item-page/edit-item-page/item-relationships/edit-relationship-list-wrapper/edit-relationship-list-wrapper.component.ts +++ b/src/app/item-page/edit-item-page/item-relationships/edit-relationship-list-wrapper/edit-relationship-list-wrapper.component.ts @@ -79,7 +79,7 @@ export class EditRelationshipListWrapperComponent implements OnInit, OnDestroy { isRightItem$ = new BehaviorSubject(false); - bothItemsMatchType$: BehaviorSubject = new BehaviorSubject(undefined); + shouldDisplayBothRelationshipSides$: Observable; /** * Array to track all subscriptions and unsubscribe them onDestroy @@ -99,10 +99,7 @@ export class EditRelationshipListWrapperComponent implements OnInit, OnDestroy { this.currentItemIsLeftItem$.next(nextValue); })); - this.subs.push(this.editItemRelationshipsService.relationshipMatchesBothSameTypes(this.relationshipType, this.itemType) - .subscribe((nextValue: boolean) => { - this.bothItemsMatchType$.next(nextValue); - })); + this.shouldDisplayBothRelationshipSides$ = this.editItemRelationshipsService.shouldDisplayBothRelationshipSides(this.relationshipType, this.itemType); } diff --git a/src/app/item-page/edit-item-page/item-relationships/edit-relationship/edit-relationship.component.ts b/src/app/item-page/edit-item-page/item-relationships/edit-relationship/edit-relationship.component.ts index 97cfb7a16bb..f79d0ee0d1d 100644 --- a/src/app/item-page/edit-item-page/item-relationships/edit-relationship/edit-relationship.component.ts +++ b/src/app/item-page/edit-item-page/item-relationships/edit-relationship/edit-relationship.component.ts @@ -131,9 +131,7 @@ export class EditRelationshipComponent implements OnChanges { this.leftItem$, this.rightItem$, ]).pipe( - map((items: Item[]) => - items.find((item) => item.uuid !== this.editItem.uuid), - ), + map(([leftItem, rightItem]: [Item, Item]) => leftItem.uuid === this.editItem.uuid ? rightItem : leftItem), take(1), ).subscribe((relatedItem) => { this.relatedItem$.next(relatedItem);