Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Fix update of User roles table after a role has been removed #2630

Merged
merged 4 commits into from
Jul 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/frontend/app/shared/monitors/pagination-monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@ import { Store } from '@ngrx/store';
import { denormalize, schema } from 'normalizr';
import { asapScheduler, Observable } from 'rxjs';
import { tag } from 'rxjs-spy/operators';
import { distinctUntilChanged, filter, map, observeOn, publishReplay, refCount, withLatestFrom } from 'rxjs/operators';
import { getAPIRequestDataState } from '../../store/selectors/api.selectors';
import {
combineLatest as combineLatestOperator,
distinctUntilChanged,
filter,
map,
observeOn,
publishReplay,
refCount,
withLatestFrom,
tap,
} from 'rxjs/operators';

import { getAPIRequestDataState, selectEntities } from '../../store/selectors/api.selectors';
import { selectPaginationState } from '../../store/selectors/pagination.selectors';
import { AppState } from './../../store/app-state';
import { ActionState } from './../../store/reducers/api-request-reducer/types';
import { PaginationEntityState } from './../../store/types/pagination.types';


export class PaginationMonitor<T = any> {
/**
* Emits the current page of entities.
Expand Down Expand Up @@ -117,13 +127,16 @@ export class PaginationMonitor<T = any> {
pagination$: Observable<PaginationEntityState>,
schema: schema.Entity
) {
const entityObservable$ = this.store.select(selectEntities<T>(this.schema.key)).pipe(distinctUntilChanged());
const allEntitiesObservable$ = this.store.select(getAPIRequestDataState);
return pagination$.pipe(
// Improve efficiency
observeOn(asapScheduler),
filter((pagination) => this.hasPage(pagination)),
distinctUntilChanged(this.isPageSameIsh),
withLatestFrom(this.store.select(getAPIRequestDataState)),
map(([pagination, allEntities]) => {
combineLatestOperator(entityObservable$),
withLatestFrom(allEntitiesObservable$),
map(([[pagination], allEntities]) => {
const page = pagination.ids[pagination.currentPage] || [];
return page.length ? denormalize(page, [schema], allEntities).filter(ent => !!ent) : [];
}),
Expand Down