Skip to content

Commit

Permalink
fix: display 'scheme stopped' notification only when scheme is actual…
Browse files Browse the repository at this point in the history
…ly stopped
  • Loading branch information
nvsukhanov committed Mar 29, 2024
1 parent dd14ff3 commit 63dabaf
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Actions, concatLatestFrom, createEffect, ofType } from '@ngrx/effects';
import { Observable, catchError, forkJoin, map, mergeMap, of, switchMap, take, timeout } from 'rxjs';
import { Observable, catchError, filter, forkJoin, map, mergeMap, of, switchMap, take, timeout } from 'rxjs';
import { Action, Store } from '@ngrx/store';
import { inject } from '@angular/core';
import { Dictionary } from '@ngrx/entity';
Expand Down Expand Up @@ -32,16 +32,13 @@ function getUniqueConnectedHubPorts(
}

function terminateScheme(
schemeModel: ControlSchemeModel | null,
schemeModel: ControlSchemeModel,
store: Store,
taskBuilder: ITaskFactory,
hubStorage: HubStorageService,
taskRunner: ITaskRunner,
timeoutMs: number,
): Observable<Action> {
if (!schemeModel) {
return of(CONTROL_SCHEME_ACTIONS.schemeStopped());
}
return of(schemeModel).pipe(
concatLatestFrom(() => [
store.select(HUB_RUNTIME_DATA_SELECTORS.selectIds),
Expand Down Expand Up @@ -87,6 +84,8 @@ export const STOP_SCHEME_EFFECT = createEffect((
return actions.pipe(
ofType(CONTROL_SCHEME_ACTIONS.stopScheme),
concatLatestFrom(() => store.select(CONTROL_SCHEME_SELECTORS.selectRunningScheme)),
mergeMap(([ , runningScheme ]) => terminateScheme(runningScheme, store, taskFactory, hubStorage, taskRunner, appConfig.schemeStartStopTimeoutMs))
map(([, runningScheme]) => runningScheme),
filter((runningScheme): runningScheme is ControlSchemeModel => !!runningScheme),
mergeMap((runningScheme) => terminateScheme(runningScheme, store, taskFactory, hubStorage, taskRunner, appConfig.schemeStartStopTimeoutMs))
) as Observable<Action>;
}, { functional: true });

0 comments on commit 63dabaf

Please sign in to comment.