Skip to content

Commit aa93989

Browse files
authored
Merge pull request #3803 from DSpace/backport-3142-to-dspace-8_x
[Port dspace-8_x] Add support for non repeatable relationships
2 parents 2d58de8 + 48f7e51 commit aa93989

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ describe('EditRelationshipListComponent', () => {
110110
},
111111
};
112112

113-
function init(leftType: string, rightType: string): void {
113+
function init(leftType: string, rightType: string, leftMaxCardinality?: number, rightMaxCardinality?: number): void {
114114
entityTypeLeft = Object.assign(new ItemType(), {
115115
id: leftType,
116116
uuid: leftType,
@@ -130,6 +130,8 @@ describe('EditRelationshipListComponent', () => {
130130
rightType: createSuccessfulRemoteDataObject$(entityTypeRight),
131131
leftwardType: `is${rightType}Of${leftType}`,
132132
rightwardType: `is${leftType}Of${rightType}`,
133+
leftMaxCardinality: leftMaxCardinality,
134+
rightMaxCardinality: rightMaxCardinality,
133135
});
134136

135137
paginationOptions = Object.assign(new PaginationComponentOptions(), {
@@ -402,4 +404,31 @@ describe('EditRelationshipListComponent', () => {
402404
}));
403405
});
404406
});
407+
408+
describe('Is repeatable relationship', () => {
409+
beforeEach(waitForAsync(() => {
410+
currentItemIsLeftItem$ = new BehaviorSubject<boolean>(true);
411+
}));
412+
describe('when max cardinality is 1', () => {
413+
beforeEach(waitForAsync(() => init('Publication', 'OrgUnit', 1, undefined)));
414+
it('should return false', () => {
415+
const result = (comp as any).isRepeatable();
416+
expect(result).toBeFalse();
417+
});
418+
});
419+
describe('when max cardinality is 2', () => {
420+
beforeEach(waitForAsync(() => init('Publication', 'OrgUnit', 2, undefined)));
421+
it('should return true', () => {
422+
const result = (comp as any).isRepeatable();
423+
expect(result).toBeTrue();
424+
});
425+
});
426+
describe('when max cardinality is undefined', () => {
427+
beforeEach(waitForAsync(() => init('Publication', 'OrgUnit', undefined, undefined)));
428+
it('should return true', () => {
429+
const result = (comp as any).isRepeatable();
430+
expect(result).toBeTrue();
431+
});
432+
});
433+
});
405434
});

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,22 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
264264
return update && update.field ? update.field.uuid : undefined;
265265
}
266266

267+
/**
268+
* Check whether the current entity can have multiple relationships of this type
269+
* This is based on the max cardinality of the relationship
270+
* @private
271+
*/
272+
private isRepeatable(): boolean {
273+
const isLeft = this.currentItemIsLeftItem$.getValue();
274+
if (isLeft) {
275+
const leftMaxCardinality = this.relationshipType.leftMaxCardinality;
276+
return hasNoValue(leftMaxCardinality) || leftMaxCardinality > 1;
277+
} else {
278+
const rightMaxCardinality = this.relationshipType.rightMaxCardinality;
279+
return hasNoValue(rightMaxCardinality) || rightMaxCardinality > 1;
280+
}
281+
}
282+
267283
/**
268284
* Open the dynamic lookup modal to search for items to add as relationships
269285
*/
@@ -281,6 +297,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
281297
modalComp.toAdd = [];
282298
modalComp.toRemove = [];
283299
modalComp.isPending = false;
300+
modalComp.repeatable = this.isRepeatable();
284301
modalComp.hiddenQuery = '-search.resourceid:' + this.item.uuid;
285302

286303
this.item.owningCollection.pipe(

0 commit comments

Comments
 (0)