diff --git a/src/lib/filtering/filter.service.ts b/src/lib/filtering/filter.service.ts index 2e94b57..edf35da 100644 --- a/src/lib/filtering/filter.service.ts +++ b/src/lib/filtering/filter.service.ts @@ -19,7 +19,7 @@ export class FilterService { this.filterGroups$ = this._refresh$.pipe( startWith(''), switchMap(() => this._filterGroups$.asObservable()), - shareReplay(), + shareReplay(1), ); this.showResetFilters$ = this._showResetFilters$; @@ -34,7 +34,7 @@ export class FilterService { map(toFlatFilters), map(f => !!f.find(el => el.checked)), distinctUntilChanged(), - shareReplay(), + shareReplay(1), ); } @@ -99,7 +99,7 @@ export class FilterService { getGroup$(slug: string): Observable { return this.filterGroups$.pipe( get(group => group.slug === slug), - shareReplay(), + shareReplay(1), ); } diff --git a/src/lib/filtering/popup-filter/popup-filter.component.html b/src/lib/filtering/popup-filter/popup-filter.component.html index 404682c..438a2dc 100644 --- a/src/lib/filtering/popup-filter/popup-filter.component.html +++ b/src/lib/filtering/popup-filter/popup-filter.component.html @@ -1,15 +1,8 @@ - + - - - + - - !!nestedFilter?.children? const atLeastOneIsExpandable = pipe( map(group => !!group?.filters.some(areExpandable)), distinctUntilChanged(), - shareReplay(), + shareReplay(1), ); @Component({ @@ -47,6 +47,7 @@ export class PopupFilterComponent implements OnInit { primaryFilterGroup$!: Observable; secondaryFilterGroup$!: Observable; primaryFilters$!: Observable; + primaryFiltersDisabled$!: Observable; constructor(readonly filterService: FilterService, readonly searchService: SearchService) {} @@ -55,15 +56,33 @@ export class PopupFilterComponent implements OnInit { map(([primary, secondary]) => [...(primary?.filters || []), ...(secondary?.filters || [])]), any(f => f.checked || !!f.indeterminate), distinctUntilChanged(), + shareReplay(1), + ); + } + + private get _primaryFilters$(): Observable { + return combineLatest([this.primaryFilterGroup$, this.searchService.valueChanges$]).pipe( + map(([group]) => this.searchService.searchIn(group?.filters ?? [])), + shareReplay(1), + ); + } + + private get _primaryFiltersDisabled$(): Observable { + return combineLatest([this.primaryFilterGroup$, this.primaryFilters$, this.searchService.valueChanges$]).pipe( + map(([group, filters, value]) => [!!group?.filterceptionPlaceholder, filters?.length === 0, value === '']), + map(([hasFilterSearch, noFilters, searchIsEmpty]) => noFilters && (!hasFilterSearch || (hasFilterSearch && searchIsEmpty))), + distinctUntilChanged(), + shareReplay(1), ); } ngOnInit(): void { - this.primaryFilterGroup$ = this.filterService.getGroup$(this.primaryFiltersSlug).pipe(shareReplay(2)); + this.primaryFilterGroup$ = this.filterService.getGroup$(this.primaryFiltersSlug).pipe(shareReplay(1)); this.primaryFilters$ = this._primaryFilters$; - this.secondaryFilterGroup$ = this.filterService.getGroup$(this.secondaryFiltersSlug).pipe(shareReplay(3)); + this.secondaryFilterGroup$ = this.filterService.getGroup$(this.secondaryFiltersSlug).pipe(shareReplay(1)); this.hasActiveFilters$ = this._hasActiveFilters$; + this.primaryFiltersDisabled$ = this._primaryFiltersDisabled$; this.atLeastOneFilterIsExpandable$ = atLeastOneIsExpandable(this.primaryFilterGroup$); this.atLeastOneSecondaryFilterIsExpandable$ = atLeastOneIsExpandable(this.secondaryFilterGroup$); } @@ -120,10 +139,4 @@ export class PopupFilterComponent implements OnInit { }); this.filterService.refresh(); } - - private get _primaryFilters$(): Observable { - return combineLatest([this.primaryFilterGroup$, this.searchService.valueChanges$]).pipe( - map(([group]) => this.searchService.searchIn(group?.filters ?? [])), - ); - } } diff --git a/src/lib/listing/listing-component.directive.ts b/src/lib/listing/listing-component.directive.ts index 214ce35..a6e3f45 100644 --- a/src/lib/listing/listing-component.directive.ts +++ b/src/lib/listing/listing-component.directive.ts @@ -48,13 +48,13 @@ export abstract class ListingComponent extends AutoUnsubscr private get _sortedDisplayedEntities$(): Observable { const sort = (entities: T[]) => this.sortingService.defaultSort(entities); const sortedEntities = () => this.listingService.displayed$.pipe(map(sort)); - return this.sortingService.sortingOption$.pipe(switchMap(sortedEntities), distinctUntilChanged(), shareReplay()); + return this.sortingService.sortingOption$.pipe(switchMap(sortedEntities), distinctUntilChanged(), shareReplay(1)); } private get _noMatch$(): Observable { return combineLatest([this.entitiesService.allLength$, this.listingService.displayedLength$]).pipe( map(([hasEntities, hasDisplayedEntities]) => !!hasEntities && !hasDisplayedEntities), - shareReplay(), + shareReplay(1), distinctUntilChanged(), ); } @@ -62,7 +62,7 @@ export abstract class ListingComponent extends AutoUnsubscr private get _noContent$(): Observable { return combineLatest([this._noMatch$, this.entitiesService.noData$]).pipe( map(([noMatch, noData]) => noMatch || noData), - shareReplay(), + shareReplay(1), distinctUntilChanged(), ); } diff --git a/src/lib/listing/services/entities.service.ts b/src/lib/listing/services/entities.service.ts index dd8a7bb..e070f0b 100644 --- a/src/lib/listing/services/entities.service.ts +++ b/src/lib/listing/services/entities.service.ts @@ -30,8 +30,8 @@ export class EntitiesService extends GenericService< @Optional() @Inject(ENTITY_PATH) protected readonly _defaultModelPath = '', ) { super(_injector, _defaultModelPath); - this.all$ = this._all$.asObservable().pipe(distinctUntilChanged(), shareReplay()); - this.allLength$ = this._all$.pipe(getLength, distinctUntilChanged(), shareReplay()); + this.all$ = this._all$.asObservable().pipe(distinctUntilChanged(), shareReplay(1)); + this.allLength$ = this._all$.pipe(getLength, distinctUntilChanged(), shareReplay(1)); this.noData$ = this._noData$; } diff --git a/src/lib/listing/services/listing.service.ts b/src/lib/listing/services/listing.service.ts index 86b7815..2b38dae 100644 --- a/src/lib/listing/services/listing.service.ts +++ b/src/lib/listing/services/listing.service.ts @@ -28,14 +28,14 @@ export class ListingService extends AutoUnsubscribe { super(); this.displayed$ = this._getDisplayed$; - this.displayedLength$ = this.displayed$.pipe(getLength, distinctUntilChanged(), shareReplay()); + this.displayedLength$ = this.displayed$.pipe(getLength, distinctUntilChanged(), shareReplay(1)); - this.selected$ = this._selected$.asObservable().pipe(shareReplay()); + this.selected$ = this._selected$.asObservable().pipe(shareReplay(1)); this.selectedEntities$ = this._selected$.asObservable().pipe( map(() => this.selected), - shareReplay(), + shareReplay(1), ); - this.selectedLength$ = this._selected$.pipe(getLength, distinctUntilChanged(), shareReplay()); + this.selectedLength$ = this._selected$.pipe(getLength, distinctUntilChanged(), shareReplay(1)); this.areAllSelected$ = this._areAllSelected$; this.areSomeSelected$ = this._areSomeSelected$; @@ -66,7 +66,7 @@ export class ListingService extends AutoUnsubscribe { this._displayed = displayed; }), distinctUntilChanged(), - shareReplay(), + shareReplay(1), ); } @@ -74,7 +74,7 @@ export class ListingService extends AutoUnsubscribe { return combineLatest([this.displayedLength$, this.selectedLength$]).pipe( map(([displayedLength, selectedLength]) => !!displayedLength && displayedLength === selectedLength), distinctUntilChanged(), - shareReplay(), + shareReplay(1), ); } @@ -82,7 +82,7 @@ export class ListingService extends AutoUnsubscribe { return this.selectedLength$.pipe( map(length => !!length), distinctUntilChanged(), - shareReplay(), + shareReplay(1), ); } @@ -90,7 +90,7 @@ export class ListingService extends AutoUnsubscribe { return combineLatest([this.areAllSelected$, this.areSomeSelected$]).pipe( map(([allAreSelected, someAreSelected]) => !allAreSelected && someAreSelected), distinctUntilChanged(), - shareReplay(), + shareReplay(1), ); } diff --git a/src/lib/search/search.service.ts b/src/lib/search/search.service.ts index 6358c80..79a6cf3 100644 --- a/src/lib/search/search.service.ts +++ b/src/lib/search/search.service.ts @@ -7,7 +7,7 @@ import { distinctUntilChanged, shareReplay } from 'rxjs/operators'; export class SearchService { skip = false; private readonly _query$ = new BehaviorSubject(''); - readonly valueChanges$ = this._query$.asObservable().pipe(distinctUntilChanged(), shareReplay()); + readonly valueChanges$ = this._query$.asObservable().pipe(distinctUntilChanged(), shareReplay(1)); get searchValue(): string { return this._query$.getValue(); diff --git a/src/lib/sorting/sorting.service.ts b/src/lib/sorting/sorting.service.ts index 78ff90e..987a301 100644 --- a/src/lib/sorting/sorting.service.ts +++ b/src/lib/sorting/sorting.service.ts @@ -13,7 +13,7 @@ export class SortingService { column: 'searchKey', order: SortingOrders.asc, }); - readonly sortingOption$ = this._sortingOption$.asObservable().pipe(distinctUntilChanged(), shareReplay()); + readonly sortingOption$ = this._sortingOption$.asObservable().pipe(distinctUntilChanged(), shareReplay(1)); get sortingOption(): SortingOption | undefined { return this._sortingOption$.getValue();