Commits

Tim Donohue authored and GitHub committed ba70a96552a Merge
Merge pull request #2361 from nona-luypaert/issue-2337_fix-vocabulary-treeview-not-updating

Fix tree not updating when switching between "Browse by Vocabulary" pages
No tags
gidlmaster

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

Modified
1 1 import { FlatTreeControl } from '@angular/cdk/tree';
2 -import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core';
2 +import { Component, EventEmitter, Input, OnDestroy, OnInit, Output, OnChanges, SimpleChanges } from '@angular/core';
3 3
4 4 import { map } from 'rxjs/operators';
5 5 import { Observable, Subscription } from 'rxjs';
6 6 import { Store } from '@ngrx/store';
7 7 import { TranslateService } from '@ngx-translate/core';
8 8
9 9 import { VocabularyEntryDetail } from '../../../core/submission/vocabularies/models/vocabulary-entry-detail.model';
10 10 import { hasValue, isEmpty, isNotEmpty } from '../../empty.util';
11 11 import { VocabularyTreeviewService } from './vocabulary-treeview.service';
12 12 import { LOAD_MORE, LOAD_MORE_ROOT, TreeviewFlatNode, TreeviewNode } from './vocabulary-treeview-node.model';
21 21 import { getFirstSucceededRemoteDataPayload } from '../../../core/shared/operators';
22 22
23 23 /**
24 24 * Component that shows a hierarchical vocabulary in a tree view
25 25 */
26 26 @Component({
27 27 selector: 'ds-vocabulary-treeview',
28 28 templateUrl: './vocabulary-treeview.component.html',
29 29 styleUrls: ['./vocabulary-treeview.component.scss']
30 30 })
31 -export class VocabularyTreeviewComponent implements OnDestroy, OnInit {
31 +export class VocabularyTreeviewComponent implements OnDestroy, OnInit, OnChanges {
32 32
33 33 /**
34 34 * The {@link VocabularyOptions} object
35 35 */
36 36 @Input() vocabularyOptions: VocabularyOptions;
37 37
38 38 /**
39 39 * Representing how many tree level load at initialization
40 40 */
41 41 @Input() preloadLevel = 2;
315 315 .filter((sub) => hasValue(sub))
316 316 .forEach((sub) => sub.unsubscribe());
317 317 }
318 318
319 319 /**
320 320 * Return an id for a given {@link VocabularyEntry}
321 321 */
322 322 private getEntryId(entry: VocabularyEntry): string {
323 323 return entry.authority || entry.otherInformation.id || undefined;
324 324 }
325 +
326 + ngOnChanges(changes: SimpleChanges): void {
327 + this.reset();
328 + this.vocabularyTreeviewService.initialize(this.vocabularyOptions, new PageInfo(), this.selectedItems, null);
329 + }
325 330 }

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut