Improved email open rate chart in dashboard 5.0

refs https://github.com/TryGhost/Team/issues/1443

- Now fetches email models instead of posts
- Fetches up to 8 emails
- Autofills missing emails, so we always have 8 emails
- Changed data structure of emailOpenRateStats variable in dashboard stats service
This commit is contained in:
Simon Backx 2022-03-28 14:20:07 +02:00
parent 4c67671dd2
commit 6208a03a11
3 changed files with 46 additions and 27 deletions

View File

@ -40,8 +40,8 @@ export default class ChartEmailOpenRate extends Component {
get chartData() { get chartData() {
const stats = this.dashboardStats.emailOpenRateStats; const stats = this.dashboardStats.emailOpenRateStats;
const labels = stats.map(stat => stat.title); const labels = stats.map(stat => stat.subject);
const data = stats.map(stat => stat.email.openRate); const data = stats.map(stat => stat.openRate);
return { return {
labels, labels,

View File

@ -215,29 +215,20 @@ export default class DashboardMocksService extends Service {
this.emailOpenRateStats = [ this.emailOpenRateStats = [
{ {
id: '23424', subject: '💸 The best way to get paid to create',
title: '💸 The best way to get paid to create', openRate: 58,
email: { submittedAt: new Date()
openedCount: 518,
deliveredCount: 1234
}
}, },
{ {
id: '23425', subject: '🎒How to start a blog and make money',
title: '🎒How to start a blog and make money', openRate: 42,
email: { submittedAt: new Date()
openedCount: 100,
deliveredCount: 900
}
} }
, ,
{ {
id: '23426', subject: 'How to turn your amateur blogging into a real business',
title: 'How to turn your amateur blogging into a real business', openRate: 89,
email: { submittedAt: new Date()
openedCount: 500,
deliveredCount: 1600
}
} }
]; ];

View File

@ -30,12 +30,11 @@ import {tracked} from '@glimmer/tracking';
*/ */
/** /**
* @todo: THIS ONE IS TEMPORARY * @typedef EmailOpenRateStat
* @typedef EmailOpenRateStat (Will be the same as post model probably)
* @type {Object} * @type {Object}
* @property {string} id Post id * @property {string} subject Email title
* @property {string} title Post title * @property {number} openRate Email openRate
* @property {?Object} Email model * @property {Date} submittedAt Date
*/ */
/** /**
@ -400,8 +399,37 @@ export default class DashboardStatsService extends Service {
return; return;
} }
const posts = yield this.store.query('post', {limit: 5, filter: 'status:published', order: 'published_at desc'}); const limit = 8;
this.emailOpenRateStats = posts; let query = {
filter: 'email_count:-0',
order: 'submitted_at desc',
limit: limit
};
const results = yield this.store.query('email', query);
const data = results.toArray();
let stats = data.map((d) => {
return {
subject: d.subject,
submittedAt: moment(d.submittedAtUTC).format('YYYY-MM-DD'),
openRate: d.openRate
};
});
const paddedResults = [];
if (data.length < limit) {
const pad = limit - data.length;
const lastSubmittedAt = data.length > 0 ? data[results.length - 1].submittedAtUTC : moment();
for (let i = 0; i < pad; i++) {
paddedResults.push({
subject: '',
submittedAt: moment(lastSubmittedAt).subtract(i + 1, 'days').format('YYYY-MM-DD'),
openRate: 0
});
}
}
stats = stats.concat(paddedResults);
stats.reverse();
this.emailOpenRateStats = stats;
} }
/** /**