Ghost/ghost/admin/app/components/member-attribution/source-attribution-table.js
Rishabh 190031f38c Added modal for showing all attribution sources
refs https://github.com/TryGhost/Team/issues/1941

- limits the source attribution list to top 5 on dashboard, and shows all sources on clicking on `Other` link

Fixed lint
2022-09-26 10:43:05 +05:30

52 lines
1.7 KiB
JavaScript

import AllSourcesModal from './modals/all-sources';
import Component from '@glimmer/component';
import {action} from '@ember/object';
import {inject as service} from '@ember/service';
export default class SourceAttributionTable extends Component {
@service membersUtils;
@service modals;
@action
openAllSources() {
this.modals.open(AllSourcesModal, {
sources: this.args.sources
});
}
get others() {
const availableSources = this.args.sources.filter(source => source.source);
const unavailableSource = this.args.sources.find(sourceData => !sourceData.source);
if (!availableSources.length && !unavailableSource) {
return null;
}
return availableSources.slice(5).reduce((acc, source) => {
return {
signups: acc.signups + source.signups,
paidConversions: acc.paidConversions + source.paidConversions
};
}, {
signups: unavailableSource?.signups ?? 0,
paidConversions: unavailableSource?.paidConversions ?? 0
});
}
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);
// const unavailableSources = this.args.sources.filter(sourceData => !sourceData.source).map((sourceData) => {
// return {
// ...sourceData,
// source: 'Unavailable'
// };
// });
// return [
// ...availableSources,
// ...unavailableSources
// ];
}
}