111731: Simplified the response of the retrieveFilterValues#facetValues$ by removing the page option

This commit is contained in:
Alexandre Vryghem
2024-02-09 16:15:01 +01:00
parent 1eadb412a6
commit f95c941c49
2 changed files with 13 additions and 21 deletions

View File

@@ -265,38 +265,27 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
}
protected retrieveFilterValues(useCachedVersionIfAvailable = true): Observable<RemoteData<FacetValues[]>> {
const facetValues$: Observable<{ values: Observable<RemoteData<FacetValues>>, page: number}> = observableCombineLatest([this.searchOptions$, this.currentPage]).pipe(
switchMap(([options, page]: [SearchOptions, number]) => {
return this.searchService.getFacetValuesFor(this.filterConfig, page, options, null, useCachedVersionIfAvailable)
.pipe(
const facetValues$: Observable<RemoteData<FacetValues>> = observableCombineLatest([this.searchOptions$, this.currentPage]).pipe(
switchMap(([options, page]: [SearchOptions, number]) => this.searchService.getFacetValuesFor(this.filterConfig, page, options, null, useCachedVersionIfAvailable)),
getFirstSucceededRemoteData(),
tap((rd: RemoteData<FacetValues>) => {
this.isLastPage$.next(hasNoValue(rd?.payload?.next));
}),
map((rd: RemoteData<FacetValues>) => ({
values: observableOf(rd),
page: page
})
)
);
})
);
let filterValues: Observable<RemoteData<FacetValues>>[] = [];
return facetValues$.pipe(
mergeMap((facetOutcome: { values: Observable<RemoteData<FacetValues>>, page: number}) => {
const newValues$ = facetOutcome.values;
mergeMap((newValues: RemoteData<FacetValues>) => {
if (this.collapseNextUpdate) {
this.showFirstPageOnly();
facetOutcome.page = 1;
filterValues = [];
this.collapseNextUpdate = false;
}
if (facetOutcome.page === 1) {
if (newValues.payload.pageInfo.currentPage === 1) {
filterValues = [];
}
filterValues = [...filterValues, newValues$];
filterValues = [...filterValues, observableOf(newValues)];
return this.rdbs.aggregate(filterValues);
}),

View File

@@ -62,6 +62,9 @@ describe('SearchHierarchyFilterComponent', () => {
value: value3,
},
],
pageInfo: {
currentPage: 1,
},
} as Partial<FacetValues> as FacetValues;
const searchFilterServiceStub = {