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-8_x] Vocabulary preloadlevel fix #3820

Open
wants to merge 4 commits into
base: dspace-8_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 @@ -21,6 +21,7 @@ import { VocabularyEntry } from '../../../core/submission/vocabularies/models/vo
import { VocabularyEntryDetail } from '../../../core/submission/vocabularies/models/vocabulary-entry-detail.model';
import { VocabularyOptions } from '../../../core/submission/vocabularies/models/vocabulary-options.model';
import { VocabularyService } from '../../../core/submission/vocabularies/vocabulary.service';
import { createSuccessfulRemoteDataObject$ } from '../../remote-data.utils';
import { createTestComponent } from '../../testing/utils.test';
import { FormFieldMetadataValueObject } from '../builder/models/form-field-metadata-value.model';
import { VocabularyTreeviewComponent } from './vocabulary-treeview.component';
Expand Down Expand Up @@ -63,6 +64,7 @@ describe('VocabularyTreeviewComponent test suite', () => {
searchTopEntries: jasmine.createSpy('searchTopEntries'),
getEntryDetailChildren: jasmine.createSpy('getEntryDetailChildren'),
clearSearchTopRequests: jasmine.createSpy('clearSearchTopRequests'),
findVocabularyById: createSuccessfulRemoteDataObject$({ preloadLevel: 2 }),
});

beforeEach(waitForAsync(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,20 @@ import {
Observable,
Subscription,
} from 'rxjs';
import {
map,
switchMap,
tap,
} from 'rxjs/operators';

import { RemoteData } from '../../../core/data/remote-data';
import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
import { PageInfo } from '../../../core/shared/page-info.model';
import { Vocabulary } from '../../../core/submission/vocabularies/models/vocabulary.model';
import { VocabularyEntry } from '../../../core/submission/vocabularies/models/vocabulary-entry.model';
import { VocabularyEntryDetail } from '../../../core/submission/vocabularies/models/vocabulary-entry-detail.model';
import { VocabularyOptions } from '../../../core/submission/vocabularies/models/vocabulary-options.model';
import { VocabularyService } from '../../../core/submission/vocabularies/vocabulary.service';
import { AlertComponent } from '../../alert/alert.component';
import { AlertType } from '../../alert/alert-type';
import {
Expand Down Expand Up @@ -165,9 +174,11 @@ export class VocabularyTreeviewComponent implements OnDestroy, OnInit, OnChanges
* Initialize instance variables
*
* @param {VocabularyTreeviewService} vocabularyTreeviewService
* @param {VocabularyService} vocabularyService
*/
constructor(
private vocabularyTreeviewService: VocabularyTreeviewService,
protected vocabularyService: VocabularyService,
) {
this.treeFlattener = new VocabularyTreeFlattener(this.transformer, this.getLevel,
this.isExpandable, this.getChildren);
Expand Down Expand Up @@ -209,12 +220,20 @@ export class VocabularyTreeviewComponent implements OnDestroy, OnInit, OnChanges
);
this.nodeMap.set(entryId, 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;
}

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

this.treeControl.expand(newNode);
}
return newNode;
Expand Down Expand Up @@ -255,15 +274,31 @@ export class VocabularyTreeviewComponent implements OnDestroy, OnInit, OnChanges
*/
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;
}
}),
tap((preloadLevel: number) => this.preloadLevel = preloadLevel),
tap(() => {
const entryId: string = (this.selectedItems?.length > 0) ? this.getEntryId(this.selectedItems[0]) : null;
this.vocabularyTreeviewService.initialize(this.vocabularyOptions, new PageInfo(), this.getSelectedEntryIds(), entryId);
}),
switchMap(() => this.vocabularyTreeviewService.getData()),
).subscribe((data) => {
this.dataSource.data = data;
}),
);

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

const entryId: string = (this.selectedItems?.length > 0) ? this.getEntryId(this.selectedItems[0]) : null;
this.vocabularyTreeviewService.initialize(this.vocabularyOptions, new PageInfo(), this.getSelectedEntryIds(), entryId);
}

/**
Expand Down
Loading