Skip to content

Commit eb33ae7

Browse files
111731: Simplified retrieveFilterValues by removing the RemoteData around all the FacetValues since they were not used
1 parent f95c941 commit eb33ae7

6 files changed

Lines changed: 24 additions & 27 deletions

File tree

src/app/shared/search/search-filters/search-filter/search-authority-filter/search-authority-filter.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div>
22
<div class="filters py-2">
33
<ds-search-facet-selected-option *ngFor="let value of (selectedValues$ | async)" [selectedValue]="value" [filterConfig]="filterConfig" [selectedValues$]="selectedValues$" [inPlaceSearch]="inPlaceSearch"></ds-search-facet-selected-option>
4-
<ng-container *ngFor="let page of (filterValues$ | async)?.payload">
4+
<ng-container *ngFor="let page of (filterValues$ | async)">
55
<div [@facetLoad]="animationState">
66
<ds-search-facet-option *ngFor="let value of page.page; trackBy: trackUpdate" [filterConfig]="filterConfig" [filterValue]="value" [selectedValues$]="selectedValues$" [inPlaceSearch]="inPlaceSearch"></ds-search-facet-option>
77
</div>

src/app/shared/search/search-filters/search-filter/search-boolean-filter/search-boolean-filter.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div>
22
<div class="filters py-2">
33
<ds-search-facet-selected-option *ngFor="let value of (selectedValues$ | async)" [selectedValue]="value" [filterConfig]="filterConfig" [selectedValues$]="selectedValues$" [inPlaceSearch]="inPlaceSearch"></ds-search-facet-selected-option>
4-
<ng-container *ngFor="let page of (filterValues$ | async)?.payload">
4+
<ng-container *ngFor="let page of (filterValues$ | async)">
55
<div [@facetLoad]="animationState">
66
<ds-search-facet-option *ngFor="let value of page.page; trackBy: trackUpdate" [filterConfig]="filterConfig" [filterValue]="value" [selectedValues$]="selectedValues$" [inPlaceSearch]="inPlaceSearch"></ds-search-facet-option>
77
</div>

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

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { animate, state, style, transition, trigger } from '@angular/animations'
22
import { Component, Inject, OnDestroy, OnInit, EventEmitter } from '@angular/core';
33
import { Router } from '@angular/router';
44

5-
import { BehaviorSubject, combineLatest as observableCombineLatest, Observable, of as observableOf, Subject, Subscription } from 'rxjs';
5+
import { BehaviorSubject, combineLatest as observableCombineLatest, Observable, of as observableOf, Subscription } from 'rxjs';
66
import { debounceTime, distinctUntilChanged, filter, map, mergeMap, switchMap, take, tap } from 'rxjs/operators';
77

88
import { RemoteDataBuildService } from '../../../../../core/cache/builders/remote-data-build.service';
@@ -15,13 +15,12 @@ import { SearchFilterConfig } from '../../../models/search-filter-config.model';
1515
import { SearchService } from '../../../../../core/shared/search/search.service';
1616
import { FILTER_CONFIG, IN_PLACE_SEARCH, REFRESH_FILTER, SearchFilterService, CHANGE_APPLIED_FILTERS } from '../../../../../core/shared/search/search-filter.service';
1717
import { SearchConfigurationService } from '../../../../../core/shared/search/search-configuration.service';
18-
import { getFirstSucceededRemoteData } from '../../../../../core/shared/operators';
18+
import { getFirstSucceededRemoteData, getFirstSucceededRemoteDataPayload } from '../../../../../core/shared/operators';
1919
import { InputSuggestion } from '../../../../input-suggestions/input-suggestions.model';
2020
import { SearchOptions } from '../../../models/search-options.model';
2121
import { SEARCH_CONFIG_SERVICE } from '../../../../../my-dspace-page/my-dspace-page.component';
2222
import { currentPath } from '../../../../utils/route.utils';
2323
import { getFacetValueForType, stripOperatorFromFilterValue, addOperatorToFilterValue } from '../../../search.utils';
24-
import { createPendingRemoteDataObject } from '../../../../remote-data.utils';
2524
import { FacetValues } from '../../../models/facet-values.model';
2625
import { AppliedFilter } from '../../../models/applied-filter.model';
2726

@@ -37,7 +36,7 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
3736
/**
3837
* Emits an array of pages with values found for this facet
3938
*/
40-
filterValues$: Subject<RemoteData<FacetValues[]>>;
39+
filterValues$: BehaviorSubject<FacetValues[]> = new BehaviorSubject([]);
4140

4241
/**
4342
* Emits the current last shown page of this facet's values
@@ -79,7 +78,7 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
7978
/**
8079
* Emits all current search options available in the search URL
8180
*/
82-
searchOptions$: Observable<SearchOptions>;
81+
searchOptions$: BehaviorSubject<SearchOptions>;
8382

8483
/**
8584
* The current URL
@@ -103,7 +102,6 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
103102
*/
104103
ngOnInit(): void {
105104
this.currentUrl = this.router.url;
106-
this.filterValues$ = new BehaviorSubject(createPendingRemoteDataObject());
107105
this.currentPage = this.getCurrentPage().pipe(distinctUntilChanged());
108106

109107
this.searchOptions$ = this.searchConfigService.searchOptions;
@@ -264,33 +262,32 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
264262
return getFacetValueForType(facet, this.filterConfig);
265263
}
266264

