* 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';
return <span />;
}
- return <Measure measure={measure} metric={{ key: finalMetricKey, type: finalMetricType }} />;
+ return (
+ <Measure measure={{ ...measure, metric: { key: finalMetricKey, type: finalMetricType } }} />
+ );
};
export default ComponentMeasure;
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,
}
};
- 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;
}
}
render() {
const { condition } = this.props;
-
const { measure } = condition;
const { metric } = measure;
return this.wrapWithLink(
<div className="overview-quality-gate-condition-container">
<div className="overview-quality-gate-condition-value">
- <Measure measure={{ value: actual, leak: actual }} metric={metric} decimals={decimals} />
+ <Measure measure={{ ...measure, value: actual, leak: actual }} decimals={decimals} />
</div>
<div>
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",
- }
- }
/>
</div>
<div>
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",
- }
- }
/>
</div>
<div>
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",
- }
- }
/>
</div>
<div>
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",
- }
- }
/>
</div>
<div>
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",
- }
- }
/>
</div>
<div>
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",
- }
- }
/>
</div>
<div>
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",
- }
- }
/>
</div>
<div>
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",
- }
- }
/>
</div>
<div>
*/
//@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';
<div className="project-card-measure-number">
<Measure
className="spacer-right"
- measure={{ leak: measures['new_bugs'] }}
- metric={{ key: 'new_bugs', type: 'SHORT_INT' }}
+ measure={{
+ metric: { key: 'new_bugs', name: 'new_bugs', type: 'SHORT_INT' },
+ leak: measures['new_bugs']
+ }}
/>
<Rating value={measures['new_reliability_rating']} />
</div>
<div className="project-card-measure-number">
<Measure
className="spacer-right"
- measure={{ leak: measures['new_vulnerabilities'] }}
- metric={{ key: 'new_vulnerabilities', type: 'SHORT_INT' }}
+ measure={{
+ metric: {
+ key: 'new_vulnerabilities',
+ name: 'new_vulnerabilities',
+ type: 'SHORT_INT'
+ },
+ leak: measures['new_vulnerabilities']
+ }}
/>
<Rating value={measures['new_security_rating']} />
</div>
<div className="project-card-measure-number">
<Measure
className="spacer-right"
- measure={{ leak: measures['new_code_smells'] }}
- metric={{ key: 'new_code_smells', type: 'SHORT_INT' }}
+ measure={{
+ metric: { key: 'new_code_smells', name: 'new_code_smells', type: 'SHORT_INT' },
+ leak: measures['new_code_smells']
+ }}
/>
<Rating value={measures['new_maintainability_rating']} />
</div>
<div className="project-card-measure-inner">
<div className="project-card-measure-number">
<Measure
- measure={{ leak: measures['new_coverage'] }}
- metric={{ key: 'new_coverage', type: 'PERCENT' }}
+ measure={{
+ metric: { key: 'new_coverage', name: 'new_coverage', type: 'PERCENT' },
+ leak: measures['new_coverage']
+ }}
/>
</div>
<div className="project-card-measure-label">
<div className="project-card-measure-inner">
<div className="project-card-measure-number">
<Measure
- measure={{ leak: measures['new_duplicated_lines_density'] }}
- metric={{ key: 'new_duplicated_lines_density', type: 'PERCENT' }}
+ measure={{
+ metric: {
+ key: 'new_duplicated_lines_density',
+ name: 'new_duplicated_lines_density',
+ type: 'PERCENT'
+ },
+ leak: measures['new_duplicated_lines_density']
+ }}
/>
</div>
<div className="project-card-measure-label">
<div className="project-card-measure-inner">
<div className="project-card-measure-number">
<Measure
- measure={{ leak: measures['new_lines'] }}
- metric={{ key: 'new_lines', type: 'SHORT_INT' }}
+ measure={{
+ metric: { key: 'new_lines', name: 'new_lines', type: 'SHORT_INT' },
+ leak: measures['new_lines']
+ }}
/>
</div>
<div className="project-card-measure-label">
//@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';
<CoverageRating value={measures['coverage']} />
</span>}
<Measure
- measure={{ value: measures['coverage'] }}
- metric={{ key: 'coverage', type: 'PERCENT' }}
+ measure={{
+ metric: { key: 'coverage', name: 'coverage', type: 'PERCENT' },
+ value: measures['coverage']
+ }}
/>
</div>
<div className="project-card-measure-label">
<DuplicationsRating value={Number(measures['duplicated_lines_density'])} />
</span>}
<Measure
- measure={{ value: measures['duplicated_lines_density'] }}
- metric={{ key: 'duplicated_lines_density', type: 'PERCENT' }}
+ measure={{
+ metric: {
+ key: 'duplicated_lines_density',
+ name: 'duplicated_lines_density',
+ type: 'PERCENT'
+ },
+ value: measures['duplicated_lines_density']
+ }}
/>
</div>
<div className="project-card-measure-label">
<SizeRating value={Number(measures['ncloc'])} />
</span>
<Measure
- measure={{ value: measures['ncloc'] }}
- metric={{ key: 'ncloc', type: 'SHORT_INT' }}
+ measure={{
+ metric: { key: 'ncloc', name: 'ncloc', type: 'SHORT_INT' },
+ value: measures['ncloc']
+ }}
/>
</div>
<div className="project-card-measure-label">
measure={
Object {
"leak": "8",
- }
- }
- metric={
- Object {
- "key": "new_bugs",
- "type": "SHORT_INT",
+ "metric": Object {
+ "key": "new_bugs",
+ "name": "new_bugs",
+ "type": "SHORT_INT",
+ },
}
}
/>
measure={
Object {
"leak": "2",
- }
- }
- metric={
- Object {
- "key": "new_vulnerabilities",
- "type": "SHORT_INT",
+ "metric": Object {
+ "key": "new_vulnerabilities",
+ "name": "new_vulnerabilities",
+ "type": "SHORT_INT",
+ },
}
}
/>
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",
+ },
}
}
/>
measure={
Object {
"leak": "26.55",
- }
- }
- metric={
- Object {
- "key": "new_coverage",
- "type": "PERCENT",
+ "metric": Object {
+ "key": "new_coverage",
+ "name": "new_coverage",
+ "type": "PERCENT",
+ },
}
}
/>
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",
+ },
}
}
/>
measure={
Object {
"leak": "87",
- }
- }
- metric={
- Object {
- "key": "new_lines",
- "type": "SHORT_INT",
+ "metric": Object {
+ "key": "new_lines",
+ "name": "new_lines",
+ "type": "SHORT_INT",
+ },
}
}
/>
measure={
Object {
"leak": "8",
- }
- }
- metric={
- Object {
- "key": "new_bugs",
- "type": "SHORT_INT",
+ "metric": Object {
+ "key": "new_bugs",
+ "name": "new_bugs",
+ "type": "SHORT_INT",
+ },
}
}
/>
measure={
Object {
"leak": "2",
- }
- }
- metric={
- Object {
- "key": "new_vulnerabilities",
- "type": "SHORT_INT",
+ "metric": Object {
+ "key": "new_vulnerabilities",
+ "name": "new_vulnerabilities",
+ "type": "SHORT_INT",
+ },
}
}
/>
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",
+ },
}
}
/>
measure={
Object {
"leak": undefined,
- }
- }
- metric={
- Object {
- "key": "new_coverage",
- "type": "PERCENT",
+ "metric": Object {
+ "key": "new_coverage",
+ "name": "new_coverage",
+ "type": "PERCENT",
+ },
}
}
/>
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",
+ },
}
}
/>
measure={
Object {
"leak": undefined,
- }
- }
- metric={
- Object {
- "key": "new_lines",
- "type": "SHORT_INT",
+ "metric": Object {
+ "key": "new_lines",
+ "name": "new_lines",
+ "type": "SHORT_INT",
+ },
}
}
/>
<Measure
measure={
Object {
+ "metric": Object {
+ "key": "coverage",
+ "name": "coverage",
+ "type": "PERCENT",
+ },
"value": undefined,
}
}
- metric={
- Object {
- "key": "coverage",
- "type": "PERCENT",
- }
- }
/>
</div>
<div
<Measure
measure={
Object {
+ "metric": Object {
+ "key": "duplicated_lines_density",
+ "name": "duplicated_lines_density",
+ "type": "PERCENT",
+ },
"value": undefined,
}
}
- metric={
- Object {
- "key": "duplicated_lines_density",
- "type": "PERCENT",
- }
- }
/>
</div>
<div
<Measure
measure={
Object {
+ "metric": Object {
+ "key": "coverage",
+ "name": "coverage",
+ "type": "PERCENT",
+ },
"value": "88.3",
}
}
- metric={
- Object {
- "key": "coverage",
- "type": "PERCENT",
- }
- }
/>
</div>
<div
<Measure
measure={
Object {
+ "metric": Object {
+ "key": "duplicated_lines_density",
+ "name": "duplicated_lines_density",
+ "type": "PERCENT",
+ },
"value": "9.8",
}
}
- metric={
- Object {
- "key": "duplicated_lines_density",
- "type": "PERCENT",
- }
- }
/>
</div>
<div
<Measure
measure={
Object {
+ "metric": Object {
+ "key": "ncloc",
+ "name": "ncloc",
+ "type": "SHORT_INT",
+ },
"value": "2053",
}
}
- metric={
- Object {
- "key": "ncloc",
- "type": "SHORT_INT",
- }
- }
/>
</div>
<div
<Measure
measure={
Object {
+ "metric": Object {
+ "key": "ncloc",
+ "name": "ncloc",
+ "type": "SHORT_INT",
+ },
"value": "16549887",
}
}
- metric={
- Object {
- "key": "ncloc",
- "type": "SHORT_INT",
- }
- }
/>
</div>
<div
--- /dev/null
+/*
+ * 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 React from 'react';
+import Rating from '../ui/Rating';
+import Level from '../ui/Level';
+import Tooltips from '../controls/Tooltip';
+import { formatMeasure, isDiffMetric } from '../../helpers/measures';
+import { formatLeak, getRatingTooltip } from './utils';
+import type { MeasureEnhanced } from './types';
+
+type Props = {
+ className?: string,
+ measure: MeasureEnhanced,
+ decimals?: ?number
+};
+
+export default class Measure extends React.PureComponent {
+ props: Props;
+
+ renderRating() {
+ const { measure } = this.props;
+ const metric = measure.metric;
+ const value = isDiffMetric(metric.key) ? measure.leak : measure.value;
+ const tooltip = getRatingTooltip(metric.key, value);
+ const rating = <Rating value={value} />;
+
+ if (tooltip) {
+ return (
+ <Tooltips overlay={tooltip}>
+ <span className={this.props.className}>
+ {rating}
+ </span>
+ </Tooltips>
+ );
+ }
+
+ 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 <Level className={className} level={measure.value} />;
+ }
+
+ const formattedValue = isDiffMetric(metric.key)
+ ? formatLeak(measure.leak, metric, { decimals })
+ : formatMeasure(measure.value, metric.type, { decimals });
+ return (
+ <span className={className}>
+ {formattedValue != null ? formattedValue : '–'}
+ </span>
+ );
+ }
+}
--- /dev/null
+/*
+ * 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 };
--- /dev/null
+/*
+ * 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;
+}