Skip to content

Commit ede5f43

Browse files
111731: Force the isActive state to be recalculated when the scope is updated
The BehaviorSubject was necessary because when the result of SearchService#getSelectedValuesForFilter is already cached, the isActive state can be recalculated even before the @input() scope is updated
1 parent 2dbf69e commit ede5f43

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

src/app/shared/search/search-filters/search-filter/search-filter.component.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
Component,
99
Inject,
1010
Input,
11+
OnChanges,
1112
OnDestroy,
1213
OnInit,
1314
} from '@angular/core';
@@ -56,7 +57,7 @@ import { SearchFacetFilterWrapperComponent } from './search-facet-filter-wrapper
5657
/**
5758
* Represents a part of the filter section for a single type of filter
5859
*/
59-
export class SearchFilterComponent implements OnInit, OnDestroy {
60+
export class SearchFilterComponent implements OnInit, OnChanges, OnDestroy {
6061
/**
6162
* The filter config for this component
6263
*/
@@ -65,7 +66,7 @@ export class SearchFilterComponent implements OnInit, OnDestroy {
6566
/**
6667
* True when the search component should show results on the current page
6768
*/
68-
@Input() inPlaceSearch;
69+
@Input() inPlaceSearch: boolean;
6970

7071
/**
7172
* Emits when the search filters values may be stale, and so they must be refreshed.
@@ -107,6 +108,11 @@ export class SearchFilterComponent implements OnInit, OnDestroy {
107108
*/
108109
active$: Observable<boolean>;
109110

111+
/**
112+
* The current scope as an observable in order to be able to re-trigger the {@link appliedFilters$}
113+
*/
114+
scope$: BehaviorSubject<string> = new BehaviorSubject(undefined);
115+
110116
subs: Subscription[] = [];
111117

112118
private readonly sequenceId: number;
@@ -137,6 +143,12 @@ export class SearchFilterComponent implements OnInit, OnDestroy {
137143
}));
138144
}
139145

146+
ngOnChanges(): void {
147+
if (this.scope$.value !== this.scope) {
148+
this.scope$.next(this.scope);
149+
}
150+
}
151+
140152
ngOnDestroy(): void {
141153
this.subs.forEach((sub: Subscription) => sub.unsubscribe());
142154
}
@@ -214,13 +226,14 @@ export class SearchFilterComponent implements OnInit, OnDestroy {
214226
return combineLatest([
215227
this.appliedFilters$,
216228
this.searchConfigService.searchOptions,
229+
this.scope$,
217230
]).pipe(
218-
switchMap(([selectedValues, options]: [AppliedFilter[], SearchOptions]) => {
231+
switchMap(([selectedValues, options, scope]: [AppliedFilter[], SearchOptions, string]) => {
219232
if (isNotEmpty(selectedValues.filter((appliedFilter: AppliedFilter) => FACET_OPERATORS.includes(appliedFilter.operator)))) {
220233
return observableOf(true);
221234
} else {
222-
if (hasValue(this.scope)) {
223-
options.scope = this.scope;
235+
if (hasValue(scope)) {
236+
options.scope = scope;
224237
}
225238
return this.searchService.getFacetValuesFor(this.filter, 1, options).pipe(
226239
filter((RD: RemoteData<FacetValues>) => !RD.isLoading),

0 commit comments

Comments
 (0)