Skip to content

Commit

Permalink
Merge branch 'w2p-122839_vocabulary-preloadlevel-fix' into vocabulary…
Browse files Browse the repository at this point in the history
…-preloadlevel-fix-7_x

# Conflicts:
#	src/app/shared/form/vocabulary-treeview/vocabulary-treeview.component.ts
  • Loading branch information
AAwouters committed Jan 2, 2025
2 parents 33fdee5 + 4ffde92 commit 18819b7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
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 { VocabularyTreeFlattener } from './vocabulary-tree-flattener';
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 @@ export class VocabularyTreeviewComponent implements OnDestroy, OnInit, OnChanges
);
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;
}

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

this.treeControl.expand(newNode);
}
return newNode;
Expand Down Expand Up @@ -212,14 +223,29 @@ 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(() => 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

0 comments on commit 18819b7

Please sign in to comment.