From 33d3ff0c440f933d74a792ea42a21db3012898fd Mon Sep 17 00:00:00 2001 From: Alexandre Vryghem Date: Fri, 12 Apr 2024 15:51:45 +0200 Subject: [PATCH] 111731: Integrated the FilterInputSuggestionsComponent in the advanced search facets to show input suggestions (only works for filters that are also part of the facets) --- .../filter-input-suggestions.component.html | 2 +- .../advanced-search.component.html | 12 +++++++ .../advanced-search.component.scss | 5 +++ .../advanced-search.component.spec.ts | 10 ++++++ .../advanced-search.component.ts | 31 ++++++++++++++++++- .../search-sidebar.component.html | 3 +- src/assets/i18n/en.json5 | 2 ++ 7 files changed, 62 insertions(+), 3 deletions(-) diff --git a/src/app/shared/input-suggestions/filter-suggestions/filter-input-suggestions.component.html b/src/app/shared/input-suggestions/filter-suggestions/filter-input-suggestions.component.html index 726dc9ca0e..1d6bf64c0b 100644 --- a/src/app/shared/input-suggestions/filter-suggestions/filter-input-suggestions.component.html +++ b/src/app/shared/input-suggestions/filter-suggestions/filter-input-suggestions.component.html @@ -4,7 +4,7 @@ (keydown.arrowup)="shiftFocusUp($event)" (keydown.esc)="close()" (dsClickOutside)="close();">
-
diff --git a/src/app/shared/search/advanced-search/advanced-search.component.scss b/src/app/shared/search/advanced-search/advanced-search.component.scss index e69de29bb2..09c5a9fa9d 100644 --- a/src/app/shared/search/advanced-search/advanced-search.component.scss +++ b/src/app/shared/search/advanced-search/advanced-search.component.scss @@ -0,0 +1,5 @@ +:host ::ng-deep { + ds-filter-input-suggestions label span { + display: none; + } +} diff --git a/src/app/shared/search/advanced-search/advanced-search.component.spec.ts b/src/app/shared/search/advanced-search/advanced-search.component.spec.ts index a8f4811d28..cbda0cf3c0 100644 --- a/src/app/shared/search/advanced-search/advanced-search.component.spec.ts +++ b/src/app/shared/search/advanced-search/advanced-search.component.spec.ts @@ -1,17 +1,25 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { AdvancedSearchComponent } from './advanced-search.component'; +import { Router } from '@angular/router'; +import { RouterStub } from '../../testing/router.stub'; import { SearchConfigurationService } from '../../../core/shared/search/search-configuration.service'; +import { SearchFilterService } from '../../../core/shared/search/search-filter.service'; import { SearchConfigurationServiceStub } from '../../testing/search-configuration-service.stub'; +import { SearchFilterServiceStub } from '../../testing/search-filter-service.stub'; import { TranslateModule } from '@ngx-translate/core'; describe('AdvancedSearchComponent', () => { let component: AdvancedSearchComponent; let fixture: ComponentFixture; + let router: RouterStub; let searchConfigurationService: SearchConfigurationServiceStub; + let searchFilterService: SearchFilterServiceStub; beforeEach(async () => { + router = new RouterStub(); searchConfigurationService = new SearchConfigurationServiceStub(); + searchFilterService = new SearchFilterServiceStub(); await TestBed.configureTestingModule({ imports: [ @@ -21,7 +29,9 @@ describe('AdvancedSearchComponent', () => { AdvancedSearchComponent, ], providers: [ + { provide: Router, useValue: router }, { provide: SearchConfigurationService, useValue: searchConfigurationService }, + { provide: SearchFilterService, useValue: searchFilterService }, ], }).compileComponents(); diff --git a/src/app/shared/search/advanced-search/advanced-search.component.ts b/src/app/shared/search/advanced-search/advanced-search.component.ts index 6607cef6e4..220649fb03 100644 --- a/src/app/shared/search/advanced-search/advanced-search.component.ts +++ b/src/app/shared/search/advanced-search/advanced-search.component.ts @@ -1,7 +1,12 @@ import { Component, Input, OnInit } from '@angular/core'; -import { map, Observable } from 'rxjs'; +import { map, Observable, of as observableOf } from 'rxjs'; import { SearchConfigurationService } from '../../../core/shared/search/search-configuration.service'; import { FilterConfig, SearchConfig } from '../../../core/shared/search/search-filters/search-config.model'; +import { SearchFilterService } from '../../../core/shared/search/search-filter.service'; +import { SearchFilterConfig } from '../models/search-filter-config.model'; +import { Router } from '@angular/router'; +import { InputSuggestion } from '../../input-suggestions/input-suggestions.model'; +import { hasValue } from '../../empty.util'; @Component({ selector: 'ds-advanced-search', @@ -12,6 +17,8 @@ export class AdvancedSearchComponent implements OnInit { @Input() configuration: string; + @Input() filtersConfig: SearchFilterConfig[]; + advancedFilters$: Observable; advancedFilterMap$: Observable>; @@ -20,8 +27,20 @@ export class AdvancedSearchComponent implements OnInit { currentOperator: string; + /** + * The value of the input field that is used to query for possible values for this filter + */ + currentValue = ''; + + /** + * Emits the result values for this filter found by the current filter query + */ + filterSearchResults$: Observable = observableOf([]); + constructor( + protected router: Router, protected searchConfigurationService: SearchConfigurationService, + protected searchFilterService: SearchFilterService, ) { } @@ -44,4 +63,14 @@ export class AdvancedSearchComponent implements OnInit { ); } + findSuggestions(query: string): void { + if (hasValue(this.filtersConfig)) { + for (const filterConfig of this.filtersConfig) { + if (filterConfig.name === this.currentFilter) { + this.filterSearchResults$ = this.searchFilterService.findSuggestions(filterConfig, this.searchConfigurationService.searchOptions.value, query); + } + } + } + } + } diff --git a/src/app/shared/search/search-sidebar/search-sidebar.component.html b/src/app/shared/search/search-sidebar/search-sidebar.component.html index 4a9c810a6f..ad1c574597 100644 --- a/src/app/shared/search/search-sidebar/search-sidebar.component.html +++ b/src/app/shared/search/search-sidebar/search-sidebar.component.html @@ -24,7 +24,8 @@ [inPlaceSearch]="inPlaceSearch" (changeAppliedFilters)="changeAppliedFilters.emit($event)"> - + diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index 83feee8f83..2fcc7c9e2a 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -3898,6 +3898,8 @@ "search.sidebar.advanced-search.filter-by": "Filter by", + "search.sidebar.advanced-search.add": "Add", + "search.sidebar.settings.title": "Settings", "search.view-switch.show-detail": "Show detail",