Skip to content

Commit 0bb0125

Browse files
FrancescoMolinaroatarix83
authored andcommitted
Merged in task/dspace-cris-2023_02_x/DSC-2336 (pull request DSpace#3156)
[DSC-2336] fix issue with duplicated nodes Approved-by: Giuseppe Digilio
2 parents bac848b + 927db8e commit 0bb0125

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/app/shared/form/vocabulary-treeview/vocabulary-treeview.service.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,25 @@ describe('VocabularyTreeviewService test suite', () => {
269269
expect(serviceAsAny.dataChange.value).toEqual(treeNodeListWithChildren);
270270
});
271271

272+
it('should not add more children if already present and is loadAll is true and onlyFirstTime is true', () => {
273+
pageInfo = Object.assign(new PageInfo(), {
274+
elementsPerPage: 1,
275+
totalElements: 2,
276+
totalPages: 2,
277+
currentPage: 2
278+
});
279+
spyOn(serviceAsAny, 'getChildrenNodesByParent').and.returnValue(hot('a', {
280+
a: buildPaginatedList(pageInfo, [])
281+
}));
282+
283+
serviceAsAny.dataChange.next(treeNodeListWithLoadMore);
284+
serviceAsAny.nodeMap = nodeMapWithChildren;
285+
scheduler.schedule(() => service.loadMore(item, [], true, true));
286+
scheduler.flush();
287+
288+
expect(serviceAsAny.getChildrenNodesByParent).not.toHaveBeenCalled();
289+
});
290+
272291
it('should add loadMore node properly', () => {
273292
pageInfo = Object.assign(new PageInfo(), {
274293
elementsPerPage: 1,

src/app/shared/form/vocabulary-treeview/vocabulary-treeview.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ export class VocabularyTreeviewService {
146146
}
147147
const parent: TreeviewNode = this.nodeMap.get(item.otherInformation.id)!;
148148
const children = this.nodeMap.get(item.otherInformation.id)!.children || [];
149+
// If there are children and is invoked with loadAll true we skip the call as it means the node has loaded already all the children
150+
if (children.length && loadAll && onlyFirstTime) {
151+
return;
152+
}
149153
this.getChildrenNodesByParent(item.otherInformation.id, parent.pageInfo, (loadAll && selectedItems.length > 0)).subscribe((list: PaginatedList<VocabularyEntryDetail>) => {
150154
if (onlyFirstTime && parent.children!.length > 0 && !loadAll) {
151155
return;

0 commit comments

Comments
 (0)