@@ -25,10 +25,10 @@ import {
2525 BehaviorSubject ,
2626 combineLatest ,
2727 Observable ,
28+ of ,
2829 Subscription ,
2930} from 'rxjs' ;
3031import {
31- debounceTime ,
3232 distinctUntilChanged ,
3333 filter ,
3434 map ,
@@ -512,9 +512,27 @@ export class SearchComponent implements OnDestroy, OnInit {
512512 this . searchLink = this . getSearchLink ( ) ;
513513 this . currentContext$ . next ( this . context ) ;
514514
515+ // Raw query param observable for configuration
516+ const configurationParam$ : Observable < string > =
517+ this . routeService . getQueryParameterValue ( 'configuration' ) . pipe ( distinctUntilChanged ( ) ) ;
518+
519+
515520 // Determinate PaginatedSearchOptions and listen to any update on it
516- const configuration $ : Observable < string > = this . searchConfigService
521+ const configurationFromService $ : Observable < string > = this . searchConfigService
517522 . getCurrentConfiguration ( this . configuration ) . pipe ( distinctUntilChanged ( ) ) ;
523+
524+ // Effective configuration: param value OR input @Input () configuration OR 'default'
525+ const configuration$ : Observable < string > = combineLatest ( [
526+ configurationParam$ ,
527+ configurationFromService$ ,
528+ of ( this . configuration ) ,
529+ ] ) . pipe (
530+ map ( ( [ paramValue , serviceValue , inputValue ] ) =>
531+ hasValue ( paramValue ) ? paramValue : ( hasValue ( inputValue ) ? inputValue : hasValue ( serviceValue ) ? serviceValue : 'default' ) ,
532+ ) ,
533+ distinctUntilChanged ( ) ,
534+ ) ;
535+
518536 const searchSortOptions$ : Observable < SortOptions [ ] > = combineLatest ( [ configuration$ , this . currentScope$ ] ) . pipe (
519537 switchMap ( ( [ configuration , scope ] : [ string , string ] ) => this . searchConfigService . getConfigurationSearchConfig ( configuration , scope ) ) ,
520538 map ( ( searchConfig : SearchConfig ) => this . searchConfigService . getConfigurationSortOptions ( searchConfig ) ) ,
@@ -528,25 +546,33 @@ export class SearchComponent implements OnDestroy, OnInit {
528546 distinctUntilChanged ( ) ,
529547 ) ;
530548 const searchOptions$ : Observable < PaginatedSearchOptions > = this . getSearchOptions ( ) . pipe ( distinctUntilChanged ( ) ) ;
549+ const queryFromQueryParam$ : Observable < string > = this . routeService . getQueryParameterValue ( 'query' ) . pipe ( distinctUntilChanged ( ) ) ;
531550
532- this . subs . push ( combineLatest ( [ configuration$ , searchSortOptions$ , searchOptions$ , sortOption$ , this . currentScope$ ] ) . pipe (
533- filter ( ( [ configuration , searchSortOptions , searchOptions , sortOption , scope ] : [ string , SortOptions [ ] , PaginatedSearchOptions , SortOptions , string ] ) => {
551+ this . subs . push ( combineLatest ( [ configuration$ , searchSortOptions$ , searchOptions$ , sortOption$ , this . currentScope$ , queryFromQueryParam$ ] ) . pipe (
552+ filter ( ( [ configuration , searchSortOptions , searchOptions , sortOption , scope , queryFromQueryParam ] : [ string , SortOptions [ ] , PaginatedSearchOptions , SortOptions , string , string ] ) => {
534553 // filter for search options related to instanced paginated id
535554 return searchOptions . pagination . id === this . paginationId ;
536555 } ) ,
537- debounceTime ( 100 ) ,
538- ) . subscribe ( ( [ configuration , searchSortOptions , searchOptions , sortOption , scope ] : [ string , SortOptions [ ] , PaginatedSearchOptions , SortOptions , string ] ) => {
539- // Build the PaginatedSearchOptions object
540- const searchOptionsConfiguration = searchOptions . configuration || configuration ;
541- const combinedOptions = Object . assign ( { } , searchOptions ,
542- {
543- configuration : searchOptionsConfiguration ,
544- sort : sortOption || searchOptions . sort ,
545- forcedEmbeddedKeys : this . forcedEmbeddedKeys . get ( searchOptionsConfiguration ) || this . forcedEmbeddedKeys . get ( 'default' ) ,
546- } ) ;
556+ // debounceTime(100),
557+ ) . subscribe ( ( [ configuration , searchSortOptions , searchOptions , sortOption , scope , queryFromQueryParam ] :
558+ [ string , SortOptions [ ] , PaginatedSearchOptions , SortOptions , string , string ] ) => {
559+ // Always apply the freshly resolved configuration (do NOT keep stale one)
560+ const combinedOptions = Object . assign ( { } , searchOptions , {
561+ configuration,
562+ sort : sortOption || searchOptions . sort ,
563+ forcedEmbeddedKeys : this . forcedEmbeddedKeys . get ( configuration ) || this . forcedEmbeddedKeys . get ( 'default' ) ,
564+ } ) ;
547565 if ( combinedOptions . query === '' ) {
548566 combinedOptions . query = this . query ;
549567 }
568+ if ( this . searchOptions$ . value ) {
569+ const currentOptions = this . searchOptions$ . value ;
570+ const query = currentOptions . query ;
571+ if ( isNotEmpty ( query ) && ( isEmpty ( combinedOptions . query ) || isEmpty ( queryFromQueryParam ) ) ) {
572+ combinedOptions . query = '' ;
573+ this . query = '' ;
574+ }
575+ }
550576 if ( isEmpty ( combinedOptions . scope ) ) {
551577 combinedOptions . scope = scope ;
552578 }
0 commit comments