mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
110889: Prevent vocabulary undefined from being retrieved in hierarchy filter when none is configured
(cherry picked from commit 9e7a59ddd0
)
This commit is contained in:
@@ -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<VocabularyEntryDetail>(),
|
||||
};
|
||||
@@ -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', () => {
|
||||
|
@@ -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,10 +70,12 @@ export class SearchHierarchyFilterComponent extends SearchFacetFilterComponent i
|
||||
super.onSubmit(addOperatorToFilterValue(data, 'query'));
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
ngOnInit(): void {
|
||||
super.ngOnInit();
|
||||
const vocabularyName: string = this.getVocabularyEntry();
|
||||
if (hasValue(vocabularyName)) {
|
||||
this.vocabularyExists$ = this.vocabularyService.searchTopEntries(
|
||||
this.getVocabularyEntry(), new PageInfo(), true, false,
|
||||
vocabularyName, new PageInfo(), true, false,
|
||||
).pipe(
|
||||
filter(rd => rd.hasCompleted),
|
||||
take(1),
|
||||
@@ -79,6 +84,7 @@ export class SearchHierarchyFilterComponent extends SearchFacetFilterComponent i
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the vocabulary tree modal popup.
|
||||
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user