Merge pull request #3819 from atmire/vocabulary-preloadlevel-fix-main

Vocabulary preloadlevel fix
This commit is contained in:
Tim Donohue
2025-07-01 17:03:09 -05:00
committed by GitHub
2 changed files with 42 additions and 6 deletions

View File

@@ -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';
@@ -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(() => {

View File

@@ -22,8 +22,17 @@ import {
Observable,
Subscription,
} from 'rxjs';
import {
map,
switchMap,
tap,
} from 'rxjs/operators';
import { VocabularyService } from 'src/app/core/submission/vocabularies/vocabulary.service';
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';
@@ -166,6 +175,7 @@ export class VocabularyTreeviewComponent implements OnDestroy, OnInit, OnChanges
*/
constructor(
private vocabularyTreeviewService: VocabularyTreeviewService,
protected vocabularyService: VocabularyService,
) {
this.treeFlattener = new VocabularyTreeFlattener(this.transformer, this.getLevel,
this.isExpandable, this.getChildren);
@@ -207,12 +217,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;
@@ -253,15 +271,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 => 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);
}
/**