diff --git a/ghost/admin/app/components/dashboard/v5/chart-paid-mix.hbs b/ghost/admin/app/components/dashboard/v5/chart-paid-mix.hbs index 9fed7eb168..0f2bd515b8 100644 --- a/ghost/admin/app/components/dashboard/v5/chart-paid-mix.hbs +++ b/ghost/admin/app/components/dashboard/v5/chart-paid-mix.hbs @@ -1,4 +1,22 @@ -

Paid mix ({{this.mode}})

+ +
+ + {{#if option.name}}{{option.name}}{{else}}Unknown option{{/if}} + +
+ +

Paid mix

+ {{#if this.loading}}
{{else}} diff --git a/ghost/admin/app/components/dashboard/v5/chart-paid-mix.js b/ghost/admin/app/components/dashboard/v5/chart-paid-mix.js index 17e8988b95..a303b82721 100644 --- a/ghost/admin/app/components/dashboard/v5/chart-paid-mix.js +++ b/ghost/admin/app/components/dashboard/v5/chart-paid-mix.js @@ -1,6 +1,15 @@ import Component from '@glimmer/component'; import {action} from '@ember/object'; import {inject as service} from '@ember/service'; +import {tracked} from '@glimmer/tracking'; + +const MODE_OPTIONS = [{ + name: 'Cadence', + value: 'cadence' +}, { + name: 'Tiers', + value: 'tiers' +}]; export default class ChartPaidMix extends Component { @service dashboardStats; @@ -24,16 +33,29 @@ export default class ChartPaidMix extends Component { } } + @tracked mode = 'cadence'; + modeOptions = MODE_OPTIONS; + + get selectedModeOption() { + return this.modeOptions.find(option => option.value === this.mode); + } + + @action + onSwitchMode(selected) { + this.mode = selected.value; + + if (this.loading) { + // We don't have the data yet for the newly selected mode + this.loadCharts(); + } + } + get loading() { if (this.mode === 'cadence') { return this.dashboardStats.paidMembersByCadence === null; } return this.dashboardStats.paidMembersByTier === null; } - - get mode() { - return 'cadence'; - } get chartType() { return 'pie'; @@ -51,7 +73,19 @@ export default class ChartPaidMix extends Component { }] }; } - throw new Error('Not yet supported'); + + const labels = this.dashboardStats.paidMembersByTier.map(stat => stat.tier.name); + const data = this.dashboardStats.paidMembersByTier.map(stat => stat.members); + + return { + labels, + datasets: [{ + data, + fill: false, + backgroundColor: ['#14b8ff'], + tension: 0.1 + }] + }; } get chartOptions() { diff --git a/ghost/admin/app/styles/layouts/dashboard.css b/ghost/admin/app/styles/layouts/dashboard.css index 4e375d6110..847dc6bc96 100644 --- a/ghost/admin/app/styles/layouts/dashboard.css +++ b/ghost/admin/app/styles/layouts/dashboard.css @@ -1093,6 +1093,12 @@ a.gh-dashboard-container { justify-content: flex-end; } +.prototype-paid-mix-dropdown { + position: absolute; + right: 15px; + top: 15px; +} + .prototype-counts { display: flex; flex-direction: row; @@ -1125,6 +1131,7 @@ a.gh-dashboard-container { .prototype-box { border: 1px solid #ebeef0; padding: 28px; + position: relative; } .prototype-box .number {