From 7b12785c3060f62161cc61804c42c7ba20362789 Mon Sep 17 00:00:00 2001 From: Simon Backx Date: Fri, 8 Apr 2022 10:04:42 +0200 Subject: [PATCH] Synced the start date of members and MRR 'all time' charts (dashboard 5.0) no issue - When using 'all time' in the past, the start date of the total members/paid members chart would differ from the MRR chart. They are now synced. - The start date is always the earliest date we have data for (MRR or member counts) - The all time chart is minimum 90 days long --- ghost/admin/app/services/dashboard-stats.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/ghost/admin/app/services/dashboard-stats.js b/ghost/admin/app/services/dashboard-stats.js index 76ec078d4a..1842a906f6 100644 --- a/ghost/admin/app/services/dashboard-stats.js +++ b/ghost/admin/app/services/dashboard-stats.js @@ -613,7 +613,23 @@ export default class DashboardStatsService extends Service { let currentRangeDate; if (days === 'all') { - currentRangeDate = data.length > 0 ? moment(data[0].date) : moment(); + const MINIMUM_DAYS = 90; + currentRangeDate = moment().subtract(MINIMUM_DAYS - 1, 'days'); + + // Make sure all charts are synced correctly and have the same start date when choosing 'all time' + if (this.mrrStats !== null && this.mrrStats.length > 0) { + const date = moment(this.mrrStats[0].date); + if (date.toDate() < currentRangeDate.toDate()) { + currentRangeDate = date; + } + } + + if (this.memberCountStats !== null && this.memberCountStats.length > 0) { + const date = moment(this.memberCountStats[0].date); + if (date.toDate() < currentRangeDate.toDate()) { + currentRangeDate = date; + } + } } else { currentRangeDate = moment().subtract(days - 1, 'days'); }