-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix resetting colors in color metrics
- Loading branch information
1 parent
1eaa516
commit 6d32d16
Showing
2 changed files
with
29 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 22 additions & 20 deletions
42
...alization/app/codeCharta/state/store/dynamicSettings/colorRange/resetColorRange.effect.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,38 @@ | ||
import { Injectable } from "@angular/core" | ||
import { Store } from "@ngrx/store" | ||
import { Actions, createEffect, ofType } from "@ngrx/effects" | ||
import { map, skip, switchMap, take, withLatestFrom } from "rxjs" | ||
import { selectedColorMetricDataSelector } from "../../../selectors/accumulatedData/metricData/selectedColorMetricData.selector" | ||
import { Store } from "@ngrx/store" | ||
import { map, switchMap, take, withLatestFrom } from "rxjs/operators" | ||
import { calculateInitialColorRange } from "./calculateInitialColorRange" | ||
import { selectedColorMetricDataSelector } from "../../../selectors/accumulatedData/metricData/selectedColorMetricData.selector" | ||
import { setColorRange } from "./colorRange.actions" | ||
import { fileActions } from "../../files/files.actions" | ||
import { setFiles } from "../../files/files.actions" | ||
import { CcState } from "../../../../codeCharta.model" | ||
import { setColorMetric } from "../colorMetric/colorMetric.actions" | ||
import { visibleFileStatesSelector } from "../../../selectors/visibleFileStates/visibleFileStates.selector" | ||
import { colorRangeSelector } from "./colorRange.selector" | ||
|
||
@Injectable() | ||
export class ResetColorRangeEffect { | ||
constructor( | ||
private actions$: Actions, | ||
private store: Store<CcState> | ||
private readonly actions$: Actions, | ||
private readonly store: Store<CcState> | ||
) {} | ||
|
||
// Only reset colors when loading new files, not when changing metrics | ||
resetColorRange$ = createEffect(() => | ||
this.actions$.pipe( | ||
ofType(...fileActions), | ||
withLatestFrom(this.store.select(visibleFileStatesSelector)), | ||
switchMap(() => this.store.select(selectedColorMetricDataSelector).pipe(skip(1), take(1))), | ||
map(selectedColorMetricData => setColorRange({ value: calculateInitialColorRange(selectedColorMetricData) })) | ||
) | ||
) | ||
|
||
resetColorRangeOnColorMetricChange$ = createEffect(() => | ||
this.actions$.pipe( | ||
ofType(setColorMetric), | ||
switchMap(() => this.store.select(selectedColorMetricDataSelector).pipe(take(1))), | ||
map(selectedColorMetricData => setColorRange({ value: calculateInitialColorRange(selectedColorMetricData) })) | ||
ofType(setFiles), | ||
withLatestFrom(this.store.select(colorRangeSelector)), | ||
switchMap(([_, currentColorRange]) => | ||
this.store.select(selectedColorMetricDataSelector).pipe( | ||
take(1), | ||
map(selectedColorMetricData => { | ||
// Only set initial colors if we don't have any custom colors yet | ||
if (currentColorRange.from === 0 && currentColorRange.to === 0) { | ||
return setColorRange({ value: calculateInitialColorRange(selectedColorMetricData) }) | ||
} | ||
return setColorRange({ value: currentColorRange }) | ||
}) | ||
) | ||
) | ||
) | ||
) | ||
} |