267-
protected retrieveFilterValues(useCachedVersionIfAvailable = true): Observable<RemoteData<FacetValues[]>> {
268-
const facetValues$: Observable<RemoteData<FacetValues>> = observableCombineLatest([this.searchOptions$, this.currentPage]).pipe(
269-
switchMap(([options, page]: [SearchOptions, number]) => this.searchService.getFacetValuesFor(this.filterConfig, page, options, null, useCachedVersionIfAvailable)),
270-
getFirstSucceededRemoteData(),
271-
tap((rd: RemoteData<FacetValues>) => {
272-
this.isLastPage$.next(hasNoValue(rd?.payload?.next));
273-
}),
274-
);
265+
protected retrieveFilterValues(useCachedVersionIfAvailable = true): Observable<FacetValues[]> {
266+
return observableCombineLatest([this.searchOptions$, this.currentPage]).pipe(
267+
switchMap(([options, page]: [SearchOptions, number]) => this.searchService.getFacetValuesFor(this.filterConfig, page, options, null, useCachedVersionIfAvailable).pipe(
268+
getFirstSucceededRemoteDataPayload(),
269+
tap((facetValues: FacetValues) => {
270+
this.isLastPage$.next(hasNoValue(facetValues?.next));
271+
}),
272+
)),
273+
map((newFacetValues: FacetValues) => {
274+
let filterValues: FacetValues[] = this.filterValues$.value;
275275

276-
let filterValues: Observable<RemoteData<FacetValues>>[] = [];
277-
return facetValues$.pipe(
278-
mergeMap((newValues: RemoteData<FacetValues>) => {
279276
if (this.collapseNextUpdate) {
280277
this.showFirstPageOnly();
281278
filterValues = [];
282279
this.collapseNextUpdate = false;
283280
}
284-
if (newValues.payload.pageInfo.currentPage === 1) {
281+
if (newFacetValues.pageInfo.currentPage === 1) {
285282
filterValues = [];
286283
}
287284

288-
filterValues = [...filterValues, observableOf(newValues)];
285+
filterValues = [...filterValues, newFacetValues];
289286

290-
return this.rdbs.aggregate(filterValues);
287+
return filterValues;
291288
}),
292-
tap((rd: RemoteData<FacetValues[]>) => {
293-
const allAppliedFilters: AppliedFilter[] = [].concat(...rd.payload.map((facetValues: FacetValues) => facetValues.appliedFilters))
289+
tap((rd: FacetValues[]) => {
290+
const allAppliedFilters: AppliedFilter[] = [].concat(...rd.map((facetValues: FacetValues) => facetValues.appliedFilters))
294291
.filter((appliedFilter: AppliedFilter) => hasValue(appliedFilter));
295292
this.selectedValues$ = this.filterService.getSelectedValuesForFilter(this.filterConfig).pipe(
296293
map((selectedValues: string[]) => {

src/app/shared/search/search-filters/search-filter/search-hierarchy-filter/search-hierarchy-filter.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div>
22
<div class="filters py-2">
33
<ds-search-facet-selected-option *ngFor="let value of (selectedValues$ | async)" [selectedValue]="value" [filterConfig]="filterConfig" [selectedValues$]="selectedValues$" [inPlaceSearch]="inPlaceSearch"></ds-search-facet-selected-option>
4-
<ng-container *ngFor="let page of (filterValues$ | async)?.payload">
4+
<ng-container *ngFor="let page of (filterValues$ | async)">
55
<div [@facetLoad]="animationState">
66
<ds-search-facet-option *ngFor="let value of page.page; trackBy: trackUpdate" [filterConfig]="filterConfig" [filterValue]="value" [selectedValues$]="selectedValues$" [inPlaceSearch]="inPlaceSearch"></ds-search-facet-option>
77
</div>

src/app/shared/search/search-filters/search-filter/search-range-filter/search-range-filter.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
[(ngModel)]="range" ngDefaultControl>
4040
</nouislider>
4141
</ng-container>
42-
<ng-container *ngFor="let page of (filterValues$ | async)?.payload">
42+
<ng-container *ngFor="let page of (filterValues$ | async)">
4343
<div [@facetLoad]="animationState">
4444
<ds-search-facet-range-option *ngFor="let value of page.page; trackBy: trackUpdate" [filterConfig]="filterConfig" [filterValue]="value" [inPlaceSearch]="inPlaceSearch"></ds-search-facet-range-option>
4545
</div>

src/app/shared/search/search-filters/search-filter/search-text-filter/search-text-filter.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div>
22
<div class="filters py-2">
33
<ds-search-facet-selected-option *ngFor="let value of (selectedValues$ | async)" [selectedValue]="value" [filterConfig]="filterConfig" [selectedValues$]="selectedValues$" [inPlaceSearch]="inPlaceSearch"></ds-search-facet-selected-option>
4-
<ng-container *ngFor="let page of (filterValues$ | async)?.payload">
4+
<ng-container *ngFor="let page of (filterValues$ | async)">
55
<div [@facetLoad]="animationState">
66
<ds-search-facet-option *ngFor="let value of page.page; trackBy: trackUpdate" [filterConfig]="filterConfig" [filterValue]="value" [selectedValues$]="selectedValues$" [inPlaceSearch]="inPlaceSearch"></ds-search-facet-option>
77
</div>

0 commit comments

Comments
 (0)