Removed newsletter name from activity feed if no multiple newsletters

refs https://github.com/TryGhost/Team/issues/1563

- Check if we have multiple newsletters in the members-events-fetcher
- Pass the resulting value to the `parse-member-event` helper
- Pass the value to the activity feed table and table-row components
This commit is contained in:
Simon Backx 2022-05-04 10:21:42 +02:00
parent 300cd79d3e
commit 6adecb5db1
9 changed files with 40 additions and 15 deletions

View File

@ -25,7 +25,7 @@
{{#if eventsFetcher.data}} {{#if eventsFetcher.data}}
<ul class="gh-dashboard-activity-list"> <ul class="gh-dashboard-activity-list">
{{#each eventsFetcher.data as |event|}} {{#each eventsFetcher.data as |event|}}
{{#let (parse-member-event event) as |parsedEvent|}} {{#let (parse-member-event event eventsFetcher.hasMultipleNewsletters) as |parsedEvent|}}
<li class="gh-dashboard-activity-item" data-test-dashboard-member-activity-item> <li class="gh-dashboard-activity-item" data-test-dashboard-member-activity-item>
<LinkTo class="member-details" @route="member" @model="{{parsedEvent.memberId}}"> <LinkTo class="member-details" @route="member" @model="{{parsedEvent.memberId}}">
<div class="gh-dashboard-activity-container"> <div class="gh-dashboard-activity-container">

View File

@ -21,7 +21,7 @@
{{else}} {{else}}
{{#if eventsFetcher.data}} {{#if eventsFetcher.data}}
{{#each eventsFetcher.data as |event|}} {{#each eventsFetcher.data as |event|}}
{{#let (parse-member-event event) as |parsedEvent|}} {{#let (parse-member-event event eventsFetcher.hasMultipleNewsletters) as |parsedEvent|}}
<div class="gh-dashboard5-list-item" data-test-dashboard-member-activity-item> <div class="gh-dashboard5-list-item" data-test-dashboard-member-activity-item>
<LinkTo class="member-details" @route="member" @model="{{parsedEvent.memberId}}"> <LinkTo class="member-details" @route="member" @model="{{parsedEvent.memberId}}">
<GhMemberAvatar @member={{parsedEvent.member}} @containerClass="w8 h8 mr3 flex-shrink-0" /> <GhMemberAvatar @member={{parsedEvent.member}} @containerClass="w8 h8 mr3 flex-shrink-0" />

View File

@ -75,7 +75,7 @@
{{else}} {{else}}
{{#if eventsFetcher.data}} {{#if eventsFetcher.data}}
{{#each eventsFetcher.data as |event|}} {{#each eventsFetcher.data as |event|}}
{{#let (parse-member-event event) as |parsedEvent|}} {{#let (parse-member-event event eventsFetcher.hasMultipleNewsletters) as |parsedEvent|}}
<div class="gh-dashboard5-list-item" data-test-dashboard-member-activity-item> <div class="gh-dashboard5-list-item" data-test-dashboard-member-activity-item>
<div class="gh-dashboard5-list-item-sub"> <div class="gh-dashboard5-list-item-sub">
<LinkTo class="member-details" @route="member" @model="{{parsedEvent.memberId}}"> <LinkTo class="member-details" @route="member" @model="{{parsedEvent.memberId}}">

View File

@ -15,7 +15,7 @@
<div class="relative h17"><GhLoadingSpinner class="h30" /></div> <div class="relative h17"><GhLoadingSpinner class="h30" /></div>
{{else if eventsFetcher.data}} {{else if eventsFetcher.data}}
{{#each eventsFetcher.data as |rawEvent|}} {{#each eventsFetcher.data as |rawEvent|}}
{{#let (parse-member-event rawEvent) as |event|}} {{#let (parse-member-event rawEvent eventsFetcher.hasMultipleNewsletters) as |event|}}
<div class="gh-member-feed-row"> <div class="gh-member-feed-row">
<div class="gh-member-feed-container"> <div class="gh-member-feed-container">
<div class="gh-member-feed-icon"> <div class="gh-member-feed-icon">

View File

@ -1,4 +1,4 @@
{{#let (parse-member-event @event) as |event|}} {{#let (parse-member-event @event @hasMultipleNewsletters) as |event|}}
<tr> <tr>
{{#unless @hideMemberColumn}} {{#unless @hideMemberColumn}}
<div class="gh-list-data"> <div class="gh-list-data">

View File

@ -10,7 +10,7 @@
</thead> </thead>
<tbody> <tbody>
{{#each @events as |event|}} {{#each @events as |event|}}
<MembersActivity::TableRow @hideMemberColumn={{@hideMemberColumn}} @event={{event}} /> <MembersActivity::TableRow @hideMemberColumn={{@hideMemberColumn}} @event={{event}} @hasMultipleNewsletters={{@hasMultipleNewsletters}} />
{{/each}} {{/each}}
</tbody> </tbody>
</table> </table>

View File

@ -9,6 +9,7 @@ import {tracked} from '@glimmer/tracking';
export default class MembersEventsFetcher extends Resource { export default class MembersEventsFetcher extends Resource {
@service ajax; @service ajax;
@service ghostPaths; @service ghostPaths;
@service store;
@tracked data = new TrackedArray([]); @tracked data = new TrackedArray([]);
@tracked isLoading = false; @tracked isLoading = false;
@ -16,6 +17,11 @@ export default class MembersEventsFetcher extends Resource {
@tracked errorMessage = null; @tracked errorMessage = null;
@tracked hasReachedEnd = false; @tracked hasReachedEnd = false;
/**
* Keep track whether we have multiple newsletters (required for parsing events)
*/
@tracked hasMultipleNewsletters = null;
cursor = null; cursor = null;
get value() { get value() {
@ -25,7 +31,8 @@ export default class MembersEventsFetcher extends Resource {
errorMessage: this.errorMessage, errorMessage: this.errorMessage,
data: this.data, data: this.data,
loadNextPage: this.loadNextPage, loadNextPage: this.loadNextPage,
hasReachedEnd: this.hasReachedEnd hasReachedEnd: this.hasReachedEnd,
hasMultipleNewsletters: this.hasMultipleNewsletters
}; };
} }
@ -37,7 +44,9 @@ export default class MembersEventsFetcher extends Resource {
filter += `+${this.args.named.filter}`; filter += `+${this.args.named.filter}`;
} }
return this.loadEventsTask.perform({filter}); // Can't get this working with Promise.all, somehow results in an infinite loop
await this.loadEventsTask.perform({filter});
await this.loadMultipleNewslettersTask.perform();
} }
@action @action
@ -67,6 +76,22 @@ export default class MembersEventsFetcher extends Resource {
this.loadEventsTask.perform({filter}); this.loadEventsTask.perform({filter});
} }
/**
* We need to know whether we have multiple newsletters so we can hide/show the newsletter name
*/
@task
*loadMultipleNewslettersTask() {
try {
const res = yield this.store.query('newsletter', {filter: 'status:active', include: 'none', limit: 1});
const newsletterCount = res.meta.pagination.total;
this.hasMultipleNewsletters = newsletterCount > 1;
} catch (e) {
// Default to true (harms the least)
this.hasMultipleNewsletters = true;
console.error(e); // eslint-disable-line
}
}
@task @task
*loadEventsTask(queryParams) { *loadEventsTask(queryParams) {
try { try {

View File

@ -1,11 +1,11 @@
import moment from 'moment'; import moment from 'moment';
import {getNonDecimal, getSymbol} from 'ghost-admin/utils/currency'; import {getNonDecimal, getSymbol} from 'ghost-admin/utils/currency';
export default function parseMemberEvent(event) { export default function parseMemberEvent(event, hasMultipleNewsletters) {
let subject = event.data.member.name || event.data.member.email; let subject = event.data.member.name || event.data.member.email;
let icon = getIcon(event); let icon = getIcon(event);
let action = getAction(event); let action = getAction(event);
let object = getObject(event); let object = getObject(event, hasMultipleNewsletters);
let info = getInfo(event); let info = getInfo(event);
let timestamp = moment(event.data.created_at); let timestamp = moment(event.data.created_at);
@ -125,12 +125,12 @@ function getAction(event) {
} }
} }
function getObject(event) { function getObject(event, hasMultipleNewsletters) {
if (event.type === 'newsletter_event') { if (event.type === 'newsletter_event') {
if (event.data.newsletter && event.data.newsletter.name) { if (hasMultipleNewsletters && event.data.newsletter && event.data.newsletter.name) {
return 'newsletter ' + event.data.newsletter.name; return 'newsletter ' + event.data.newsletter.name;
} }
return 'emails'; return 'newsletter';
} }
if (event.type === 'subscription_event') { if (event.type === 'subscription_event') {

View File

@ -26,7 +26,7 @@
<GhMemberDetailsActivity @member={{this.memberRecord}} /> <GhMemberDetailsActivity @member={{this.memberRecord}} />
{{/if}} {{/if}}
<div class="gh-list-scrolling"> <div class="gh-list-scrolling">
<MembersActivity::Table @hideMemberColumn={{if this.member true}} @events={{eventsFetcher.data}} /> <MembersActivity::Table @hideMemberColumn={{if this.member true}} @events={{eventsFetcher.data}} @hasMultipleNewsletters={{eventsFetcher.hasMultipleNewsletters}} />
{{#if (not (or eventsFetcher.isLoading eventsFetcher.hasReachedEnd))}} {{#if (not (or eventsFetcher.isLoading eventsFetcher.hasReachedEnd))}}
<GhScrollTrigger @enter={{eventsFetcher.loadNextPage}} @triggerOffset={{250}} /> <GhScrollTrigger @enter={{eventsFetcher.loadNextPage}} @triggerOffset={{250}} />