mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Filled defaults for newsletter open stats
refs https://github.com/TryGhost/Team/issues/469 Pads newsletter stats in case of insufficient data with empty values for line chart
This commit is contained in:
parent
f5dc5d166d
commit
f1ea66fb5f
1 changed files with 17 additions and 1 deletions
|
@ -149,7 +149,8 @@ export default class MembersStatsService extends Service {
|
||||||
limit: 10
|
limit: 10
|
||||||
};
|
};
|
||||||
const results = yield this.store.query('email', query);
|
const results = yield this.store.query('email', query);
|
||||||
const stats = results.map((d) => {
|
|
||||||
|
let stats = results.map((d) => {
|
||||||
const {emailCount, openedCount, subject, submittedAt} = d;
|
const {emailCount, openedCount, subject, submittedAt} = d;
|
||||||
const openRate = (emailCount && emailCount !== 0) ? (openedCount / emailCount).toFixed(1) : 0;
|
const openRate = (emailCount && emailCount !== 0) ? (openedCount / emailCount).toFixed(1) : 0;
|
||||||
return {
|
return {
|
||||||
|
@ -158,6 +159,21 @@ export default class MembersStatsService extends Service {
|
||||||
openRate
|
openRate
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const paddedResults = [];
|
||||||
|
if (results.length < 10) {
|
||||||
|
const pad = 10 - results.length;
|
||||||
|
const lastSubmittedAt = results.length > 0 ? results[results.length - 1].submittedAt : 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.newsletterStats = stats;
|
this.newsletterStats = stats;
|
||||||
return stats;
|
return stats;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue