Skip to content

Commit

Permalink
Merge pull request #559 from SUSE/fix-refresh-maxed-list
Browse files Browse the repository at this point in the history
Fix application of `maxed` lists following page refresh
  • Loading branch information
richard-cox authored Nov 23, 2022
2 parents b4438a9 + 69f6a91 commit 06242a6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ jobs:
- name: Backend Lint
before_script:
- "./deploy/ci/travis/install-go.sh"
- go get -u golang.org/x/lint/golint
- export GO111MODULE=on
- go get golang.org/x/lint/[email protected]
script:
- golint src/jetstream/...
- ./deploy/ci/travis/update-go-report-card.sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Store } from '@ngrx/store';
import {
asapScheduler,
BehaviorSubject,
combineLatest,
combineLatest as observableCombineLatest,
isObservable,
Observable,
Expand All @@ -39,6 +40,7 @@ import {
refCount,
startWith,
subscribeOn,
switchMap,
takeWhile,
tap,
withLatestFrom,
Expand Down Expand Up @@ -468,7 +470,13 @@ export class ListComponent<T> implements OnInit, OnChanges, OnDestroy, AfterView
// - Pass any multi filter changes made by the user to the pagination controller and thus the store
// - If the first multi filter has one value it's not shown, ensure it's automatically selected to ensure other filters are correct
this.multiFilterWidgetObservables = new Array<Subscription>();
this.paginationController.filter$.pipe(

combineLatest(this.multiFilterManagers.map(mfm => {
// Use this instead of filterIsReady$ to ensure the drop downs report as ready even when there's nothing to select
return mfm.filterIsInitialised$;
})).pipe(
filter(firs => firs.every(ready => ready)),
switchMap(() => this.paginationController.filter$),
first(),
tap(() => {
Object.values(this.multiFilterManagers).forEach((filterManager: MultiFilterManager<T>, index: number) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,18 @@ export interface IGlobalListAction<T> extends IOptionalAction<T> {
action: () => void;
}

/**
* Class to support a single multi filter entry/drop down
*/
export class MultiFilterManager<T> {
/**
* Supporting dependencies ready and there are items available to select
*/
public filterIsReady$: Observable<boolean>;
/**
* Supporting dependencies ready and the items to select have been fetched (but may be zero)
*/
public filterIsInitialised$: Observable<boolean>;
public filterItems$: Observable<IListMultiFilterConfigItem[]>;
public hasItems$: Observable<boolean>;
public hasOneOrLessItems$: Observable<boolean>;
Expand All @@ -225,6 +235,7 @@ export class MultiFilterManager<T> {
this.hasOneOrLessItems$ = this.filterItems$.pipe(map(items => items.length <= 1));
this.hasItems$ = this.filterItems$.pipe(map(items => !!items.length));
this.filterIsReady$ = this.getReadyObservable(multiFilterConfig, dataSource, this.hasItems$);
this.filterIsInitialised$ = this.getInitialisedObservable(multiFilterConfig, dataSource, this.filterItems$);

// Also select the first option if configured
if (multiFilterConfig.autoSelectFirst) {
Expand All @@ -251,6 +262,21 @@ export class MultiFilterManager<T> {
);
}

private getInitialisedObservable(
multiFilterConfig: IListMultiFilterConfig,
dataSource: IListDataSource<T>,
filterItems$: Observable<IListMultiFilterConfigItem[]>
) {
return combineLatest(
dataSource.isLoadingPage$,
multiFilterConfig.loading$,
filterItems$,
).pipe(
map(([fetchingListPage, fetchingFilter, filterItems]) => (!fetchingListPage && !fetchingFilter) && !!filterItems),
startWith(false)
);
}

private getItemObservable(multiFilterConfig: IListMultiFilterConfig) {
return multiFilterConfig.list$.pipe(
map(list => list ? list : [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ export class LocalStorageService {
params: paginationSection.params,
clientPagination: paginationSection.clientPagination,
isListPagination: paginationSection.isListPagination, // We do not persist any that are false
forcedLocalPage: paginationSection.forcedLocalPage // Value of the multi-entity filter
forcedLocalPage: paginationSection.forcedLocalPage, // Value of the multi-entity filter
// Persist this state, so the console knows to set q params on filter change (means user is stuck in max'd view)
maxedState: paginationSection.maxedState
};
return res2;
}, {});
Expand Down

0 comments on commit 06242a6

Please sign in to comment.