@@ -14,6 +14,10 @@ import {
1414 Output ,
1515 PLATFORM_ID ,
1616} from '@angular/core' ;
17+ import { NavigationStart , Router } from '@angular/router' ;
18+
19+ import { BehaviorSubject , combineLatest , Observable , Subscription , of } from 'rxjs' ;
20+ import { debounceTime , distinctUntilChanged , filter , map , switchMap , tap } from 'rxjs/operators' ;
1721import {
1822 NavigationStart ,
1923 Router ,
@@ -497,8 +501,12 @@ export class SearchComponent implements OnDestroy, OnInit {
497501
498502 this . searchConfigService . setPaginationId ( this . paginationId ) ;
499503
500- this . routeService . setParameter ( 'configuration' , this . configuration ) ;
501- this . routeService . setParameter ( 'fixedFilterQuery' , this . fixedFilterQuery ) ;
504+ if ( hasValue ( this . configuration ) ) {
505+ this . routeService . setParameter ( 'configuration' , this . configuration ) ;
506+ }
507+ if ( hasValue ( this . fixedFilterQuery ) ) {
508+ this . routeService . setParameter ( 'fixedFilterQuery' , this . fixedFilterQuery ) ;
509+ }
502510
503511 this . currentScope$ = this . routeService . getQueryParameterValue ( 'scope' ) . pipe (
504512 map ( ( routeValue : string ) => hasValue ( routeValue ) ? routeValue : this . scope ?? '' ) ,
@@ -508,9 +516,27 @@ export class SearchComponent implements OnDestroy, OnInit {
508516 this . searchLink = this . getSearchLink ( ) ;
509517 this . currentContext$ . next ( this . context ) ;
510518
519+ // Raw query param observable for configuration
520+ const configurationParam$ : Observable < string > =
521+ this . routeService . getQueryParameterValue ( 'configuration' ) . pipe ( distinctUntilChanged ( ) ) ;
522+
523+
511524 // Determinate PaginatedSearchOptions and listen to any update on it
512- const configuration $ : Observable < string > = this . searchConfigService
525+ const configurationFromService $ : Observable < string > = this . searchConfigService
513526 . getCurrentConfiguration ( this . configuration ) . pipe ( distinctUntilChanged ( ) ) ;
527+
528+ // Effective configuration: param value OR input @Input () configuration OR 'default'
529+ const configuration$ : Observable < string > = combineLatest ( [
530+ configurationParam$ ,
531+ configurationFromService$ ,
532+ of ( this . configuration )
533+ ] ) . pipe (
534+ map ( ( [ paramValue , serviceValue , inputValue ] ) =>
535+ hasValue ( paramValue ) ? paramValue : ( hasValue ( inputValue ) ? inputValue : hasValue ( serviceValue ) ? serviceValue : 'default' )
536+ ) ,
537+ distinctUntilChanged ( )
538+ ) ;
539+
514540 const searchSortOptions$ : Observable < SortOptions [ ] > = combineLatest ( [ configuration$ , this . currentScope$ ] ) . pipe (
515541 switchMap ( ( [ configuration , scope ] : [ string , string ] ) => this . searchConfigService . getConfigurationSearchConfig ( configuration , scope ) ) ,
516542 map ( ( searchConfig : SearchConfig ) => this . searchConfigService . getConfigurationSortOptions ( searchConfig ) ) ,
@@ -531,15 +557,14 @@ export class SearchComponent implements OnDestroy, OnInit {
531557 return searchOptions . pagination . id === this . paginationId ;
532558 } ) ,
533559 debounceTime ( 100 ) ,
534- ) . subscribe ( ( [ configuration , searchSortOptions , searchOptions , sortOption , scope ] : [ string , SortOptions [ ] , PaginatedSearchOptions , SortOptions , string ] ) => {
535- // Build the PaginatedSearchOptions object
536- const searchOptionsConfiguration = searchOptions . configuration || configuration ;
537- const combinedOptions = Object . assign ( { } , searchOptions ,
538- {
539- configuration : searchOptionsConfiguration ,
540- sort : sortOption || searchOptions . sort ,
541- forcedEmbeddedKeys : this . forcedEmbeddedKeys . get ( searchOptionsConfiguration ) || this . forcedEmbeddedKeys . get ( 'default' ) ,
542- } ) ;
560+ ) . subscribe ( ( [ configuration , searchSortOptions , searchOptions , sortOption , scope ] :
561+ [ string , SortOptions [ ] , PaginatedSearchOptions , SortOptions , string ] ) => {
562+ // Always apply the freshly resolved configuration (do NOT keep stale one)
563+ const combinedOptions = Object . assign ( { } , searchOptions , {
564+ configuration,
565+ sort : sortOption || searchOptions . sort ,
566+ forcedEmbeddedKeys : this . forcedEmbeddedKeys . get ( configuration ) || this . forcedEmbeddedKeys . get ( 'default' ) ,
567+ } ) ;
543568 if ( combinedOptions . query === '' ) {
544569 combinedOptions . query = this . query ;
545570 }
0 commit comments