diff --git a/assets/js/dashboard/stats/graph/top-stats.js b/assets/js/dashboard/stats/graph/top-stats.js index bb1ffb515..b8478a7d7 100644 --- a/assets/js/dashboard/stats/graph/top-stats.js +++ b/assets/js/dashboard/stats/graph/top-stats.js @@ -14,100 +14,102 @@ function Maybe({condition, children}) { } } -export default class TopStats extends React.Component { - renderPercentageComparison(name, comparison, forceDarkBg = false) { - const formattedComparison = numberFormatter(Math.abs(comparison)) - - const defaultClassName = classNames({ - "pl-2 text-xs dark:text-gray-100": !forceDarkBg, - "pl-2 text-xs text-gray-100": forceDarkBg - }) - - const noChangeClassName = classNames({ - "pl-2 text-xs text-gray-700 dark:text-gray-300": !forceDarkBg, - "pl-2 text-xs text-gray-300": forceDarkBg - }) - - if (comparison > 0) { - const color = name === 'Bounce rate' ? 'text-red-400' : 'text-green-500' - return ↑ {formattedComparison}% - } else if (comparison < 0) { - const color = name === 'Bounce rate' ? 'text-green-500' : 'text-red-400' - return ↓ {formattedComparison}% - } else if (comparison === 0) { - return 〰 0% - } else { - return null - } +function renderPercentageComparison(name, comparison, forceDarkBg = false) { + const formattedComparison = numberFormatter(Math.abs(comparison)) + + const defaultClassName = classNames({ + "pl-2 text-xs dark:text-gray-100": !forceDarkBg, + "pl-2 text-xs text-gray-100": forceDarkBg + }) + + const noChangeClassName = classNames({ + "pl-2 text-xs text-gray-700 dark:text-gray-300": !forceDarkBg, + "pl-2 text-xs text-gray-300": forceDarkBg + }) + + if (comparison > 0) { + const color = name === 'Bounce rate' ? 'text-red-400' : 'text-green-500' + return ↑ {formattedComparison}% + } else if (comparison < 0) { + const color = name === 'Bounce rate' ? 'text-green-500' : 'text-red-400' + return ↓ {formattedComparison}% + } else if (comparison === 0) { + return 〰 0% + } else { + return null } +} - topStatNumberShort(name, value) { - if (['visit duration', 'time on page'].includes(name.toLowerCase())) { - return durationFormatter(value) - } else if (['bounce rate', 'conversion rate'].includes(name.toLowerCase())) { - return value + '%' - } else if (['average revenue', 'total revenue'].includes(name.toLowerCase())) { - return value?.short - } else { - return numberFormatter(value) - } +function topStatNumberShort(name, value) { + if (['visit duration', 'time on page'].includes(name.toLowerCase())) { + return durationFormatter(value) + } else if (['bounce rate', 'conversion rate'].includes(name.toLowerCase())) { + return value + '%' + } else if (['average revenue', 'total revenue'].includes(name.toLowerCase())) { + return value?.short + } else { + return numberFormatter(value) } +} - topStatNumberLong(name, value) { - if (['visit duration', 'time on page'].includes(name.toLowerCase())) { - return durationFormatter(value) - } else if (['bounce rate', 'conversion rate'].includes(name.toLowerCase())) { - return value + '%' - } else if (['average revenue', 'total revenue'].includes(name.toLowerCase())) { - return value?.long - } else { - return (value || 0).toLocaleString() - } +function topStatNumberLong(name, value) { + if (['visit duration', 'time on page'].includes(name.toLowerCase())) { + return durationFormatter(value) + } else if (['bounce rate', 'conversion rate'].includes(name.toLowerCase())) { + return value + '%' + } else if (['average revenue', 'total revenue'].includes(name.toLowerCase())) { + return value?.long + } else { + return (value || 0).toLocaleString() } +} - topStatTooltip(stat, query) { +export default function TopStats(props) { + const {site, query, data, onMetricUpdate, tooltipBoundary, lastLoadTimestamp} = props + + function tooltip(stat) { let statName = stat.name.toLowerCase() statName = stat.value === 1 ? statName.slice(0, -1) : statName return (
Last updated
Last updated
{this.topStatNumberShort(stat.name, stat.value)}
-{ formatDateRange(site, topStatData.from, topStatData.to) }
-{topStatNumberShort(stat.name, stat.value)}
+{ this.topStatNumberShort(stat.name, stat.comparison_value) }
-{ formatDateRange(site, topStatData.comparing_from, topStatData.comparing_to) }
-{ formatDateRange(site, data.from, data.to) }
{ topStatNumberShort(stat.name, stat.comparison_value) }
+{ formatDateRange(site, data.comparing_from, data.comparing_to) }