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 { NotificationsService } from '@services/notifications.service';
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 { 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)
.pipe(
switchMap(() => this._notificationsService.getNotificationsIfChanged(INCLUDE_SEEN)),
switchMapTo(this._notificationsService.getNotificationsIfChanged(INCLUDE_SEEN)),
tap(notifications => this._notifications$.next(notifications)),
)
.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 * as moment from 'moment';
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 {
CHANGED_CHECK_INTERVAL,
@ -141,9 +141,9 @@ export class DossierOverviewScreenComponent extends ListingComponent<File> imple
this.addSubscription = timer(CHANGED_CHECK_INTERVAL, CHANGED_CHECK_INTERVAL)
.pipe(
switchMap(() => this._filesService.hasChanges$(this.dossierId)),
switchMapTo(this._filesService.hasChanges$(this.dossierId)),
filter(changed => changed),
switchMap(() => this._reloadFiles()),
switchMapTo(this._reloadFiles()),
)
.subscribe();

View File

@ -20,7 +20,7 @@ import { ConfigService } from '../config.service';
import { DossiersService } from '@services/entity-services/dossiers.service';
import { FilesService } from '@services/entity-services/files.service';
import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service';
import { switchMap, tap } from 'rxjs/operators';
import { switchMapTo, tap } from 'rxjs/operators';
@Component({
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)
.pipe(
switchMap(() => this._dossiersService.loadAllIfChanged()),
switchMapTo(this._dossiersService.loadAllIfChanged()),
tap(() => this.computeAllFilters()),
)
.subscribe();

View File

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

View File

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

View File

@ -4,7 +4,7 @@ import { File, IFile } from '@red/domain';
import { Observable } from 'rxjs';
import { UserService } from '../user.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';
@Injectable({
@ -38,7 +38,7 @@ export class FilesService extends EntitiesService<File, IFile> {
@Validate()
setUnderApprovalFor(@RequiredParam() fileIds: List, @RequiredParam() dossierId: string, approverId: string) {
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()
setReviewerFor(@RequiredParam() filesIds: List, @RequiredParam() dossierId: string, reviewerId: string) {
const url = `${this._defaultModelPath}/set-reviewer/${dossierId}/bulk`;
return this._post<unknown>(filesIds, url, [{ key: 'reviewerId', value: reviewerId }]).pipe(
switchMap(() => this.loadAll(dossierId)),
);
return this._post<unknown>(filesIds, url, [{ key: 'reviewerId', value: reviewerId }]).pipe(switchMapTo(this.loadAll(dossierId)));
}
/**
@ -58,7 +56,7 @@ export class FilesService extends EntitiesService<File, IFile> {
@Validate()
setApprovedFor(@RequiredParam() filesIds: List, @RequiredParam() dossierId: string) {
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()
setUnderReviewFor(@RequiredParam() filesIds: List, @RequiredParam() dossierId: string) {
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()
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()
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()
@ -29,7 +29,7 @@ export class ReanalysisService extends GenericService<unknown> {
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()
@ -40,13 +40,13 @@ export class ReanalysisService extends GenericService<unknown> {
}
return this._post({}, `toggle-analysis/${dossierId}/${fileId}`, queryParams).pipe(
switchMap(() => this._filesService.loadAll(dossierId)),
switchMapTo(this._filesService.loadAll(dossierId)),
);
}
@Validate()
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()