11import { Injectable } from '@angular/core' ;
2- import { Params } from '@angular/router' ;
32import {
43 createSelector ,
54 MemoizedSelector ,
@@ -75,7 +74,14 @@ export class SearchFilterService {
7574 * @param {string } filterValue The value for which to search
7675 * @returns {Observable<boolean> } Emit true when the filter is active with the given value
7776 */
78- isFilterActiveWithValue ( paramName : string , filterValue : string ) : Observable < boolean > {
77+ isFilterActiveWithValue ( paramName : string , filterValue : string , searchInstanceId ?: string ) : Observable < boolean > {
78+ if ( hasValue ( searchInstanceId ) ) {
79+ return observableCombineLatest (
80+ this . routeService . hasQueryParamWithValue ( this . getSearchInstanceParam ( searchInstanceId , paramName ) , filterValue ) ,
81+ this . routeService . getQueryParamsWithPrefix ( this . getSearchInstanceParam ( searchInstanceId , 'f.' ) ) ,
82+ this . routeService . hasQueryParamWithValue ( paramName , filterValue ) ,
83+ ) . pipe ( map ( ( [ instanceActive , instanceFilters , legacyActive ] ) => instanceActive || ( ! isNotEmpty ( instanceFilters ) && legacyActive ) ) ) ;
84+ }
7985 return this . routeService . hasQueryParamWithValue ( paramName , filterValue ) ;
8086 }
8187
@@ -84,24 +90,31 @@ export class SearchFilterService {
8490 * @param {string } paramName The parameter name of the filter's configuration for which to search
8591 * @returns {Observable<boolean> } Emit true when the filter is active with any value
8692 */
87- isFilterActive ( paramName : string ) : Observable < boolean > {
93+ isFilterActive ( paramName : string , searchInstanceId ?: string ) : Observable < boolean > {
94+ if ( hasValue ( searchInstanceId ) ) {
95+ return observableCombineLatest (
96+ this . routeService . hasQueryParam ( this . getSearchInstanceParam ( searchInstanceId , paramName ) ) ,
97+ this . routeService . getQueryParamsWithPrefix ( this . getSearchInstanceParam ( searchInstanceId , 'f.' ) ) ,
98+ this . routeService . hasQueryParam ( paramName ) ,
99+ ) . pipe ( map ( ( [ instanceActive , instanceFilters , legacyActive ] ) => instanceActive || ( ! isNotEmpty ( instanceFilters ) && legacyActive ) ) ) ;
100+ }
88101 return this . routeService . hasQueryParam ( paramName ) ;
89102 }
90103
91104 /**
92105 * Fetch the current active scope from the query parameters
93106 * @returns {Observable<string> }
94107 */
95- getCurrentScope ( ) : Observable < string > {
96- return this . routeService . getQueryParameterValue ( 'scope' ) ;
108+ getCurrentScope ( searchInstanceId ?: string ) {
109+ return this . getCurrentSearchInstanceQueryParam ( searchInstanceId , 'scope' ) ;
97110 }
98111
99112 /**
100113 * Fetch the current query from the query parameters
101114 * @returns {Observable<string> }
102115 */
103- getCurrentQuery ( ) : Observable < string > {
104- return this . routeService . getQueryParameterValue ( 'query' ) ;
116+ getCurrentQuery ( searchInstanceId ?: string ) {
117+ return this . getCurrentSearchInstanceQueryParam ( searchInstanceId , 'query' ) ;
105118 }
106119
107120 /**
@@ -142,16 +155,22 @@ export class SearchFilterService {
142155 * Fetch the current active filters from the query parameters
143156 * @returns {Observable<Params> }
144157 */
145- getCurrentFilters ( ) : Observable < Params > {
158+ getCurrentFilters ( searchInstanceId ?: string ) {
159+ if ( hasValue ( searchInstanceId ) ) {
160+ return observableCombineLatest (
161+ this . routeService . getQueryParamsWithPrefix ( this . getSearchInstanceParam ( searchInstanceId , 'f.' ) ) ,
162+ this . routeService . getQueryParamsWithPrefix ( 'f.' ) ,
163+ ) . pipe ( map ( ( [ instanceFilters , legacyFilters ] ) => isNotEmpty ( instanceFilters ) ? instanceFilters : legacyFilters ) ) ;
164+ }
146165 return this . routeService . getQueryParamsWithPrefix ( 'f.' ) ;
147166 }
148167
149168 /**
150169 * Fetch the current view from the query parameters
151170 * @returns {Observable<string> }
152171 */
153- getCurrentView ( ) : Observable < string > {
154- return this . routeService . getQueryParameterValue ( 'view' ) ;
172+ getCurrentView ( searchInstanceId ?: string ) {
173+ return this . getCurrentSearchInstanceQueryParam ( searchInstanceId , 'view' ) ;
155174 }
156175
157176 /**
@@ -190,6 +209,20 @@ export class SearchFilterService {
190209 return `${ new EmphasizePipe ( ) . transform ( facet . value , query ) } (${ facet . count } )` ;
191210 }
192211
212+ private getSearchInstanceParam ( searchInstanceId : string , parameterName : string ) : string {
213+ return `${ searchInstanceId } .${ parameterName } ` ;
214+ }
215+
216+ private getCurrentSearchInstanceQueryParam ( searchInstanceId : string | undefined , parameterName : string ) : Observable < string > {
217+ if ( hasValue ( searchInstanceId ) ) {
218+ return observableCombineLatest (
219+ this . routeService . getQueryParameterValue ( this . getSearchInstanceParam ( searchInstanceId , parameterName ) ) ,
220+ this . routeService . getQueryParameterValue ( parameterName ) ,
221+ ) . pipe ( map ( ( [ instanceValue , legacyValue ] ) => hasValue ( instanceValue ) ? instanceValue : legacyValue ) ) ;
222+ }
223+ return this . routeService . getQueryParameterValue ( parameterName ) ;
224+ }
225+
193226 /**
194227 * Checks if the state of a given filter is currently collapsed or not
195228 * @param {string } filterName The filtername for which the collapsed state is checked
0 commit comments