From 7562d01e1fd1b72a70fd3c392145a1dbebb28155 Mon Sep 17 00:00:00 2001 From: Mathieu Suen Date: Thu, 20 Aug 2020 09:54:10 +0200 Subject: [PATCH] SONAR-13569 Fix missleading message when referencing same branch for new code. --- .../apps/overview/branches/BranchOverview.tsx | 35 +++--- .../branches/BranchOverviewRenderer.tsx | 12 +- .../apps/overview/branches/MeasuresPanel.tsx | 22 ++-- .../branches/MeasuresPanelNoNewCode.tsx | 28 +++-- .../__tests__/BranchOverview-test.tsx | 4 +- .../__tests__/BranchOverviewRenderer-test.tsx | 2 +- .../branches/__tests__/MeasuresPanel-test.tsx | 4 +- .../__tests__/MeasuresPanelNoNewCode-test.tsx | 12 +- .../BranchOverview-test.tsx.snap | 6 +- .../BranchOverviewRenderer-test.tsx.snap | 4 +- .../__snapshots__/MeasuresPanel-test.tsx.snap | 6 +- .../MeasuresPanelNoNewCode-test.tsx.snap | 119 +++++++++++++++--- .../main/js/apps/overview/components/App.tsx | 2 +- .../src/main/js/helpers/branch-like.ts | 12 -- .../resources/org/sonar/l10n/core.properties | 3 +- 15 files changed, 180 insertions(+), 91 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/overview/branches/BranchOverview.tsx b/server/sonar-web/src/main/js/apps/overview/branches/BranchOverview.tsx index 80a41ecc993..e1af67b481c 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/BranchOverview.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/BranchOverview.tsx @@ -43,7 +43,7 @@ import { extractStatusConditionsFromProjectStatus } from '../../../helpers/qualityGates'; import { ApplicationPeriod } from '../../../types/application'; -import { BranchLike } from '../../../types/branch-like'; +import { Branch, BranchLike } from '../../../types/branch-like'; import { ComponentQualifier } from '../../../types/component'; import { MetricKey } from '../../../types/metrics'; import { GraphType, MeasureHistory } from '../../../types/project-activity'; @@ -53,7 +53,7 @@ import { HISTORY_METRICS_LIST, METRICS } from '../utils'; import BranchOverviewRenderer from './BranchOverviewRenderer'; interface Props { - branchLike?: BranchLike; + branch?: Branch; component: T.Component; } @@ -95,7 +95,7 @@ export default class BranchOverview extends React.PureComponent { componentDidUpdate(prevProps: Props) { if ( this.props.component.key !== prevProps.component.key || - !isSameBranchLike(this.props.branchLike, prevProps.branchLike) + !isSameBranchLike(this.props.branch, prevProps.branch) ) { this.loadStatus(); this.loadHistory(); @@ -115,22 +115,21 @@ export default class BranchOverview extends React.PureComponent { }; loadApplicationStatus = async () => { - const { branchLike, component } = this.props; + const { branch, component } = this.props; this.setState({ loadingStatus: true }); // Start by loading the application quality gate info, as well as the meta // data for the application as a whole. const appStatus = await getApplicationQualityGate({ application: component.key, - ...getBranchLikeQuery(branchLike) + ...getBranchLikeQuery(branch) }); const { measures: appMeasures, metrics, period } = await this.loadMeasuresAndMeta( component.key, - branchLike + branch ); const appBranchName = - (branchLike && !isMainBranch(branchLike) && getBranchLikeDisplayName(branchLike)) || - undefined; + (branch && !isMainBranch(branch) && getBranchLikeDisplayName(branch)) || undefined; const appDetails = await getApplicationDetails(component.key, appBranchName); @@ -212,14 +211,14 @@ export default class BranchOverview extends React.PureComponent { loadProjectStatus = async () => { const { - branchLike, + branch, component: { key, name } } = this.props; this.setState({ loadingStatus: true }); const projectStatus = await getQualityGateProjectStatus({ projectKey: key, - ...getBranchLikeQuery(branchLike) + ...getBranchLikeQuery(branch) }); // Get failing condition metric keys. We need measures for them as well to @@ -229,7 +228,7 @@ export default class BranchOverview extends React.PureComponent { ? uniq([...METRICS, ...projectStatus.conditions.map(c => c.metricKey)]) : METRICS; - this.loadMeasuresAndMeta(key, branchLike, metricKeys).then( + this.loadMeasuresAndMeta(key, branch, metricKeys).then( ({ measures, metrics, period }) => { if (this.mounted && measures) { const { ignoredConditions, status } = projectStatus; @@ -242,7 +241,7 @@ export default class BranchOverview extends React.PureComponent { key, name, status, - branchLike + branchLike: branch }; this.setState({ @@ -292,14 +291,14 @@ export default class BranchOverview extends React.PureComponent { }; loadHistoryMeasures = () => { - const { branchLike, component } = this.props; + const { branch, component } = this.props; const { graph } = this.state; const graphMetrics = getHistoryMetrics(graph, []); const metrics = uniq([...HISTORY_METRICS_LIST, ...graphMetrics]); return getAllTimeMachineData({ - ...getBranchLikeQuery(branchLike), + ...getBranchLikeQuery(branch), from: FROM_DATE, component: component.key, metrics: metrics.join() @@ -322,10 +321,10 @@ export default class BranchOverview extends React.PureComponent { }; loadAnalyses = () => { - const { branchLike } = this.props; + const { branch } = this.props; return getProjectActivity({ - ...getBranchLikeQuery(branchLike), + ...getBranchLikeQuery(branch), project: this.getTopLevelComponent(), from: FROM_DATE }).then( @@ -389,7 +388,7 @@ export default class BranchOverview extends React.PureComponent { }; render() { - const { branchLike, component } = this.props; + const { branch, component } = this.props; const { analyses, appLeak, @@ -414,7 +413,7 @@ export default class BranchOverview extends React.PureComponent { {projectIsEmpty ? ( - + ) : (
@@ -88,7 +88,7 @@ export function BranchOverviewRenderer(props: BranchOverviewRendererProps) {
isDiffMetric(m.metric.key)); const isApp = component.qualifier === ComponentQualifier.Application; @@ -107,11 +107,7 @@ export function MeasuresPanel(props: MeasuresPanelProps) {
{!hasDiffMeasures && isNewCodeTab ? ( - + ) : ( <> {[ @@ -121,7 +117,7 @@ export function MeasuresPanel(props: MeasuresPanelProps) { IssueType.CodeSmell ].map((type: IssueType) => (
-

- {hasBadNewCodeSetting - ? translate('overview.measures.bad_setting.explanation') - : translate('overview.measures.empty_explanation')} -

- {hasBadNewCodeSetting ? ( +

{translate(badExplanationKey)}

+ {hasBadNewCodeSettingSameRef ? ( showSettingsLink && (

{translate('settings.new_code_period.category')} diff --git a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-test.tsx b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-test.tsx index 8981816952b..1e2ae85b21b 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-test.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-test.tsx @@ -254,7 +254,7 @@ describe('application overview', () => { }); it('should fetch correctly other branch', async () => { - const wrapper = shallowRender({ branchLike: mockBranch(), component }); + const wrapper = shallowRender({ branch: mockBranch(), component }); await waitAndUpdate(wrapper); expect(getApplicationDetails).toHaveBeenCalled(); expect(wrapper).toMatchSnapshot(); @@ -358,7 +358,7 @@ it('should correctly handle graph type storage', () => { function shallowRender(props: Partial = {}) { return shallow( { function shallowRender(props: Partial = {}) { return shallow( { it('should render correctly if branch is misconfigured', () => { const wrapper = shallowRender({ - branchLike: mockBranch({ name: 'own-reference' }), + branch: mockBranch({ name: 'own-reference' }), measures: [ mockMeasureEnhanced({ metric: mockMetric({ key: MetricKey.coverage }) }), mockMeasureEnhanced({ metric: mockMetric({ key: MetricKey.bugs }) }) @@ -92,7 +92,7 @@ it('should render correctly if the data is still loading', () => { function shallowRender(props: Partial = {}) { return shallow( { expect( shallowRender({ period: mockPeriod({ date: '2018-05-23', mode: 'PREVIOUS_VERSION' }) }) ).toMatchInlineSnapshot(defaultMessage); + expect( + shallowRender({ + period: mockPeriod({ date: undefined, mode: 'REFERENCE_BRANCH', parameter: 'master' }) + }) + ).toMatchSnapshot(); + expect( + shallowRender({ + period: mockPeriod({ date: undefined, mode: 'REFERENCE_BRANCH', parameter: 'notsame' }) + }) + ).toMatchSnapshot(); }); it('should render "bad code setting" explanation', () => { @@ -96,6 +106,6 @@ it('should render "bad code setting" explanation', () => { function shallowRender(props: Partial = {}) { return shallow( - + ); } diff --git a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/__snapshots__/BranchOverview-test.tsx.snap b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/__snapshots__/BranchOverview-test.tsx.snap index 65a67fdbc66..4b54bcd6e45 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/__snapshots__/BranchOverview-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/__snapshots__/BranchOverview-test.tsx.snap @@ -43,7 +43,7 @@ exports[`application overview should fetch correctly other branch 1`] = ` "projectName": "Foo", } } - branchLike={ + branch={ Object { "analysisDate": "2018-01-01", "excludedFromPurge": true, @@ -965,7 +965,7 @@ exports[`application overview should render correctly 1`] = ` "projectName": "Foo", } } - branchLike={ + branch={ Object { "analysisDate": "2018-01-01", "excludedFromPurge": true, @@ -1880,7 +1880,7 @@ exports[`project overview should render correctly 1`] = ` }, ] } - branchLike={ + branch={ Object { "analysisDate": "2018-01-01", "excludedFromPurge": true, diff --git a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/__snapshots__/BranchOverviewRenderer-test.tsx.snap b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/__snapshots__/BranchOverviewRenderer-test.tsx.snap index 9caecddb2bd..2c47e891d63 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/__snapshots__/BranchOverviewRenderer-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/__snapshots__/BranchOverviewRenderer-test.tsx.snap @@ -50,7 +50,7 @@ exports[`should render correctly 1`] = ` className="display-flex-column" > - overview.measures.bad_setting.explanation + overview.measures.bad_reference.explanation +

+

+ + learn_more + , + } + } + />

@@ -58,27 +75,101 @@ exports[`should render "bad code setting" explanation: with link 1`] = `

- overview.measures.bad_setting.explanation + overview.measures.bad_reference.explanation +

+

+ + learn_more + , + } + } + /> +

+
+
+`; + +exports[`should render the default message 5`] = ` +
+ +
+

+ overview.measures.same_reference.explanation +

+
+
+`; + +exports[`should render the default message 6`] = ` +
+ +
+

+ overview.measures.bad_reference.explanation

- settings.new_code_period.category + learn_more , } } diff --git a/server/sonar-web/src/main/js/apps/overview/components/App.tsx b/server/sonar-web/src/main/js/apps/overview/components/App.tsx index 93eb9ca5a2f..214719012d3 100644 --- a/server/sonar-web/src/main/js/apps/overview/components/App.tsx +++ b/server/sonar-web/src/main/js/apps/overview/components/App.tsx @@ -67,7 +67,7 @@ export class App extends React.PureComponent { hasAnalyses={this.props.isPending || this.props.isInProgress} /> ) : ( - + )} ); diff --git a/server/sonar-web/src/main/js/helpers/branch-like.ts b/server/sonar-web/src/main/js/helpers/branch-like.ts index 356c704c262..14243c1317a 100644 --- a/server/sonar-web/src/main/js/helpers/branch-like.ts +++ b/server/sonar-web/src/main/js/helpers/branch-like.ts @@ -59,18 +59,6 @@ export function getBranchLikeKey(branchLike: BranchLike) { return isPullRequest(branchLike) ? `pull-request-${branchLike.key}` : `branch-${branchLike.name}`; } -export function getBranchQualityGateColor(status: string) { - let indicatorColor = 'gray'; - if (status === 'ERROR') { - indicatorColor = 'red'; - } else if (status === 'WARN') { - indicatorColor = 'orange'; - } else if (status === 'OK') { - indicatorColor = 'green'; - } - return indicatorColor; -} - export function isSameBranchLike(a: BranchLike | undefined, b: BranchLike | undefined) { // main branches are always equal if (isMainBranch(a) && isMainBranch(b)) { diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 5a27708fa38..c7842a6f40d 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -2768,7 +2768,8 @@ overview.recent_activity=Recent Activity overview.measures=Measures overview.measures.empty_explanation=Measures on New Code will appear after the second analysis of this branch. overview.measures.empty_link={learn_more_link} about the Clean as You Code approach. -overview.measures.bad_setting.explanation=This branch is configured to use itself as reference branch. It will never have New Code. +overview.measures.same_reference.explanation=This branch is configured to use itself as reference branch. It will never have New Code. +overview.measures.bad_reference.explanation=This branch could not be compared to its reference branch. See the SCM or analysis report for more details. overview.measures.bad_setting.link=This can be fixed in the {setting_link} setting. overview.measures.security_hotspots_reviewed=Reviewed -- 2.39.5