Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: keep selected metrics when excluding buildings #2935

Merged
merged 5 commits into from Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/)
- Fix SonarImporter requesting no metrics from SonarQube when the list of metrics was left empty [#2913](https://github.com/MaibornWolff/codecharta/pull/2913)
- Exclude edge metrics from custom scenarios, when there are no edge metrics available. Before it was impossible to apply those custom configs [#2928](https://github.com/MaibornWolff/codecharta/pull/2928)
- Fix of NoSuchMethodException due to a call of method `readNBytes()` that is not available in Java 9 with replacement call `read()` [#2930](https://github.com/MaibornWolff/codecharta/pull/2930)
- Keep selected metrics when excluding buildings [#2935](https://github.com/MaibornWolff/codecharta/pull/2935)
- Update UI correctly when toggling between standard and delta mode [#2937](https://github.com/MaibornWolff/codecharta/pull/2937)

## [1.101.1] - 2022-07-27
Expand Down
@@ -1,8 +1,10 @@
import { ApplicationInitStatus } from "@angular/core"
import { TestBed } from "@angular/core/testing"
import { Subject } from "rxjs"
import { BehaviorSubject, Subject } from "rxjs"
import { EffectsModule } from "../../angular-redux/effects/effects.module"
import { Store } from "../../angular-redux/store"
import { nodeMetricDataSelector } from "../../selectors/accumulatedData/metricData/nodeMetricData.selector"
import { areChosenMetricsAvailableSelector } from "../../selectors/allNecessaryRenderDataAvailable/areAllNecessaryRenderDataAvailable.selector"
import { setAreaMetric } from "../../store/dynamicSettings/areaMetric/areaMetric.actions"
import { setColorMetric } from "../../store/dynamicSettings/colorMetric/colorMetric.actions"
import { setDistributionMetric } from "../../store/dynamicSettings/distributionMetric/distributionMetric.actions"
Expand All @@ -11,8 +13,18 @@ import { ResetChosenMetricsEffect } from "./resetChosenMetrics.effect"

describe("resetChosenMetricsEffect", () => {
let mockedNodeMetricDataSelector = new Subject()
const mockedAreChosenMetricsAvailableSelector = new BehaviorSubject(false)
const mockedStore = {
select: () => mockedNodeMetricDataSelector,
select: (selector: unknown) => {
switch (selector) {
case nodeMetricDataSelector:
return mockedNodeMetricDataSelector
case areChosenMetricsAvailableSelector:
return mockedAreChosenMetricsAvailableSelector
default:
throw new Error("selector is not mocked")
}
},
dispatch: jest.fn()
}

Expand Down Expand Up @@ -60,4 +72,14 @@ describe("resetChosenMetricsEffect", () => {
expect(mockedStore.dispatch).toHaveBeenCalledWith(setHeightMetric("loc"))
expect(mockedStore.dispatch).toHaveBeenCalledWith(setColorMetric("loc"))
})

it("should do nothing, when chosen metrics are still available", () => {
mockedAreChosenMetricsAvailableSelector.next(true)
mockedNodeMetricDataSelector.next([
{ name: "rloc", maxValue: 9001 },
{ name: "loc", maxValue: 9001 }
])

expect(mockedStore.dispatch).not.toHaveBeenCalled()
})
})
@@ -1,5 +1,5 @@
import { Inject, Injectable } from "@angular/core"
import { filter, tap } from "rxjs"
import { filter, tap, withLatestFrom } from "rxjs"
import { defaultNMetrics, isAnyMetricAvailable, preselectCombination } from "./utils/metricHelper"
import { createEffect } from "../../angular-redux/effects/createEffect"
import { Store } from "../../angular-redux/store"
Expand All @@ -9,6 +9,7 @@ import { getDefaultDistribution } from "./utils/getDefaultDistributionMetric"
import { setAreaMetric } from "../../store/dynamicSettings/areaMetric/areaMetric.actions"
import { setHeightMetric } from "../../store/dynamicSettings/heightMetric/heightMetric.actions"
import { setColorMetric } from "../../store/dynamicSettings/colorMetric/colorMetric.actions"
import { areChosenMetricsAvailableSelector } from "../../selectors/allNecessaryRenderDataAvailable/areAllNecessaryRenderDataAvailable.selector"

@Injectable()
export class ResetChosenMetricsEffect {
Expand All @@ -18,7 +19,9 @@ export class ResetChosenMetricsEffect {
() =>
this.store.select(nodeMetricDataSelector).pipe(
filter(isAnyMetricAvailable),
tap(nodeMetricData => {
withLatestFrom(this.store.select(areChosenMetricsAvailableSelector)),
filter(([, areChosenMetricsAvailable]) => !areChosenMetricsAvailable),
tap(([nodeMetricData]) => {
this.store.dispatch(setDistributionMetric(getDefaultDistribution(nodeMetricData)))

let [defaultedAreaMetric, defaultedHeightMetric, defaultedColorMetric] = preselectCombination(nodeMetricData)
Expand Down
Expand Up @@ -57,4 +57,9 @@ describe("nodeMetricDataSelector", () => {

expect(result.filter(x => x.name === NodeMetricDataService.UNARY_METRIC).length).toBe(1)
})

it("should return empty metricData when there are no files selected. If it would contain default metrics someone might falsely assume all parsing was already done", () => {
const result = calculateNodeMetricData([], [])
expect(result.length).toBe(0)
})
})
Expand Up @@ -10,6 +10,10 @@ import { visibleFileStatesSelector } from "../../visibleFileStates.selector"
import { sortByMetricName } from "./sortByMetricName"

export const calculateNodeMetricData = (visibleFileStates: FileState[], blacklist: BlacklistItem[]) => {
if (visibleFileStates.length === 0) {
return []
}

const metricMaxValues: Map<string, number> = new Map()
const metricMinValues: Map<string, number> = new Map()

Expand Down
Expand Up @@ -11,7 +11,7 @@ import { areMetricsAvailable } from "./utils/areMetricsAvailable"

const areFileStatesAvailableSelector = createSelector([filesSelector], files => fileStatesAvailable(files))

const areChosenMetricsAvailableSelector = createSelector(
export const areChosenMetricsAvailableSelector = createSelector(
[nodeMetricDataSelector, areaMetricSelector, colorMetricSelector, heightMetricSelector],
(nodeMetricData, areaMetric, colorMetric, heightMetric) => areMetricsAvailable(nodeMetricData, [areaMetric, colorMetric, heightMetric])
)
Expand Down