From 0d7ada66b38f4867415cbb876b88d754e3b2078e Mon Sep 17 00:00:00 2001 From: Simon Backx Date: Fri, 8 Apr 2022 09:51:30 +0200 Subject: [PATCH] Replaced usage of older MRR stats endpoint with new endpoint refs https://github.com/TryGhost/Team/issues/1470 - Correctly uses the highest value currency in the MRR graph --- ghost/admin/app/services/dashboard-stats.js | 23 ++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/ghost/admin/app/services/dashboard-stats.js b/ghost/admin/app/services/dashboard-stats.js index d4ebddbc70..76ec078d4a 100644 --- a/ghost/admin/app/services/dashboard-stats.js +++ b/ghost/admin/app/services/dashboard-stats.js @@ -325,13 +325,26 @@ export default class DashboardStatsService extends Service { return; } - let statsUrl = this.ghostPaths.url.api('members/stats/mrr'); + let statsUrl = this.ghostPaths.url.api('stats/mrr'); let stats = yield this.ajax.request(statsUrl); - // @todo: add proper support for all different currencies that are returned - this.mrrStats = stats.data[0].data.map((d) => { - return {date: d.date, mrr: d.value}; - }); + // Only show the highest value currency and filter the other ones out + const totals = stats.meta.totals; + let currentMax = totals[0]; + if (!currentMax) { + // No valid data + this.mrrStats = []; + return; + } + + for (const total of totals) { + if (total.mrr > currentMax.mrr) { + currentMax = total; + } + } + + const useCurrency = currentMax.currency; + this.mrrStats = stats.stats.filter(d => d.currency === useCurrency); } loadLastSeen() {