Merge branch 'VM/RED-10483' into 'master'
RED-10483 - stop making additional dossier requests which leads to "Dossier... Closes RED-10483 See merge request redactmanager/red-ui!712
This commit is contained in:
commit
c02863b079
@ -1,5 +1,5 @@
|
||||
import { GenericService, ROOT_CHANGES_KEY } from '@iqser/common-ui';
|
||||
import { Dossier, DossierStats, IChangesDetails } from '@red/domain';
|
||||
import { Dossier, IChangesDetails, IDossierChanges } from '@red/domain';
|
||||
import { forkJoin, Observable, Subscription, timer } from 'rxjs';
|
||||
import { filter, map, switchMap, take, tap } from 'rxjs/operators';
|
||||
import { NGXLogger } from 'ngx-logger';
|
||||
@ -24,17 +24,18 @@ export class DossiersChangesService extends GenericService<Dossier> implements O
|
||||
protected readonly _defaultModelPath = 'dossier';
|
||||
|
||||
loadOnlyChanged(): Observable<IChangesDetails> {
|
||||
const load = (changes: IChangesDetails) => this.#load(changes.dossierChanges.map(d => d.dossierId));
|
||||
const load = (changes: IChangesDetails) => this.#load(this.#mapDossierChanges(changes.dossierChanges));
|
||||
|
||||
const loadStats = (change: IChangesDetails) => {
|
||||
const dossierStatsToLoad = new Set<string>();
|
||||
change.dossierChanges.forEach(dossierChange => dossierStatsToLoad.add(dossierChange.dossierId));
|
||||
change.fileChanges.forEach(fileChange => dossierStatsToLoad.add(fileChange.dossierId));
|
||||
return this.#dossierStatsService.getFor(Array.from(dossierStatsToLoad));
|
||||
const dossierIds = this.#filterDossierIds(Array.from(dossierStatsToLoad));
|
||||
return this.#dossierStatsService.getFor(dossierIds);
|
||||
};
|
||||
|
||||
return this.hasChangesDetails$().pipe(
|
||||
tap(changes => this.#logger.info('[DOSSIERS_CHANGES] Found changes', changes)),
|
||||
tap(changes => console.log('[DOSSIERS_CHANGES] Found changes', changes)),
|
||||
switchMap(dossierChanges =>
|
||||
forkJoin([load(dossierChanges), loadStats(dossierChanges), this.#dashboardStatsService.loadAll().pipe(take(1))]).pipe(
|
||||
map(() => dossierChanges),
|
||||
@ -97,4 +98,13 @@ export class DossiersChangesService extends GenericService<Dossier> implements O
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
#filterDossierIds(ids: string[]) {
|
||||
return ids.filter(id => this.#dashboardStatsService.all.find(stats => stats.dossiersInTemplate.includes(id)));
|
||||
}
|
||||
|
||||
#mapDossierChanges(dossierChanges: IDossierChanges | string[]): string[] {
|
||||
const dossierIds = dossierChanges.map(change => change.dossierId);
|
||||
return this.#filterDossierIds(dossierIds);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { StatsService } from '@iqser/common-ui';
|
||||
import { DOSSIER_ID, DossierStats, IDossierStats } from '@red/domain';
|
||||
import { DashboardStats, DOSSIER_ID, DossierStats, IDossierStats } from '@red/domain';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { UserService } from '@users/user.service';
|
||||
import { NGXLogger } from 'ngx-logger';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user