Use switchMapTo instead of switchMap

This commit is contained in:
Adina Țeudan 2021-11-22 21:44:44 +02:00
parent f89f6a16ec
commit 7863adb602
7 changed files with 22 additions and 24 deletions

View File

@ -5,7 +5,7 @@ import { UserService } from '@services/user.service';
import { DossiersService } from '@services/entity-services/dossiers.service'; import { DossiersService } from '@services/entity-services/dossiers.service';
import { NotificationsService } from '@services/notifications.service'; import { NotificationsService } from '@services/notifications.service';
import { Notification } from '@red/domain'; import { Notification } from '@red/domain';
import { distinctUntilChanged, map, switchMap, tap } from 'rxjs/operators'; import { distinctUntilChanged, map, switchMapTo, tap } from 'rxjs/operators';
import { BehaviorSubject, Observable, timer } from 'rxjs'; import { BehaviorSubject, Observable, timer } from 'rxjs';
import { AutoUnsubscribe, CHANGED_CHECK_INTERVAL, List, shareLast } from '@iqser/common-ui'; import { AutoUnsubscribe, CHANGED_CHECK_INTERVAL, List, shareLast } from '@iqser/common-ui';
@ -54,7 +54,7 @@ export class NotificationsComponent extends AutoUnsubscribe implements OnInit {
this.addSubscription = timer(CHANGED_CHECK_INTERVAL, CHANGED_CHECK_INTERVAL) this.addSubscription = timer(CHANGED_CHECK_INTERVAL, CHANGED_CHECK_INTERVAL)
.pipe( .pipe(
switchMap(() => this._notificationsService.getNotificationsIfChanged(INCLUDE_SEEN)), switchMapTo(this._notificationsService.getNotificationsIfChanged(INCLUDE_SEEN)),
tap(notifications => this._notifications$.next(notifications)), tap(notifications => this._notifications$.next(notifications)),
) )
.subscribe(); .subscribe();

View File

@ -17,7 +17,7 @@ import { FileUploadService } from '@upload-download/services/file-upload.service
import { StatusOverlayService } from '@upload-download/services/status-overlay.service'; import { StatusOverlayService } from '@upload-download/services/status-overlay.service';
import * as moment from 'moment'; import * as moment from 'moment';
import { Observable, timer } from 'rxjs'; import { Observable, timer } from 'rxjs';
import { filter, switchMap, tap } from 'rxjs/operators'; import { filter, switchMapTo, tap } from 'rxjs/operators';
import { convertFiles, Files, handleFileDrop } from '@utils/index'; import { convertFiles, Files, handleFileDrop } from '@utils/index';
import { import {
CHANGED_CHECK_INTERVAL, CHANGED_CHECK_INTERVAL,
@ -141,9 +141,9 @@ export class DossierOverviewScreenComponent extends ListingComponent<File> imple
this.addSubscription = timer(CHANGED_CHECK_INTERVAL, CHANGED_CHECK_INTERVAL) this.addSubscription = timer(CHANGED_CHECK_INTERVAL, CHANGED_CHECK_INTERVAL)
.pipe( .pipe(
switchMap(() => this._filesService.hasChanges$(this.dossierId)), switchMapTo(this._filesService.hasChanges$(this.dossierId)),
filter(changed => changed), filter(changed => changed),
switchMap(() => this._reloadFiles()), switchMapTo(this._reloadFiles()),
) )
.subscribe(); .subscribe();

View File

@ -20,7 +20,7 @@ import { ConfigService } from '../config.service';
import { DossiersService } from '@services/entity-services/dossiers.service'; import { DossiersService } from '@services/entity-services/dossiers.service';
import { FilesService } from '@services/entity-services/files.service'; import { FilesService } from '@services/entity-services/files.service';
import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service'; import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service';
import { switchMap, tap } from 'rxjs/operators'; import { switchMapTo, tap } from 'rxjs/operators';
@Component({ @Component({
templateUrl: './dossiers-listing-screen.component.html', templateUrl: './dossiers-listing-screen.component.html',
@ -68,7 +68,7 @@ export class DossiersListingScreenComponent extends ListingComponent<Dossier> im
this.addSubscription = timer(CHANGED_CHECK_INTERVAL, CHANGED_CHECK_INTERVAL) this.addSubscription = timer(CHANGED_CHECK_INTERVAL, CHANGED_CHECK_INTERVAL)
.pipe( .pipe(
switchMap(() => this._dossiersService.loadAllIfChanged()), switchMapTo(this._dossiersService.loadAllIfChanged()),
tap(() => this.computeAllFilters()), tap(() => this.computeAllFilters()),
) )
.subscribe(); .subscribe();

View File

@ -592,7 +592,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
private _subscribeToFileUpdates(): void { private _subscribeToFileUpdates(): void {
this.addSubscription = timer(0, 5000) this.addSubscription = timer(0, 5000)
.pipe(switchMap(() => this._filesService.reload(this.dossierId, this.fileId))) .pipe(switchMapTo(this._filesService.reload(this.dossierId, this.fileId)))
.subscribe(); .subscribe();
this.addSubscription = this.file$.subscribe(() => { this.addSubscription = this.file$.subscribe(() => {
this._updateCanPerformActions(); this._updateCanPerformActions();

View File

@ -2,7 +2,7 @@ import { GenericService, HeadersConfiguration, List, QueryParam, RequiredParam,
import { Injectable, Injector } from '@angular/core'; import { Injectable, Injector } from '@angular/core';
import { HttpHeaders, HttpResponse } from '@angular/common/http'; import { HttpHeaders, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { switchMap } from 'rxjs/operators'; import { switchMap, switchMapTo } from 'rxjs/operators';
import { FilesService } from '@services/entity-services/files.service'; import { FilesService } from '@services/entity-services/files.service';
import { DossierStatsService } from '@services/entity-services/dossier-stats.service'; import { DossierStatsService } from '@services/entity-services/dossier-stats.service';
@ -20,7 +20,7 @@ export class FileManagementService extends GenericService<unknown> {
@Validate() @Validate()
delete(@RequiredParam() fileIds: List, @RequiredParam() dossierId: string) { delete(@RequiredParam() fileIds: List, @RequiredParam() dossierId: string) {
return super._post(fileIds, `delete/${dossierId}`).pipe(switchMap(() => this._filesService.loadAll(dossierId))); return super._post(fileIds, `delete/${dossierId}`).pipe(switchMapTo(this._filesService.loadAll(dossierId)));
} }
@Validate() @Validate()
@ -28,12 +28,12 @@ export class FileManagementService extends GenericService<unknown> {
const queryParams = fileIds.map<QueryParam>(id => ({ key: 'fileIds', value: id })); const queryParams = fileIds.map<QueryParam>(id => ({ key: 'fileIds', value: id }));
return super return super
.delete({}, `delete/hard-delete/${dossierId}`, queryParams) .delete({}, `delete/hard-delete/${dossierId}`, queryParams)
.pipe(switchMap(() => this._dossierStatsService.getFor([dossierId]))); .pipe(switchMapTo(this._dossierStatsService.getFor([dossierId])));
} }
@Validate() @Validate()
restore(@RequiredParam() body: List, @RequiredParam() dossierId: string) { restore(@RequiredParam() body: List, @RequiredParam() dossierId: string) {
return this._post(body, `delete/restore/${dossierId}`).pipe(switchMap(() => this._filesService.loadAll(dossierId))); return this._post(body, `delete/restore/${dossierId}`).pipe(switchMapTo(this._filesService.loadAll(dossierId)));
} }
downloadOriginalFile(dossierId: string, fileId: string, observe?: 'body', inline?: boolean, indicator?: string): Observable<Blob>; downloadOriginalFile(dossierId: string, fileId: string, observe?: 'body', inline?: boolean, indicator?: string): Observable<Blob>;

View File

@ -4,7 +4,7 @@ import { File, IFile } from '@red/domain';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { UserService } from '../user.service'; import { UserService } from '../user.service';
import { FilesMapService } from '@services/entity-services/files-map.service'; import { FilesMapService } from '@services/entity-services/files-map.service';
import { map, mapTo, switchMap, tap } from 'rxjs/operators'; import { map, mapTo, switchMap, switchMapTo, tap } from 'rxjs/operators';
import { DossierStatsService } from '@services/entity-services/dossier-stats.service'; import { DossierStatsService } from '@services/entity-services/dossier-stats.service';
@Injectable({ @Injectable({
@ -38,7 +38,7 @@ export class FilesService extends EntitiesService<File, IFile> {
@Validate() @Validate()
setUnderApprovalFor(@RequiredParam() fileIds: List, @RequiredParam() dossierId: string, approverId: string) { setUnderApprovalFor(@RequiredParam() fileIds: List, @RequiredParam() dossierId: string, approverId: string) {
const url = `${this._defaultModelPath}/under-approval/${dossierId}/bulk`; const url = `${this._defaultModelPath}/under-approval/${dossierId}/bulk`;
return this._post<unknown>(fileIds, url, [{ key: 'approverId', value: approverId }]).pipe(switchMap(() => this.loadAll(dossierId))); return this._post<unknown>(fileIds, url, [{ key: 'approverId', value: approverId }]).pipe(switchMapTo(this.loadAll(dossierId)));
} }
/** /**
@ -47,9 +47,7 @@ export class FilesService extends EntitiesService<File, IFile> {
@Validate() @Validate()
setReviewerFor(@RequiredParam() filesIds: List, @RequiredParam() dossierId: string, reviewerId: string) { setReviewerFor(@RequiredParam() filesIds: List, @RequiredParam() dossierId: string, reviewerId: string) {
const url = `${this._defaultModelPath}/set-reviewer/${dossierId}/bulk`; const url = `${this._defaultModelPath}/set-reviewer/${dossierId}/bulk`;
return this._post<unknown>(filesIds, url, [{ key: 'reviewerId', value: reviewerId }]).pipe( return this._post<unknown>(filesIds, url, [{ key: 'reviewerId', value: reviewerId }]).pipe(switchMapTo(this.loadAll(dossierId)));
switchMap(() => this.loadAll(dossierId)),
);
} }
/** /**
@ -58,7 +56,7 @@ export class FilesService extends EntitiesService<File, IFile> {
@Validate() @Validate()
setApprovedFor(@RequiredParam() filesIds: List, @RequiredParam() dossierId: string) { setApprovedFor(@RequiredParam() filesIds: List, @RequiredParam() dossierId: string) {
return this._post<unknown>(filesIds, `${this._defaultModelPath}/approved/${dossierId}/bulk`).pipe( return this._post<unknown>(filesIds, `${this._defaultModelPath}/approved/${dossierId}/bulk`).pipe(
switchMap(() => this.loadAll(dossierId)), switchMapTo(this.loadAll(dossierId)),
); );
} }
@ -68,7 +66,7 @@ export class FilesService extends EntitiesService<File, IFile> {
@Validate() @Validate()
setUnderReviewFor(@RequiredParam() filesIds: List, @RequiredParam() dossierId: string) { setUnderReviewFor(@RequiredParam() filesIds: List, @RequiredParam() dossierId: string) {
return this._post<unknown>(filesIds, `${this._defaultModelPath}/under-review/${dossierId}/bulk`).pipe( return this._post<unknown>(filesIds, `${this._defaultModelPath}/under-review/${dossierId}/bulk`).pipe(
switchMap(() => this.loadAll(dossierId)), switchMapTo(this.loadAll(dossierId)),
); );
} }

View File

@ -14,12 +14,12 @@ export class ReanalysisService extends GenericService<unknown> {
@Validate() @Validate()
excludePages(@RequiredParam() body: IPageExclusionRequest, @RequiredParam() dossierId: string, @RequiredParam() fileId: string) { excludePages(@RequiredParam() body: IPageExclusionRequest, @RequiredParam() dossierId: string, @RequiredParam() fileId: string) {
return this._post(body, `exclude-pages/${dossierId}/${fileId}`).pipe(switchMap(() => this._filesService.reload(dossierId, fileId))); return this._post(body, `exclude-pages/${dossierId}/${fileId}`).pipe(switchMapTo(this._filesService.reload(dossierId, fileId)));
} }
@Validate() @Validate()
includePages(@RequiredParam() body: IPageExclusionRequest, @RequiredParam() dossierId: string, @RequiredParam() fileId: string) { includePages(@RequiredParam() body: IPageExclusionRequest, @RequiredParam() dossierId: string, @RequiredParam() fileId: string) {
return this._post(body, `include-pages/${dossierId}/${fileId}`).pipe(switchMap(() => this._filesService.reload(dossierId, fileId))); return this._post(body, `include-pages/${dossierId}/${fileId}`).pipe(switchMapTo(this._filesService.reload(dossierId, fileId)));
} }
@Validate() @Validate()
@ -29,7 +29,7 @@ export class ReanalysisService extends GenericService<unknown> {
queryParams.push({ key: 'force', value: force }); queryParams.push({ key: 'force', value: force });
} }
return this._post(fileIds, `reanalyze/${dossierId}/bulk`, queryParams).pipe(switchMap(() => this._filesService.loadAll(dossierId))); return this._post(fileIds, `reanalyze/${dossierId}/bulk`, queryParams).pipe(switchMapTo(this._filesService.loadAll(dossierId)));
} }
@Validate() @Validate()
@ -40,13 +40,13 @@ export class ReanalysisService extends GenericService<unknown> {
} }
return this._post({}, `toggle-analysis/${dossierId}/${fileId}`, queryParams).pipe( return this._post({}, `toggle-analysis/${dossierId}/${fileId}`, queryParams).pipe(
switchMap(() => this._filesService.loadAll(dossierId)), switchMapTo(this._filesService.loadAll(dossierId)),
); );
} }
@Validate() @Validate()
ocrFiles(@RequiredParam() body: List, @RequiredParam() dossierId: string) { ocrFiles(@RequiredParam() body: List, @RequiredParam() dossierId: string) {
return this._post(body, `ocr/reanalyze/${dossierId}/bulk`).pipe(switchMap(() => this._filesService.loadAll(dossierId))); return this._post(body, `ocr/reanalyze/${dossierId}/bulk`).pipe(switchMapTo(this._filesService.loadAll(dossierId)));
} }
@Validate() @Validate()