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:
parent
300cd79d3e
commit
6adecb5db1
@ -25,7 +25,7 @@
|
||||
{{#if eventsFetcher.data}}
|
||||
<ul class="gh-dashboard-activity-list">
|
||||
{{#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>
|
||||
<LinkTo class="member-details" @route="member" @model="{{parsedEvent.memberId}}">
|
||||
<div class="gh-dashboard-activity-container">
|
||||
|
@ -21,7 +21,7 @@
|
||||
{{else}}
|
||||
{{#if eventsFetcher.data}}
|
||||
{{#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>
|
||||
<LinkTo class="member-details" @route="member" @model="{{parsedEvent.memberId}}">
|
||||
<GhMemberAvatar @member={{parsedEvent.member}} @containerClass="w8 h8 mr3 flex-shrink-0" />
|
||||
|
@ -75,7 +75,7 @@
|
||||
{{else}}
|
||||
{{#if eventsFetcher.data}}
|
||||
{{#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-sub">
|
||||
<LinkTo class="member-details" @route="member" @model="{{parsedEvent.memberId}}">
|
||||
|
@ -15,7 +15,7 @@
|
||||
<div class="relative h17"><GhLoadingSpinner class="h30" /></div>
|
||||
{{else if eventsFetcher.data}}
|
||||
{{#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-container">
|
||||
<div class="gh-member-feed-icon">
|
||||
|
@ -1,4 +1,4 @@
|
||||
{{#let (parse-member-event @event) as |event|}}
|
||||
{{#let (parse-member-event @event @hasMultipleNewsletters) as |event|}}
|
||||
<tr>
|
||||
{{#unless @hideMemberColumn}}
|
||||
<div class="gh-list-data">
|
||||
|
@ -10,7 +10,7 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#each @events as |event|}}
|
||||
<MembersActivity::TableRow @hideMemberColumn={{@hideMemberColumn}} @event={{event}} />
|
||||
<MembersActivity::TableRow @hideMemberColumn={{@hideMemberColumn}} @event={{event}} @hasMultipleNewsletters={{@hasMultipleNewsletters}} />
|
||||
{{/each}}
|
||||
</tbody>
|
||||
</table>
|
||||
|
@ -9,6 +9,7 @@ import {tracked} from '@glimmer/tracking';
|
||||
export default class MembersEventsFetcher extends Resource {
|
||||
@service ajax;
|
||||
@service ghostPaths;
|
||||
@service store;
|
||||
|
||||
@tracked data = new TrackedArray([]);
|
||||
@tracked isLoading = false;
|
||||
@ -16,6 +17,11 @@ export default class MembersEventsFetcher extends Resource {
|
||||
@tracked errorMessage = null;
|
||||
@tracked hasReachedEnd = false;
|
||||
|
||||
/**
|
||||
* Keep track whether we have multiple newsletters (required for parsing events)
|
||||
*/
|
||||
@tracked hasMultipleNewsletters = null;
|
||||
|
||||
cursor = null;
|
||||
|
||||
get value() {
|
||||
@ -25,7 +31,8 @@ export default class MembersEventsFetcher extends Resource {
|
||||
errorMessage: this.errorMessage,
|
||||
data: this.data,
|
||||
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}`;
|
||||
}
|
||||
|
||||
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
|
||||
@ -67,6 +76,22 @@ export default class MembersEventsFetcher extends Resource {
|
||||
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
|
||||
*loadEventsTask(queryParams) {
|
||||
try {
|
||||
|
@ -1,11 +1,11 @@
|
||||
import moment from 'moment';
|
||||
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 icon = getIcon(event);
|
||||
let action = getAction(event);
|
||||
let object = getObject(event);
|
||||
let object = getObject(event, hasMultipleNewsletters);
|
||||
let info = getInfo(event);
|
||||
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.data.newsletter && event.data.newsletter.name) {
|
||||
if (hasMultipleNewsletters && event.data.newsletter && event.data.newsletter.name) {
|
||||
return 'newsletter – ' + event.data.newsletter.name;
|
||||
}
|
||||
return 'emails';
|
||||
return 'newsletter';
|
||||
}
|
||||
|
||||
if (event.type === 'subscription_event') {
|
||||
|
@ -26,7 +26,7 @@
|
||||
<GhMemberDetailsActivity @member={{this.memberRecord}} />
|
||||
{{/if}}
|
||||
<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))}}
|
||||
<GhScrollTrigger @enter={{eventsFetcher.loadNextPage}} @triggerOffset={{250}} />
|
||||
@ -45,4 +45,4 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{{outlet}}
|
||||
{{outlet}}
|
||||
|
Loading…
Reference in New Issue
Block a user