@@ -18,18 +18,27 @@ import {
18
18
} from '@angular/router' ;
19
19
import {
20
20
BehaviorSubject ,
21
- combineLatest as observableCombineLatest ,
21
+ combineLatest ,
22
+ from ,
22
23
Observable ,
23
24
of as observableOf ,
24
25
Subscription ,
25
26
} from 'rxjs' ;
26
27
import {
28
+ debounceTime ,
27
29
distinctUntilChanged ,
30
+ filter ,
28
31
map ,
32
+ mergeMap ,
33
+ reduce ,
29
34
switchMap ,
30
35
take ,
31
36
tap ,
32
37
} from 'rxjs/operators' ;
38
+ import {
39
+ getFacetValueForType ,
40
+ stripOperatorFromFilterValue ,
41
+ } from 'src/app/shared/search/search.utils' ;
33
42
34
43
import { RemoteDataBuildService } from '../../../../../core/cache/builders/remote-data-build.service' ;
35
44
import { getFirstSucceededRemoteDataPayload } from '../../../../../core/shared/operators' ;
@@ -40,6 +49,7 @@ import { SEARCH_CONFIG_SERVICE } from '../../../../../my-dspace-page/my-dspace-c
40
49
import {
41
50
hasNoValue ,
42
51
hasValue ,
52
+ isNotEmpty ,
43
53
} from '../../../../empty.util' ;
44
54
import { InputSuggestion } from '../../../../input-suggestions/input-suggestions.model' ;
45
55
import { currentPath } from '../../../../utils/route.utils' ;
@@ -166,9 +176,33 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
166
176
) ;
167
177
this . subs . push (
168
178
this . searchOptions$ . subscribe ( ( ) => this . updateFilterValueList ( ) ) ,
179
+ this . refreshFilters . asObservable ( ) . pipe (
180
+ filter ( ( toRefresh : boolean ) => toRefresh ) ,
181
+ // NOTE This is a workaround, otherwise retrieving filter values returns tha old cached response
182
+ debounceTime ( ( 100 ) ) ,
183
+ mergeMap ( ( ) => this . retrieveFilterValues ( false ) ) ,
184
+ ) . subscribe ( ) ,
169
185
this . retrieveFilterValues ( ) . subscribe ( ) ,
170
186
) ;
171
- this . selectedAppliedFilters$ = this . searchService . getSelectedValuesForFilter ( this . filterConfig . name ) . pipe (
187
+
188
+ this . selectedAppliedFilters$ = combineLatest ( [
189
+ this . searchService . getSelectedValuesForFilter ( this . filterConfig . name ) ,
190
+ this . facetValues$ . asObservable ( ) . pipe (
191
+ mergeMap ( ( values : FacetValues [ ] ) => from ( values ) . pipe (
192
+ reduce ( ( acc : FacetValue [ ] , value : FacetValues ) => acc . concat ( value . page ) , [ ] ) ,
193
+ ) ) ,
194
+ ) ,
195
+ ] ) . pipe (
196
+ filter ( ( [ allAppliedFilters , facetValues ] : [ AppliedFilter [ ] , FacetValue [ ] ] ) => isNotEmpty ( facetValues ) ) ,
197
+ map ( ( [ allAppliedFilters , facetValues ] : [ AppliedFilter [ ] , FacetValue [ ] ] ) => {
198
+ return allAppliedFilters . map ( ( appliedValue ) => {
199
+ const fValue = facetValues
200
+ . find ( ( facetValue : FacetValue ) => stripOperatorFromFilterValue ( getFacetValueForType ( facetValue , this . filterConfig ) ) === appliedValue . value ) ;
201
+ return ( hasValue ( fValue ) ) ? Object . assign ( appliedValue , {
202
+ label : fValue . label ,
203
+ } ) : appliedValue ;
204
+ } ) ;
205
+ } ) ,
172
206
map ( ( allAppliedFilters : AppliedFilter [ ] ) => allAppliedFilters . filter ( ( appliedFilter : AppliedFilter ) => FACET_OPERATORS . includes ( appliedFilter . operator ) ) ) ,
173
207
distinctUntilChanged ( ( previous : AppliedFilter [ ] , next : AppliedFilter [ ] ) => JSON . stringify ( previous ) === JSON . stringify ( next ) ) ,
174
208
) ;
@@ -287,9 +321,9 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
287
321
* Retrieves all the filter value suggestion pages that need to be displayed in the facet and combines it into one
288
322
* list.
289
323
*/
290
- protected retrieveFilterValues ( ) : Observable < FacetValues [ ] > {
291
- return observableCombineLatest ( [ this . searchOptions$ , this . currentPage ] ) . pipe (
292
- switchMap ( ( [ options , page ] : [ SearchOptions , number ] ) => this . searchService . getFacetValuesFor ( this . filterConfig , page , options ) . pipe (
324
+ protected retrieveFilterValues ( useCachedVersionIfAvailable = true ) : Observable < FacetValues [ ] > {
325
+ return combineLatest ( [ this . searchOptions$ , this . currentPage ] ) . pipe (
326
+ switchMap ( ( [ options , page ] : [ SearchOptions , number ] ) => this . searchService . getFacetValuesFor ( this . filterConfig , page , options , null , useCachedVersionIfAvailable ) . pipe (
293
327
getFirstSucceededRemoteDataPayload ( ) ,
294
328
tap ( ( facetValues : FacetValues ) => {
295
329
this . isLastPage$ . next ( hasNoValue ( facetValues ?. next ) ) ;
0 commit comments