diff --git a/src/app/shared/search/search-filters/search-filter/search-hierarchy-filter/search-hierarchy-filter.component.spec.ts b/src/app/shared/search/search-filters/search-filter/search-hierarchy-filter/search-hierarchy-filter.component.spec.ts index 4469a124ce6..a6212ca9c5e 100644 --- a/src/app/shared/search/search-filters/search-filter/search-hierarchy-filter/search-hierarchy-filter.component.spec.ts +++ b/src/app/shared/search/search-filters/search-filter/search-hierarchy-filter/search-hierarchy-filter.component.spec.ts @@ -27,6 +27,8 @@ import { SearchConfigurationServiceStub } from '../../../../testing/search-confi import { VocabularyEntryDetail } from '../../../../../core/submission/vocabularies/models/vocabulary-entry-detail.model'; import { FacetValue} from '../../../models/facet-value.model'; import { SearchFilterConfig } from '../../../models/search-filter-config.model'; +import { APP_CONFIG } from '../../../../../../config/app-config.interface'; +import { environment } from '../../../../../../environments/environment.test'; describe('SearchHierarchyFilterComponent', () => { @@ -34,7 +36,7 @@ describe('SearchHierarchyFilterComponent', () => { let showVocabularyTreeLink: DebugElement; const testSearchLink = 'test-search'; - const testSearchFilter = 'test-search-filter'; + const testSearchFilter = 'subject'; const VocabularyTreeViewComponent = { select: new EventEmitter(), }; @@ -73,6 +75,7 @@ describe('SearchHierarchyFilterComponent', () => { { provide: Router, useValue: router }, { provide: NgbModal, useValue: ngbModal }, { provide: VocabularyService, useValue: vocabularyService }, + { provide: APP_CONFIG, useValue: environment }, { provide: SEARCH_CONFIG_SERVICE, useValue: new SearchConfigurationServiceStub() }, { provide: IN_PLACE_SEARCH, useValue: false }, { provide: FILTER_CONFIG, useValue: Object.assign(new SearchFilterConfig(), { name: testSearchFilter }) }, @@ -86,7 +89,7 @@ describe('SearchHierarchyFilterComponent', () => { function init() { fixture = TestBed.createComponent(SearchHierarchyFilterComponent); fixture.detectChanges(); - showVocabularyTreeLink = fixture.debugElement.query(By.css('a#show-test-search-filter-tree')); + showVocabularyTreeLink = fixture.debugElement.query(By.css(`a#show-${testSearchFilter}-tree`)); } describe('if the vocabulary doesn\'t exist', () => { diff --git a/src/app/shared/search/search-filters/search-filter/search-hierarchy-filter/search-hierarchy-filter.component.ts b/src/app/shared/search/search-filters/search-filter/search-hierarchy-filter/search-hierarchy-filter.component.ts index d53fa37cf4b..18ddbbdf97e 100644 --- a/src/app/shared/search/search-filters/search-filter/search-hierarchy-filter/search-hierarchy-filter.component.ts +++ b/src/app/shared/search/search-filters/search-filter/search-hierarchy-filter/search-hierarchy-filter.component.ts @@ -24,9 +24,11 @@ import { filter, map, take } from 'rxjs/operators'; import { VocabularyService } from '../../../../../core/submission/vocabularies/vocabulary.service'; import { Observable, BehaviorSubject } from 'rxjs'; import { PageInfo } from '../../../../../core/shared/page-info.model'; -import { environment } from '../../../../../../environments/environment'; import { addOperatorToFilterValue } from '../../../search.utils'; import { VocabularyTreeviewModalComponent } from '../../../../form/vocabulary-treeview-modal/vocabulary-treeview-modal.component'; +import { hasValue } from '../../../../empty.util'; +import { APP_CONFIG, AppConfig } from '../../../../../../config/app-config.interface'; +import { FilterVocabularyConfig } from '../../../../../../config/filter-vocabulary-config'; @Component({ selector: 'ds-search-hierarchy-filter', @@ -47,6 +49,7 @@ export class SearchHierarchyFilterComponent extends SearchFacetFilterComponent i protected router: Router, protected modalService: NgbModal, protected vocabularyService: VocabularyService, + @Inject(APP_CONFIG) protected appConfig: AppConfig, @Inject(SEARCH_CONFIG_SERVICE) public searchConfigService: SearchConfigurationService, @Inject(IN_PLACE_SEARCH) public inPlaceSearch: boolean, @Inject(FILTER_CONFIG) public filterConfig: SearchFilterConfig, @@ -67,17 +70,20 @@ export class SearchHierarchyFilterComponent extends SearchFacetFilterComponent i super.onSubmit(addOperatorToFilterValue(data, 'query')); } - ngOnInit() { + ngOnInit(): void { super.ngOnInit(); - this.vocabularyExists$ = this.vocabularyService.searchTopEntries( - this.getVocabularyEntry(), new PageInfo(), true, false, - ).pipe( - filter(rd => rd.hasCompleted), - take(1), - map(rd => { - return rd.hasSucceeded; - }), - ); + const vocabularyName: string = this.getVocabularyEntry(); + if (hasValue(vocabularyName)) { + this.vocabularyExists$ = this.vocabularyService.searchTopEntries( + vocabularyName, new PageInfo(), true, false, + ).pipe( + filter(rd => rd.hasCompleted), + take(1), + map(rd => { + return rd.hasSucceeded; + }), + ); + } } /** @@ -93,11 +99,11 @@ export class SearchHierarchyFilterComponent extends SearchFacetFilterComponent i name: this.getVocabularyEntry(), closed: true }; - modalRef.result.then((detail: VocabularyEntryDetail) => { - this.selectedValues$ + void modalRef.result.then((detail: VocabularyEntryDetail) => { + this.subs.push(this.selectedValues$ .pipe(take(1)) .subscribe((selectedValues) => { - this.router.navigate( + void this.router.navigate( [this.searchService.getSearchLink()], { queryParams: { @@ -107,16 +113,16 @@ export class SearchHierarchyFilterComponent extends SearchFacetFilterComponent i queryParamsHandling: 'merge', }, ); - }); - }).catch(); + })); + }); } /** * Returns the matching vocabulary entry for the given search filter. * These are configurable in the config file. */ - getVocabularyEntry() { - const foundVocabularyConfig = environment.vocabularies.filter((v) => v.filter === this.filterConfig.name); + getVocabularyEntry(): string { + const foundVocabularyConfig: FilterVocabularyConfig[] = this.appConfig.vocabularies.filter((v: FilterVocabularyConfig) => v.filter === this.filterConfig.name); if (foundVocabularyConfig.length > 0 && foundVocabularyConfig[0].enabled === true) { return foundVocabularyConfig[0].vocabulary; }