From b1b3c726420964ac0fa8af4921595918be50b78e Mon Sep 17 00:00:00 2001 From: Rishabh Garg Date: Mon, 26 Sep 2022 23:29:30 +0530 Subject: [PATCH] Added sorting for attribution data on dashboard (#15474) refs https://github.com/TryGhost/Team/issues/1941 - sorts attribution table and chart on signups or paid conversions --- .../dashboard/charts/attribution.hbs | 13 +++++- .../dashboard/charts/attribution.js | 7 ++++ .../member-attribution/modals/all-sources.hbs | 2 +- .../member-attribution/modals/all-sources.js | 14 ------- .../source-attribution-chart.js | 5 +-- .../source-attribution-table.hbs | 16 +++++++- .../source-attribution-table.js | 41 +++++++++++-------- ghost/admin/app/styles/layouts/dashboard.css | 2 +- 8 files changed, 60 insertions(+), 40 deletions(-) diff --git a/ghost/admin/app/components/dashboard/charts/attribution.hbs b/ghost/admin/app/components/dashboard/charts/attribution.hbs index a310bc68f3..d487e7c32d 100644 --- a/ghost/admin/app/components/dashboard/charts/attribution.hbs +++ b/ghost/admin/app/components/dashboard/charts/attribution.hbs @@ -4,11 +4,20 @@

Top sources

- +
- +
diff --git a/ghost/admin/app/components/dashboard/charts/attribution.js b/ghost/admin/app/components/dashboard/charts/attribution.js index a56b6180e4..0f3fea0b6f 100644 --- a/ghost/admin/app/components/dashboard/charts/attribution.js +++ b/ghost/admin/app/components/dashboard/charts/attribution.js @@ -1,9 +1,16 @@ import Component from '@glimmer/component'; import {action} from '@ember/object'; import {inject as service} from '@ember/service'; +import {tracked} from '@glimmer/tracking'; export default class Recents extends Component { @service dashboardStats; + @tracked sortColumn = 'signups'; + + @action + setSortColumn(column) { + this.sortColumn = column; + } @action loadData() { diff --git a/ghost/admin/app/components/member-attribution/modals/all-sources.hbs b/ghost/admin/app/components/member-attribution/modals/all-sources.hbs index 074523bedb..a9d28dca56 100644 --- a/ghost/admin/app/components/member-attribution/modals/all-sources.hbs +++ b/ghost/admin/app/components/member-attribution/modals/all-sources.hbs @@ -15,7 +15,7 @@
- {{#each this.sources as |sourceData|}} + {{#each @data.sources as |sourceData|}}
{{sourceData.source}} diff --git a/ghost/admin/app/components/member-attribution/modals/all-sources.js b/ghost/admin/app/components/member-attribution/modals/all-sources.js index 0b73f41efd..b756ab4a03 100644 --- a/ghost/admin/app/components/member-attribution/modals/all-sources.js +++ b/ghost/admin/app/components/member-attribution/modals/all-sources.js @@ -3,18 +3,4 @@ import {inject as service} from '@ember/service'; export default class FullAttributionTable extends Component { @service membersUtils; - - get sources() { - const availableSources = this.args.data.sources.filter(source => source.source); - const unavailableSources = this.args.data.sources.filter(sourceData => !sourceData.source).map((sourceData) => { - return { - ...sourceData, - source: 'Unavailable' - }; - }); - return [ - ...availableSources, - ...unavailableSources - ]; - } } diff --git a/ghost/admin/app/components/member-attribution/source-attribution-chart.js b/ghost/admin/app/components/member-attribution/source-attribution-chart.js index acbdb71923..6b1fecaab0 100644 --- a/ghost/admin/app/components/member-attribution/source-attribution-chart.js +++ b/ghost/admin/app/components/member-attribution/source-attribution-chart.js @@ -1,5 +1,4 @@ import Component from '@glimmer/component'; -import {tracked} from '@glimmer/tracking'; const CHART_COLORS = [ '#8e42ff', @@ -11,8 +10,6 @@ const CHART_COLORS = [ ]; export default class SourceAttributionChart extends Component { - @tracked chartType = 'free'; - get sources() { return this.args.sources; } @@ -84,7 +81,7 @@ export default class SourceAttributionChart extends Component { } get chartData() { - if (this.chartType === 'free') { + if (this.args.sortColumn === 'signups') { const sortedByFree = [...this.sources]; sortedByFree.sort((a, b) => { return b.signups - a.signups; diff --git a/ghost/admin/app/components/member-attribution/source-attribution-table.hbs b/ghost/admin/app/components/member-attribution/source-attribution-table.hbs index c8c32ac1f4..5b5c0a7d2d 100644 --- a/ghost/admin/app/components/member-attribution/source-attribution-table.hbs +++ b/ghost/admin/app/components/member-attribution/source-attribution-table.hbs @@ -1,9 +1,21 @@
Sources
-
Signups {{svg-jar "arrow-down-small"}}
+
+ Signups {{svg-jar "arrow-down-small"}} +
{{#if this.membersUtils.paidMembersEnabled}} -
Paid Conversions {{svg-jar "arrow-down-small"}}
+
+ Paid Conversions {{svg-jar "arrow-down-small"}} +
{{/if}}
diff --git a/ghost/admin/app/components/member-attribution/source-attribution-table.js b/ghost/admin/app/components/member-attribution/source-attribution-table.js index 78ca395533..8bf5239834 100644 --- a/ghost/admin/app/components/member-attribution/source-attribution-table.js +++ b/ghost/admin/app/components/member-attribution/source-attribution-table.js @@ -10,12 +10,24 @@ export default class SourceAttributionTable extends Component { @action openAllSources() { this.modals.open(AllSourcesModal, { - sources: this.args.sources + sources: [ + ...this.sortedSources, + ...this.unavailableSource + ] + }); + } + + get unavailableSource() { + return this.args.sources.filter(sourceData => !sourceData.source).map((sourceData) => { + return { + ...sourceData, + source: 'Unavailable' + }; }); } get others() { - const availableSources = this.args.sources.filter(source => source.source); + const availableSources = this.sortedSources; const unavailableSource = this.args.sources.find(sourceData => !sourceData.source); if (!availableSources.length && !unavailableSource) { return null; @@ -32,20 +44,17 @@ export default class SourceAttributionTable extends Component { }); } - get sources() { - return this.args.sources.filter(source => source.source).slice(0, 5); - // const availableSources = this.args.sources.filter(source => source.source); - // return availableSources.slice(0, 5); + get sortedSources() { + return this.args.sources?.filter(source => source.source).sort((a, b) => { + if (this.args.sortColumn === 'signups') { + return b.signups - a.signups; + } else { + return b.paidConversions - a.paidConversions; + } + }) || []; + } - // const unavailableSources = this.args.sources.filter(sourceData => !sourceData.source).map((sourceData) => { - // return { - // ...sourceData, - // source: 'Unavailable' - // }; - // }); - // return [ - // ...availableSources, - // ...unavailableSources - // ]; + get sources() { + return this.sortedSources.slice(0, 5); } } diff --git a/ghost/admin/app/styles/layouts/dashboard.css b/ghost/admin/app/styles/layouts/dashboard.css index e33b4acb65..b4b3a50743 100644 --- a/ghost/admin/app/styles/layouts/dashboard.css +++ b/ghost/admin/app/styles/layouts/dashboard.css @@ -1075,7 +1075,7 @@ Dashboard Attribution */ } .gh-dashboard-list-title.sorted-by svg { - display: block; + display: inline; } .gh-dashboard-list-title svg path {