Skip to content

Commit 813db7c

Browse files
115046: Fixed same type entity relationships with same leftward/rightward type displaying twice
1 parent 6d1e6f9 commit 813db7c

6 files changed

Lines changed: 46 additions & 22 deletions

File tree

src/app/item-page/edit-item-page/item-relationships/edit-item-relationships.service.spec.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,23 +318,42 @@ describe('EditItemRelationshipsService', () => {
318318
const relationshipType = Object.assign(new RelationshipType(), {
319319
leftType: createSuccessfulRemoteDataObject$({id: 'sameType'}),
320320
rightType: createSuccessfulRemoteDataObject$({id:'sameType'}),
321+
leftwardType: 'isDepartmentOfDivision',
322+
rightwardType: 'isDivisionOfDepartment',
321323
});
322324
const itemType = Object.assign(new ItemType(), {id: 'sameType'} );
323325

324-
const result = service.relationshipMatchesBothSameTypes(relationshipType, itemType);
326+
const result = service.shouldDisplayBothRelationshipSides(relationshipType, itemType);
325327
result.subscribe((resultValue) => {
326328
expect(resultValue).toBeTrue();
327329
done();
328330
});
329331
});
332+
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) => {
333+
const relationshipType = Object.assign(new RelationshipType(), {
334+
leftType: createSuccessfulRemoteDataObject$({ id: 'sameType' }),
335+
rightType: createSuccessfulRemoteDataObject$({ id: 'sameType' }),
336+
leftwardType: 'isOrgUnitOfOrgUnit',
337+
rightwardType: 'isOrgUnitOfOrgUnit',
338+
});
339+
const itemType = Object.assign(new ItemType(), { id: 'sameType' });
340+
341+
const result = service.shouldDisplayBothRelationshipSides(relationshipType, itemType);
342+
result.subscribe((resultValue) => {
343+
expect(resultValue).toBeFalse();
344+
done();
345+
});
346+
});
330347
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) => {
331348
const relationshipType = Object.assign(new RelationshipType(), {
332349
leftType: createSuccessfulRemoteDataObject$({id: 'sameType'}),
333350
rightType: createSuccessfulRemoteDataObject$({id: 'sameType'}),
351+
leftwardType: 'isDepartmentOfDivision',
352+
rightwardType: 'isDivisionOfDepartment',
334353
});
335354
const itemType = Object.assign(new ItemType(), {id: 'something-else'} );
336355

337-
const result = service.relationshipMatchesBothSameTypes(relationshipType, itemType);
356+
const result = service.shouldDisplayBothRelationshipSides(relationshipType, itemType);
338357
result.subscribe((resultValue) => {
339358
expect(resultValue).toBeFalse();
340359
done();
@@ -344,10 +363,12 @@ describe('EditItemRelationshipsService', () => {
344363
const relationshipType = Object.assign(new RelationshipType(), {
345364
leftType: createSuccessfulRemoteDataObject$({id: 'leftType'}),
346365
rightType: createSuccessfulRemoteDataObject$({id: 'rightType'}),
366+
leftwardType: 'isAuthorOfPublication',
367+
rightwardType: 'isPublicationOfAuthor',
347368
});
348369
const itemType = Object.assign(new ItemType(), {id: 'leftType'} );
349370

350-
const result = service.relationshipMatchesBothSameTypes(relationshipType, itemType);
371+
const result = service.shouldDisplayBothRelationshipSides(relationshipType, itemType);
351372
result.subscribe((resultValue) => {
352373
expect(resultValue).toBeFalse();
353374
done();

src/app/item-page/edit-item-page/item-relationships/edit-item-relationships.service.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,17 @@ export class EditItemRelationshipsService {
200200
);
201201
}
202202

203-
relationshipMatchesBothSameTypes(relationshipType: RelationshipType, itemType: ItemType): Observable<boolean> {
203+
/**
204+
* Whether both side of the relationship need to be displayed on the edit relationship page or not.
205+
*
206+
* @param relationshipType The relationship type
207+
* @param itemType The item type
208+
*/
209+
shouldDisplayBothRelationshipSides(relationshipType: RelationshipType, itemType: ItemType): Observable<boolean> {
204210
return this.getRelationshipLeftAndRightType(relationshipType).pipe(
205211
map(([leftType, rightType]: [ItemType, ItemType]) => {
206-
return leftType.id === itemType.id && rightType.id === itemType.id;
207-
})
212+
return leftType.id === itemType.id && rightType.id === itemType.id && relationshipType.leftwardType !== relationshipType.rightwardType;
213+
}),
208214
);
209215
}
210216

src/app/item-page/edit-item-page/item-relationships/edit-relationship-list-wrapper/edit-relationship-list-wrapper.component.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
<ng-container *ngIf="bothItemsMatchType$ | async">
1+
<ng-container *ngIf="shouldDisplayBothRelationshipSides$ | async">
22
<ds-edit-relationship-list
33
[url]="url"
44
[item]="item"
55
[itemType]="itemType"
66
[relationshipType]="relationshipType"
77
[hasChanges]="hasChanges"
88
[currentItemIsLeftItem$]="isLeftItem$"
9+
class="d-block mb-4"
910
></ds-edit-relationship-list>
1011
<ds-edit-relationship-list
1112
[url]="url"
@@ -17,7 +18,7 @@
1718
></ds-edit-relationship-list>
1819
</ng-container>
1920

20-
<ng-container *ngIf="!(bothItemsMatchType$ | async)">
21+
<ng-container *ngIf="(shouldDisplayBothRelationshipSides$ | async) === false">
2122
<ds-edit-relationship-list
2223
[url]="url"
2324
[item]="item"

src/app/item-page/edit-item-page/item-relationships/edit-relationship-list-wrapper/edit-relationship-list-wrapper.component.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { RelationshipType } from '../../../../core/shared/item-relationships/rel
88
import { createSuccessfulRemoteDataObject$ } from '../../../../shared/remote-data.utils';
99
import { ItemType } from '../../../../core/shared/item-relationships/item-type.model';
1010
import { Item } from '../../../../core/shared/item.model';
11+
import { cold } from 'jasmine-marbles';
1112

1213
describe('EditRelationshipListWrapperComponent', () => {
1314
let editItemRelationshipsService: EditItemRelationshipsService;
@@ -36,7 +37,7 @@ describe('EditRelationshipListWrapperComponent', () => {
3637

3738
editItemRelationshipsService = jasmine.createSpyObj('editItemRelationshipsService', {
3839
isProvidedItemTypeLeftType: observableOf(true),
39-
relationshipMatchesBothSameTypes: observableOf(false)
40+
shouldDisplayBothRelationshipSides: observableOf(false),
4041
});
4142

4243

@@ -69,10 +70,10 @@ describe('EditRelationshipListWrapperComponent', () => {
6970
});
7071
it('should set currentItemIsLeftItem$ and bothItemsMatchType$ based on the provided relationshipType, itemType and item', () => {
7172
expect(editItemRelationshipsService.isProvidedItemTypeLeftType).toHaveBeenCalledWith(relationshipType, leftType, item);
72-
expect(editItemRelationshipsService.relationshipMatchesBothSameTypes).toHaveBeenCalledWith(relationshipType, leftType);
73+
expect(editItemRelationshipsService.shouldDisplayBothRelationshipSides).toHaveBeenCalledWith(relationshipType, leftType);
7374

7475
expect(comp.currentItemIsLeftItem$.getValue()).toEqual(true);
75-
expect(comp.bothItemsMatchType$.getValue()).toEqual(false);
76+
expect(comp.shouldDisplayBothRelationshipSides$).toBeObservable(cold('(a|)', { a: false }));
7677
});
7778
});
7879

@@ -96,7 +97,7 @@ describe('EditRelationshipListWrapperComponent', () => {
9697

9798
describe('when the current item is both left and right', () => {
9899
it('should render two relationship list sections', () => {
99-
(editItemRelationshipsService.relationshipMatchesBothSameTypes as jasmine.Spy).and.returnValue(observableOf(true));
100+
(editItemRelationshipsService.shouldDisplayBothRelationshipSides as jasmine.Spy).and.returnValue(observableOf(true));
100101
comp.ngOnInit();
101102
fixture.detectChanges();
102103

src/app/item-page/edit-item-page/item-relationships/edit-relationship-list-wrapper/edit-relationship-list-wrapper.component.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class EditRelationshipListWrapperComponent implements OnInit, OnDestroy {
5656

5757
isRightItem$ = new BehaviorSubject(false);
5858

59-
bothItemsMatchType$: BehaviorSubject<boolean> = new BehaviorSubject(undefined);
59+
shouldDisplayBothRelationshipSides$: Observable<boolean>;
6060

6161
/**
6262
* Array to track all subscriptions and unsubscribe them onDestroy
@@ -76,10 +76,7 @@ export class EditRelationshipListWrapperComponent implements OnInit, OnDestroy {
7676
this.currentItemIsLeftItem$.next(nextValue);
7777
}));
7878

79-
this.subs.push(this.editItemRelationshipsService.relationshipMatchesBothSameTypes(this.relationshipType, this.itemType)
80-
.subscribe((nextValue: boolean) => {
81-
this.bothItemsMatchType$.next(nextValue);
82-
}));
79+
this.shouldDisplayBothRelationshipSides$ = this.editItemRelationshipsService.shouldDisplayBothRelationshipSides(this.relationshipType, this.itemType);
8380
}
8481

8582

src/app/item-page/edit-item-page/item-relationships/edit-relationship/edit-relationship.component.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,11 @@ export class EditRelationshipComponent implements OnChanges {
9090
getRemoteDataPayload(),
9191
filter((item: Item) => hasValue(item) && isNotEmpty(item.uuid))
9292
);
93-
this.relatedItem$ = observableCombineLatest(
93+
this.relatedItem$ = observableCombineLatest([
9494
this.leftItem$,
9595
this.rightItem$,
96-
).pipe(
97-
map((items: Item[]) =>
98-
items.find((item) => item.uuid !== this.editItem.uuid)
99-
)
96+
]).pipe(
97+
map(([leftItem, rightItem]: [Item, Item]) => leftItem.uuid === this.editItem.uuid ? rightItem : leftItem),
10098
);
10199
} else {
102100
this.relatedItem$ = of(this.update.relatedItem);

0 commit comments

Comments
 (0)