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() {
const stats = this.dashboardStats.emailOpenRateStats;
const labels = stats.map(stat => stat.title);
const data = stats.map(stat => stat.email.openRate);
const labels = stats.map(stat => stat.subject);
const data = stats.map(stat => stat.openRate);
return {
labels,

View File

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

View File

@ -30,12 +30,11 @@ import {tracked} from '@glimmer/tracking';
*/
/**
* @todo: THIS ONE IS TEMPORARY
* @typedef EmailOpenRateStat (Will be the same as post model probably)
* @typedef EmailOpenRateStat
* @type {Object}
* @property {string} id Post id
* @property {string} title Post title
* @property {?Object} Email model
* @property {string} subject Email title
* @property {number} openRate Email openRate
* @property {Date} submittedAt Date
*/
/**
@ -400,8 +399,37 @@ export default class DashboardStatsService extends Service {
return;
}
const posts = yield this.store.query('post', {limit: 5, filter: 'status:published', order: 'published_at desc'});
this.emailOpenRateStats = posts;
const limit = 8;
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;
}
/**