From 41c087b7e17d18b72d01e948c89b0256475e505a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gr=C3=A9goire=20Aubert?= Date: Fri, 7 Jul 2017 12:36:18 +0200 Subject: [PATCH] SONAR-9403 Replace the measures history graph by a link to the project activity page --- .../component-measures/components/Measure.js | 8 +++--- .../details/MeasureDetails.js | 3 ++- .../details/MeasureDetailsHeader.js | 26 +++++++++++++++---- .../details/drilldown/Breadcrumb.js | 6 ++--- .../details/drilldown/MeasureDrilldown.js | 16 +----------- .../home/MeasureListValue.js | 4 +-- .../main/js/apps/component-measures/hooks.js | 4 +-- .../js/apps/component-measures/styles.css | 4 +-- .../main/js/apps/component-measures/utils.js | 13 +++------- .../icons-components/HistoryIcon.js} | 21 +++++++++------ server/sonar-web/src/main/js/helpers/urls.js | 13 ++++++++++ 11 files changed, 66 insertions(+), 52 deletions(-) rename server/sonar-web/src/main/js/{apps/component-measures/components/IconHistory.js => components/icons-components/HistoryIcon.js} (62%) diff --git a/server/sonar-web/src/main/js/apps/component-measures/components/Measure.js b/server/sonar-web/src/main/js/apps/component-measures/components/Measure.js index 3b3672ed4f1..aa81154e99f 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/components/Measure.js +++ b/server/sonar-web/src/main/js/apps/component-measures/components/Measure.js @@ -20,9 +20,9 @@ import React from 'react'; import Rating from '../../../components/ui/Rating'; import Level from '../../../components/ui/Level'; -import { formatMeasure } from '../../../helpers/measures'; +import { formatMeasure, isDiffMetric } from '../../../helpers/measures'; import { TooltipsContainer } from '../../../components/mixins/tooltips-mixin'; -import { formatLeak, isDiffMetric, getRatingTooltip } from '../utils'; +import { formatLeak, getRatingTooltip } from '../utils'; export default class Measure extends React.PureComponent { static propTypes = { @@ -33,7 +33,7 @@ export default class Measure extends React.PureComponent { }; renderRating(measure, metric) { - const value = isDiffMetric(metric) ? measure.leak : measure.value; + const value = isDiffMetric(metric.key) ? measure.leak : measure.value; const tooltip = getRatingTooltip(metric.key, value); const rating = ; @@ -64,7 +64,7 @@ export default class Measure extends React.PureComponent { return ; } - const formattedValue = isDiffMetric(finalMetric) + const formattedValue = isDiffMetric(finalMetric.key) ? formatLeak(measure.leak, finalMetric, { decimals }) : formatMeasure(measure.value, finalMetric.type, { decimals }); return ( diff --git a/server/sonar-web/src/main/js/apps/component-measures/details/MeasureDetails.js b/server/sonar-web/src/main/js/apps/component-measures/details/MeasureDetails.js index 0c6f0cfd625..ab1c9386456 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/details/MeasureDetails.js +++ b/server/sonar-web/src/main/js/apps/component-measures/details/MeasureDetails.js @@ -110,10 +110,11 @@ export default class MeasureDetails extends React.PureComponent { {measure && diff --git a/server/sonar-web/src/main/js/apps/component-measures/details/MeasureDetailsHeader.js b/server/sonar-web/src/main/js/apps/component-measures/details/MeasureDetailsHeader.js index d3cdb27ff1a..adaada9f517 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/details/MeasureDetailsHeader.js +++ b/server/sonar-web/src/main/js/apps/component-measures/details/MeasureDetailsHeader.js @@ -18,24 +18,40 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import React from 'react'; +import { Link } from 'react-router'; import Measure from './../components/Measure'; import LanguageDistribution from '../../../components/charts/LanguageDistribution'; import LeakPeriodLegend from '../components/LeakPeriodLegend'; +import IssueTypeIcon from '../../../components/ui/IssueTypeIcon'; +import HistoryIcon from '../../../components/icons-components/HistoryIcon'; import { ComplexityDistribution } from '../../../components/shared/complexity-distribution'; -import { isDiffMetric } from '../utils'; +import { isDiffMetric } from '../../../helpers/measures'; import { TooltipsContainer } from '../../../components/mixins/tooltips-mixin'; +import { getComponentMeasureHistory } from '../../../helpers/urls'; import { getLocalizedMetricName } from '../../../helpers/l10n'; -import IssueTypeIcon from '../../../components/ui/IssueTypeIcon'; -export default function MeasureDetailsHeader({ measure, metric, secondaryMeasure, leakPeriod }) { +export default function MeasureDetailsHeader({ + component, + measure, + metric, + secondaryMeasure, + leakPeriod +}) { + const isDiff = isDiffMetric(metric.key); return (

{getLocalizedMetricName(metric)} + {!isDiff && + + + }

- {isDiffMetric(metric) && + {isDiff &&
} @@ -43,7 +59,7 @@ export default function MeasureDetailsHeader({ measure, metric, secondaryMeasure
- {isDiffMetric(metric) + {isDiff ?
diff --git a/server/sonar-web/src/main/js/apps/component-measures/details/drilldown/Breadcrumb.js b/server/sonar-web/src/main/js/apps/component-measures/details/drilldown/Breadcrumb.js index 5261badeaf2..15ac0ded735 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/details/drilldown/Breadcrumb.js +++ b/server/sonar-web/src/main/js/apps/component-measures/details/drilldown/Breadcrumb.js @@ -19,8 +19,8 @@ */ import React from 'react'; import QualifierIcon from '../../../../components/shared/QualifierIcon'; -import { isDiffMetric, formatLeak } from '../../utils'; -import { formatMeasure } from '../../../../helpers/measures'; +import { formatLeak } from '../../utils'; +import { formatMeasure, isDiffMetric } from '../../../../helpers/measures'; const Breadcrumb = ({ component, metric, onBrowse }) => { const handleClick = e => { @@ -40,7 +40,7 @@ const Breadcrumb = ({ component, metric, onBrowse }) => { inner = {component.name}; } - const value = isDiffMetric(metric) + const value = isDiffMetric(metric.key) ? formatLeak(component.leak, metric) : formatMeasure(component.value, metric.type); diff --git a/server/sonar-web/src/main/js/apps/component-measures/details/drilldown/MeasureDrilldown.js b/server/sonar-web/src/main/js/apps/component-measures/details/drilldown/MeasureDrilldown.js index fdde4ab81bf..f54768defb7 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/details/drilldown/MeasureDrilldown.js +++ b/server/sonar-web/src/main/js/apps/component-measures/details/drilldown/MeasureDrilldown.js @@ -23,8 +23,7 @@ import IconList from './../../components/IconList'; import IconTree from './../../components/IconTree'; import IconBubbles from './../../components/IconBubbles'; import IconTreemap from './../../components/IconTreemap'; -import IconHistory from './../../components/IconHistory'; -import { hasHistory, hasBubbleChart, hasTreemap } from '../../utils'; +import { hasBubbleChart, hasTreemap } from '../../utils'; import { translate } from '../../../../helpers/l10n'; export default function MeasureDrilldown(props) { @@ -85,19 +84,6 @@ export default function MeasureDrilldown(props) { {translate('component_measures.tab.treemap')} } - - {hasHistory(metric.key) && -
  • - - - {translate('component_measures.tab.history')} - -
  • } {child} diff --git a/server/sonar-web/src/main/js/apps/component-measures/home/MeasureListValue.js b/server/sonar-web/src/main/js/apps/component-measures/home/MeasureListValue.js index 165980283b1..da121fc6995 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/home/MeasureListValue.js +++ b/server/sonar-web/src/main/js/apps/component-measures/home/MeasureListValue.js @@ -19,12 +19,12 @@ */ import React from 'react'; import Measure from '../components/Measure'; -import { isDiffMetric } from '../utils'; +import { isDiffMetric } from '../../../helpers/measures'; const MeasureListValue = ({ measure }) => { const { metric } = measure; - if (isDiffMetric(metric)) { + if (isDiffMetric(metric.key)) { return (
    a { +.measure-details-metric > a:not(.button) { border: none; color: #444; } -.measure-details-metric > a:hover { +.measure-details-metric > a:not(.button):hover { color: #236a97; } diff --git a/server/sonar-web/src/main/js/apps/component-measures/utils.js b/server/sonar-web/src/main/js/apps/component-measures/utils.js index 91c3e3f92b2..20595c7ab18 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/utils.js +++ b/server/sonar-web/src/main/js/apps/component-measures/utils.js @@ -21,13 +21,10 @@ import bubbles from './config/bubbles'; import { formatMeasure, formatMeasureVariation, - getRatingTooltip as nextGetRatingTooltip + getRatingTooltip as nextGetRatingTooltip, + isDiffMetric } from '../../helpers/measures'; -export function isDiffMetric(metric) { - return metric.key.indexOf('new_') === 0; -} - export function getLeakValue(measure, periodIndex = 1) { if (!measure) { return null; @@ -63,7 +60,7 @@ export function getSingleLeakValue(measures, periodIndex = 1) { } export function formatLeak(value, metric, options) { - if (isDiffMetric(metric)) { + if (isDiffMetric(metric.key)) { return formatMeasure(value, metric.type, options); } else { return formatMeasureVariation(value, metric.type, options); @@ -102,10 +99,6 @@ export function enhanceWithMeasure(components, metric, periodIndex = 1) { }); } -export function hasHistory(metricKey) { - return metricKey.indexOf('new_') !== 0; -} - export function hasBubbleChart(domainName) { return !!bubbles[domainName]; } diff --git a/server/sonar-web/src/main/js/apps/component-measures/components/IconHistory.js b/server/sonar-web/src/main/js/components/icons-components/HistoryIcon.js similarity index 62% rename from server/sonar-web/src/main/js/apps/component-measures/components/IconHistory.js rename to server/sonar-web/src/main/js/components/icons-components/HistoryIcon.js index 19db8dc375d..7fed99c67bc 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/components/IconHistory.js +++ b/server/sonar-web/src/main/js/components/icons-components/HistoryIcon.js @@ -17,19 +17,24 @@ * 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'; -export default function IconHistory() { +type Props = { className?: string, size?: number }; + +export default function IconHistory({ className, size = 16 }: Props) { /* eslint max-len: 0 */ return ( - + className={className} + xmlns="http://www.w3.org/2000/svg" + viewBox="0 0 16 16" + width={size} + height={size}> + ); } diff --git a/server/sonar-web/src/main/js/helpers/urls.js b/server/sonar-web/src/main/js/helpers/urls.js index 7f512e298c8..07103e12255 100644 --- a/server/sonar-web/src/main/js/helpers/urls.js +++ b/server/sonar-web/src/main/js/helpers/urls.js @@ -68,6 +68,19 @@ export function getComponentDrilldownUrl(componentKey, metric) { }; } +/** + * Generate URL for a component's measure history + * @param {string} componentKey + * @param {string} metric + * @returns {Object} + */ +export function getComponentMeasureHistory(componentKey, metric) { + return { + pathname: '/project/activity', + query: { id: componentKey, graph: 'custom', custom_metrics: metric } + }; +} + /** * Generate URL for a component's permissions page * @param {string} componentKey -- 2.39.5