Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Port dspace-7_x] Vocabulary preloadlevel fix #3821

Open
wants to merge 4 commits into
base: dspace-7_x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { authReducer } from '../../../core/auth/auth.reducer';
import { storeModuleConfig } from '../../../app.reducer';
import { By } from '@angular/platform-browser';
import { VocabularyService } from '../../../core/submission/vocabularies/vocabulary.service';
import { createSuccessfulRemoteDataObject$ } from '../../remote-data.utils';

describe('VocabularyTreeviewComponent test suite', () => {

Expand Down Expand Up @@ -56,7 +57,8 @@ describe('VocabularyTreeviewComponent test suite', () => {
findEntryDetailById: jasmine.createSpy('findEntryDetailById'),
searchTopEntries: jasmine.createSpy('searchTopEntries'),
getEntryDetailChildren: jasmine.createSpy('getEntryDetailChildren'),
clearSearchTopRequests: jasmine.createSpy('clearSearchTopRequests')
clearSearchTopRequests: jasmine.createSpy('clearSearchTopRequests'),
findVocabularyById: createSuccessfulRemoteDataObject$({ preloadLevel: 2 }),
});

initialState = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FlatTreeControl } from '@angular/cdk/tree';
import { Component, ElementRef, EventEmitter, Input, OnDestroy, OnInit, Output, OnChanges, SimpleChanges, ViewChild } from '@angular/core';

import { map, tap, switchMap } from 'rxjs/operators';
import { Observable, Subscription } from 'rxjs';
import { Store } from '@ngrx/store';
import { TranslateService } from '@ngx-translate/core';
Expand All @@ -16,8 +17,10 @@
import { VocabularyTreeFlatDataSource } from './vocabulary-tree-flat-data-source';
import { CoreState } from '../../../core/core-state.model';
import { VocabularyService } from '../../../core/submission/vocabularies/vocabulary.service';
import { getFirstSucceededRemoteDataPayload } from '../../../core/shared/operators';
import { getFirstSucceededRemoteDataPayload, getFirstCompletedRemoteData } from '../../../core/shared/operators';
import { AlertType } from '../../alert/alert-type';
import { Vocabulary } from '../../../core/submission/vocabularies/models/vocabulary.model';
import { RemoteData } from '../../../core/data/remote-data';

/**
* Component that shows a hierarchical vocabulary in a tree view
Expand Down Expand Up @@ -166,12 +169,20 @@
);
this.nodeMap.set(node.item.id, newNode);

if ((((level + 1) < this.preloadLevel) && newNode.childrenLoaded)
if ((((level + 1) < this.preloadLevel))
|| (newNode.isSearchNode && newNode.childrenLoaded)
|| newNode.isInInitValueHierarchy) {
if (!newNode.isSearchNode) {

if (newNode.item.id === LOAD_MORE || newNode.item.id === LOAD_MORE_ROOT) {
// When a 'LOAD_MORE' node is encountered, the parent already has a lot of expanded children
// so this is a good point to stop expanding.
return newNode;

Check warning on line 179 in src/app/shared/form/vocabulary-treeview/vocabulary-treeview.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/form/vocabulary-treeview/vocabulary-treeview.component.ts#L179

Added line #L179 was not covered by tests
}

if (!newNode.childrenLoaded) {
this.loadChildren(newNode);
}

this.treeControl.expand(newNode);
}
return newNode;
Expand Down Expand Up @@ -212,14 +223,29 @@
*/
ngOnInit(): void {
this.subs.push(
this.vocabularyTreeviewService.getData().subscribe((data) => {
this.vocabularyService.findVocabularyById(this.vocabularyOptions.name).pipe(
// Retrieve the configured preloadLevel from REST
getFirstCompletedRemoteData(),
map((vocabularyRD: RemoteData<Vocabulary>) => {
if (vocabularyRD.hasSucceeded &&
hasValue(vocabularyRD.payload.preloadLevel) &&
vocabularyRD.payload.preloadLevel > 1) {
return vocabularyRD.payload.preloadLevel;
} else {
// Set preload level to 1 in case request fails
return 1;

Check warning on line 236 in src/app/shared/form/vocabulary-treeview/vocabulary-treeview.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/form/vocabulary-treeview/vocabulary-treeview.component.ts#L236

Added line #L236 was not covered by tests
}
}),
tap(preloadLevel => this.preloadLevel = preloadLevel),
tap(() => this.vocabularyTreeviewService.initialize(this.vocabularyOptions, new PageInfo(), this.selectedItems, null)),
switchMap(() => this.vocabularyTreeviewService.getData()),
).subscribe((data) => {
this.dataSource.data = data;
})
);

this.loading = this.vocabularyTreeviewService.isLoading();

this.vocabularyTreeviewService.initialize(this.vocabularyOptions, new PageInfo(), this.selectedItems, null);
this.loading = this.vocabularyTreeviewService.isLoading();
}

/**
Expand Down
Loading