From 30465aaaf44d599f36d7456c97da67cdcc4a1a14 Mon Sep 17 00:00:00 2001 From: Vini Brasil Date: Thu, 4 May 2023 10:42:48 +0100 Subject: [PATCH] Add percentage difference back to default view (#2895) This commit brings back percentage arrows to default view. These were removed by the recent comparisons work, and we've had reports of people missing it. As we haven't noticed any difference in performance, I've decided to revert that change. --- assets/js/dashboard/stats/graph/top-stats.js | 18 ++++++++++++++---- .../js/dashboard/stats/graph/visitor-graph.js | 6 +++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/assets/js/dashboard/stats/graph/top-stats.js b/assets/js/dashboard/stats/graph/top-stats.js index 81140bddd..ec0e1f83b 100644 --- a/assets/js/dashboard/stats/graph/top-stats.js +++ b/assets/js/dashboard/stats/graph/top-stats.js @@ -15,11 +15,18 @@ function Maybe({condition, children}) { } export default class TopStats extends React.Component { - renderPercentageComparison(name, comparison) { + renderPercentageComparison(name, comparison, forceDarkBg = false) { const formattedComparison = numberFormatter(Math.abs(comparison)) - const defaultClassName = "text-xs text-gray-100" - const noChangeClassName = "text-xs text-gray-300" + const defaultClassName = classNames({ + "text-xs dark:text-gray-100": !forceDarkBg, + "text-xs text-gray-100": forceDarkBg + }) + + const noChangeClassName = classNames({ + "text-xs text-gray-700 dark:text-gray-300": !forceDarkBg, + "text-xs text-gray-300": forceDarkBg + }) if (comparison > 0) { const color = name === 'Bounce rate' ? 'text-red-400' : 'text-green-500' @@ -65,7 +72,7 @@ export default class TopStats extends React.Component {
{query.comparison &&
{this.topStatNumberLong(stat.name, stat.value)} vs. {this.topStatNumberLong(stat.name, stat.comparison_value)} {statName} - {this.renderPercentageComparison(stat.name, stat.change)} + {this.renderPercentageComparison(stat.name, stat.change, true)}
} {!query.comparison &&
@@ -134,6 +141,9 @@ export default class TopStats extends React.Component {

{this.topStatNumberShort(stat.name, stat.value)}

+ + { this.renderPercentageComparison(stat.name, stat.change) } +

{ formatDateRange(site, topStatData.from, topStatData.to) }

diff --git a/assets/js/dashboard/stats/graph/visitor-graph.js b/assets/js/dashboard/stats/graph/visitor-graph.js index 36193c672..d2d392c51 100644 --- a/assets/js/dashboard/stats/graph/visitor-graph.js +++ b/assets/js/dashboard/stats/graph/visitor-graph.js @@ -14,6 +14,7 @@ import FadeIn from '../../fade-in'; import * as url from '../../util/url' import classNames from 'classnames'; import { parseNaiveDate, isBefore } from '../../util/date' +import { isComparisonEnabled } from '../../comparison-input' const calculateMaximumY = function(dataset) { const yAxisValues = dataset @@ -474,7 +475,10 @@ export default class VisitorGraph extends React.Component { } fetchTopStatData() { - api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/top-stats`, this.props.query) + const query = { ...this.props.query } + if (!isComparisonEnabled(query.comparison)) query.comparison = 'previous_period' + + api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/top-stats`, query) .then((res) => { res.top_stats = this.maybeRemoveFeatureFlaggedMetrics(res.top_stats) this.setState({ topStatsLoadingState: LoadingState.loaded, topStatData: res }, () => {