From: Grégoire Aubert Date: Wed, 26 Jul 2017 10:07:07 +0000 (+0200) Subject: Move Measure component to the global components folder X-Git-Tag: 6.6-RC1~657 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cadc6bb011393ff5092f83f146bd9b74bad21460;p=sonarqube.git Move Measure component to the global components folder --- diff --git a/server/sonar-web/src/main/js/apps/code/components/ComponentMeasure.js b/server/sonar-web/src/main/js/apps/code/components/ComponentMeasure.js index 7ad6e2067c1..b0e2db4adc1 100644 --- a/server/sonar-web/src/main/js/apps/code/components/ComponentMeasure.js +++ b/server/sonar-web/src/main/js/apps/code/components/ComponentMeasure.js @@ -18,7 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import React from 'react'; -import Measure from '../../component-measures-old/components/Measure'; +import Measure from '../../../components/measure/Measure'; const ComponentMeasure = ({ component, metricKey, metricType }) => { const isProject = component.qualifier === 'TRK'; @@ -35,7 +35,9 @@ const ComponentMeasure = ({ component, metricKey, metricType }) => { return ; } - return ; + return ( + + ); }; export default ComponentMeasure; diff --git a/server/sonar-web/src/main/js/apps/overview/qualityGate/QualityGateCondition.js b/server/sonar-web/src/main/js/apps/overview/qualityGate/QualityGateCondition.js index 905f06b0d68..e00bb556764 100644 --- a/server/sonar-web/src/main/js/apps/overview/qualityGate/QualityGateCondition.js +++ b/server/sonar-web/src/main/js/apps/overview/qualityGate/QualityGateCondition.js @@ -22,26 +22,20 @@ import React from 'react'; import classNames from 'classnames'; import { Link } from 'react-router'; import { DrilldownLink } from '../../../components/shared/drilldown-link'; -import Measure from '../../component-measures-old/components/Measure'; +import Measure from '../../../components/measure/Measure'; +import IssueTypeIcon from '../../../components/ui/IssueTypeIcon'; import { getPeriodValue, isDiffMetric, formatMeasure } from '../../../helpers/measures'; import { translate } from '../../../helpers/l10n'; import { getComponentIssuesUrl } from '../../../helpers/urls'; -import IssueTypeIcon from '../../../components/ui/IssueTypeIcon'; import type { Component } from '../types'; +import type { MeasureEnhanced } from '../../../components/measure/types'; export default class QualityGateCondition extends React.PureComponent { props: { component: Component, condition: { level: string, - measure: { - metric: { - key: string, - name: string, - type: string - }, - value: string - }, + measure: MeasureEnhanced, op: string, period: number, error: string, @@ -49,10 +43,10 @@ export default class QualityGateCondition extends React.PureComponent { } }; - getDecimalsNumber(threshold: number, value: number) { + getDecimalsNumber(threshold: number, value: number): ?number { const delta = Math.abs(threshold - value); if (delta < 0.1 && delta > 0) { - //$FlowFixMe The matching result can't null because of the previous check + //$FlowFixMe The matching result can't be null because of the previous check return delta.toFixed(20).match('[^0.]').index - 1; } } @@ -130,7 +124,6 @@ export default class QualityGateCondition extends React.PureComponent { render() { const { condition } = this.props; - const { measure } = condition; const { metric } = measure; @@ -151,7 +144,7 @@ export default class QualityGateCondition extends React.PureComponent { return this.wrapWithLink(
- +
diff --git a/server/sonar-web/src/main/js/apps/overview/qualityGate/__tests__/__snapshots__/QualityGateCondition-test.js.snap b/server/sonar-web/src/main/js/apps/overview/qualityGate/__tests__/__snapshots__/QualityGateCondition-test.js.snap index f9e6d025176..cf6049b83cb 100644 --- a/server/sonar-web/src/main/js/apps/overview/qualityGate/__tests__/__snapshots__/QualityGateCondition-test.js.snap +++ b/server/sonar-web/src/main/js/apps/overview/qualityGate/__tests__/__snapshots__/QualityGateCondition-test.js.snap @@ -28,16 +28,20 @@ exports[`new_maintainability_rating 1`] = ` measure={ Object { "leak": "3", + "metric": Object { + "key": "new_maintainability_rating", + "name": "new_maintainability_rating", + "type": "RATING", + }, + "periods": Array [ + Object { + "index": 1, + "value": "3", + }, + ], "value": "3", } } - metric={ - Object { - "key": "new_maintainability_rating", - "name": "new_maintainability_rating", - "type": "RATING", - } - } />
@@ -80,16 +84,20 @@ exports[`new_open_issues 1`] = ` measure={ Object { "leak": "10", + "metric": Object { + "key": "new_open_issues", + "name": "new_open_issues", + "type": "INT", + }, + "periods": Array [ + Object { + "index": 1, + "value": "10", + }, + ], "value": "10", } } - metric={ - Object { - "key": "new_open_issues", - "name": "new_open_issues", - "type": "INT", - } - } />
@@ -143,16 +151,20 @@ exports[`new_reliability_rating 1`] = ` measure={ Object { "leak": "3", + "metric": Object { + "key": "new_reliability_rating", + "name": "new_reliability_rating", + "type": "RATING", + }, + "periods": Array [ + Object { + "index": 1, + "value": "3", + }, + ], "value": "3", } } - metric={ - Object { - "key": "new_reliability_rating", - "name": "new_reliability_rating", - "type": "RATING", - } - } />
@@ -206,16 +218,20 @@ exports[`new_security_rating 1`] = ` measure={ Object { "leak": "3", + "metric": Object { + "key": "new_security_rating", + "name": "new_security_rating", + "type": "RATING", + }, + "periods": Array [ + Object { + "index": 1, + "value": "3", + }, + ], "value": "3", } } - metric={ - Object { - "key": "new_security_rating", - "name": "new_security_rating", - "type": "RATING", - } - } />
@@ -258,16 +274,14 @@ exports[`open_issues 1`] = ` measure={ Object { "leak": "10", + "metric": Object { + "key": "open_issues", + "name": "Open open_issues", + "type": "INT", + }, "value": "10", } } - metric={ - Object { - "key": "open_issues", - "name": "Open open_issues", - "type": "INT", - } - } />
@@ -320,16 +334,14 @@ exports[`reliability_rating 1`] = ` measure={ Object { "leak": "3", + "metric": Object { + "key": "reliability_rating", + "name": "reliability_rating", + "type": "RATING", + }, "value": "3", } } - metric={ - Object { - "key": "reliability_rating", - "name": "reliability_rating", - "type": "RATING", - } - } />
@@ -382,16 +394,14 @@ exports[`security_rating 1`] = ` measure={ Object { "leak": "3", + "metric": Object { + "key": "security_rating", + "name": "security_rating", + "type": "RATING", + }, "value": "3", } } - metric={ - Object { - "key": "security_rating", - "name": "security_rating", - "type": "RATING", - } - } />
@@ -443,16 +453,14 @@ exports[`sqale_rating 1`] = ` measure={ Object { "leak": "3", + "metric": Object { + "key": "sqale_rating", + "name": "sqale_rating", + "type": "RATING", + }, "value": "3", } } - metric={ - Object { - "key": "sqale_rating", - "name": "sqale_rating", - "type": "RATING", - } - } />
diff --git a/server/sonar-web/src/main/js/apps/projects/components/ProjectCardLeakMeasures.js b/server/sonar-web/src/main/js/apps/projects/components/ProjectCardLeakMeasures.js index 4189c2e1a64..36de893963f 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/ProjectCardLeakMeasures.js +++ b/server/sonar-web/src/main/js/apps/projects/components/ProjectCardLeakMeasures.js @@ -19,7 +19,7 @@ */ //@flow import React from 'react'; -import Measure from '../../component-measures-old/components/Measure'; +import Measure from '../../../components/measure/Measure'; import BugIcon from '../../../components/icons-components/BugIcon'; import CodeSmellIcon from '../../../components/icons-components/CodeSmellIcon'; import Rating from '../../../components/ui/Rating'; @@ -42,8 +42,10 @@ export default function ProjectCardLeakMeasures({ measures }: Props) {
@@ -59,8 +61,14 @@ export default function ProjectCardLeakMeasures({ measures }: Props) {
@@ -76,8 +84,10 @@ export default function ProjectCardLeakMeasures({ measures }: Props) {
@@ -92,8 +102,10 @@ export default function ProjectCardLeakMeasures({ measures }: Props) {
@@ -106,8 +118,14 @@ export default function ProjectCardLeakMeasures({ measures }: Props) {
@@ -120,8 +138,10 @@ export default function ProjectCardLeakMeasures({ measures }: Props) {
diff --git a/server/sonar-web/src/main/js/apps/projects/components/ProjectCardOverallMeasures.js b/server/sonar-web/src/main/js/apps/projects/components/ProjectCardOverallMeasures.js index 546b511eb0e..701e707657b 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/ProjectCardOverallMeasures.js +++ b/server/sonar-web/src/main/js/apps/projects/components/ProjectCardOverallMeasures.js @@ -20,7 +20,7 @@ //@flow import React from 'react'; import ProjectCardLanguages from './ProjectCardLanguages'; -import Measure from '../../component-measures-old/components/Measure'; +import Measure from '../../../components/measure/Measure'; import Rating from '../../../components/ui/Rating'; import CoverageRating from '../../../components/ui/CoverageRating'; import DuplicationsRating from '../../../components/ui/DuplicationsRating'; @@ -79,8 +79,10 @@ export default function ProjectCardOverallMeasures({ measures }: Props) { }
@@ -97,8 +99,14 @@ export default function ProjectCardOverallMeasures({ measures }: Props) { }
@@ -115,8 +123,10 @@ export default function ProjectCardOverallMeasures({ measures }: Props) {
diff --git a/server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/ProjectCardLeakMeasures-test.js.snap b/server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/ProjectCardLeakMeasures-test.js.snap index ff9b33de649..bbce939030e 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/ProjectCardLeakMeasures-test.js.snap +++ b/server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/ProjectCardLeakMeasures-test.js.snap @@ -19,12 +19,11 @@ exports[`should render correctly with all data 1`] = ` measure={ Object { "leak": "8", - } - } - metric={ - Object { - "key": "new_bugs", - "type": "SHORT_INT", + "metric": Object { + "key": "new_bugs", + "name": "new_bugs", + "type": "SHORT_INT", + }, } } /> @@ -59,12 +58,11 @@ exports[`should render correctly with all data 1`] = ` measure={ Object { "leak": "2", - } - } - metric={ - Object { - "key": "new_vulnerabilities", - "type": "SHORT_INT", + "metric": Object { + "key": "new_vulnerabilities", + "name": "new_vulnerabilities", + "type": "SHORT_INT", + }, } } /> @@ -99,12 +97,11 @@ exports[`should render correctly with all data 1`] = ` measure={ Object { "leak": "0", - } - } - metric={ - Object { - "key": "new_code_smells", - "type": "SHORT_INT", + "metric": Object { + "key": "new_code_smells", + "name": "new_code_smells", + "type": "SHORT_INT", + }, } } /> @@ -138,12 +135,11 @@ exports[`should render correctly with all data 1`] = ` measure={ Object { "leak": "26.55", - } - } - metric={ - Object { - "key": "new_coverage", - "type": "PERCENT", + "metric": Object { + "key": "new_coverage", + "name": "new_coverage", + "type": "PERCENT", + }, } } /> @@ -169,12 +165,11 @@ exports[`should render correctly with all data 1`] = ` measure={ Object { "leak": "0.55", - } - } - metric={ - Object { - "key": "new_duplicated_lines_density", - "type": "PERCENT", + "metric": Object { + "key": "new_duplicated_lines_density", + "name": "new_duplicated_lines_density", + "type": "PERCENT", + }, } } /> @@ -200,12 +195,11 @@ exports[`should render correctly with all data 1`] = ` measure={ Object { "leak": "87", - } - } - metric={ - Object { - "key": "new_lines", - "type": "SHORT_INT", + "metric": Object { + "key": "new_lines", + "name": "new_lines", + "type": "SHORT_INT", + }, } } /> @@ -239,12 +233,11 @@ exports[`should render no data style new coverage, new duplications and new line measure={ Object { "leak": "8", - } - } - metric={ - Object { - "key": "new_bugs", - "type": "SHORT_INT", + "metric": Object { + "key": "new_bugs", + "name": "new_bugs", + "type": "SHORT_INT", + }, } } /> @@ -279,12 +272,11 @@ exports[`should render no data style new coverage, new duplications and new line measure={ Object { "leak": "2", - } - } - metric={ - Object { - "key": "new_vulnerabilities", - "type": "SHORT_INT", + "metric": Object { + "key": "new_vulnerabilities", + "name": "new_vulnerabilities", + "type": "SHORT_INT", + }, } } /> @@ -319,12 +311,11 @@ exports[`should render no data style new coverage, new duplications and new line measure={ Object { "leak": "0", - } - } - metric={ - Object { - "key": "new_code_smells", - "type": "SHORT_INT", + "metric": Object { + "key": "new_code_smells", + "name": "new_code_smells", + "type": "SHORT_INT", + }, } } /> @@ -358,12 +349,11 @@ exports[`should render no data style new coverage, new duplications and new line measure={ Object { "leak": undefined, - } - } - metric={ - Object { - "key": "new_coverage", - "type": "PERCENT", + "metric": Object { + "key": "new_coverage", + "name": "new_coverage", + "type": "PERCENT", + }, } } /> @@ -389,12 +379,11 @@ exports[`should render no data style new coverage, new duplications and new line measure={ Object { "leak": undefined, - } - } - metric={ - Object { - "key": "new_duplicated_lines_density", - "type": "PERCENT", + "metric": Object { + "key": "new_duplicated_lines_density", + "name": "new_duplicated_lines_density", + "type": "PERCENT", + }, } } /> @@ -420,12 +409,11 @@ exports[`should render no data style new coverage, new duplications and new line measure={ Object { "leak": undefined, - } - } - metric={ - Object { - "key": "new_lines", - "type": "SHORT_INT", + "metric": Object { + "key": "new_lines", + "name": "new_lines", + "type": "SHORT_INT", + }, } } /> diff --git a/server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/ProjectCardOverallMeasures-test.js.snap b/server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/ProjectCardOverallMeasures-test.js.snap index 797b56431ad..2cf247a1451 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/ProjectCardOverallMeasures-test.js.snap +++ b/server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/ProjectCardOverallMeasures-test.js.snap @@ -14,15 +14,14 @@ exports[`should not render coverage 1`] = `
; + + if (tooltip) { + return ( + + + {rating} + + + ); + } + + return rating; + } + + render() { + const { className, decimals, measure } = this.props; + const metric = measure.metric; + + if (metric.type === 'RATING') { + return this.renderRating(); + } + + if (metric.type === 'LEVEL') { + return ; + } + + const formattedValue = isDiffMetric(metric.key) + ? formatLeak(measure.leak, metric, { decimals }) + : formatMeasure(measure.value, metric.type, { decimals }); + return ( + + {formattedValue != null ? formattedValue : '–'} + + ); + } +} diff --git a/server/sonar-web/src/main/js/components/measure/types.js b/server/sonar-web/src/main/js/components/measure/types.js new file mode 100644 index 00000000000..1883833c97a --- /dev/null +++ b/server/sonar-web/src/main/js/components/measure/types.js @@ -0,0 +1,33 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +// @flow +import type { Metric } from '../../store/metrics/actions'; + +type MeasureIntern = { + value?: string, + periods?: Array<{ + index: number, + value: string + }> +}; + +export type Measure = MeasureIntern & { metric: string }; + +export type MeasureEnhanced = MeasureIntern & { metric: Metric, leak?: ?string }; diff --git a/server/sonar-web/src/main/js/components/measure/utils.js b/server/sonar-web/src/main/js/components/measure/utils.js new file mode 100644 index 00000000000..bf98a58ee7b --- /dev/null +++ b/server/sonar-web/src/main/js/components/measure/utils.js @@ -0,0 +1,45 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +// @flow +import { + formatMeasure, + formatMeasureVariation, + getRatingTooltip as nextGetRatingTooltip, + isDiffMetric +} from '../../helpers/measures'; +import type { Metric } from '../../store/metrics/actions'; + +const KNOWN_RATINGS = ['sqale_rating', 'reliability_rating', 'security_rating']; + +export function formatLeak(value: ?string, metric: Metric, options: Object) { + if (isDiffMetric(metric.key)) { + return formatMeasure(value, metric.type, options); + } else { + return formatMeasureVariation(value, metric.type, options); + } +} + +export function getRatingTooltip(metricKey: string, value: ?string) { + const finalMetricKey = isDiffMetric(metricKey) ? metricKey.substr(4) : metricKey; + if (KNOWN_RATINGS.includes(finalMetricKey)) { + return nextGetRatingTooltip(finalMetricKey, value); + } + return null; +}