mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-23 02:41:50 +03:00
f78f264982
no issue - the `memberRecord` getter on the members activity controller was returning the direct result of `store.findRecord()` which in reality is a `PromiseObject` that is a type of proxy. Although templates handle this OK, any JS code using the object needs to know that it's not a typical type of object and has to use `.get()` for all property access to avoid errors - switched `memberRecord` from a getter to a resource so we have more control over the returned object and loading lifecycle - added a `MemberFetcher` resource class that awaits the result of the store find and only then sets the value meaning we always have a fully resolved model object - being a resource the fetch will only occur when the `member` id property changes, unlike the getter which performed the fetch every time it was accessed
52 lines
1.6 KiB
JavaScript
52 lines
1.6 KiB
JavaScript
import Controller from '@ember/controller';
|
|
import MemberFetcher from 'ghost-admin/helpers/member-fetcher';
|
|
import {EMAIL_EVENTS, NEWSLETTER_EVENTS} from 'ghost-admin/helpers/members-event-filter';
|
|
import {action} from '@ember/object';
|
|
import {inject as service} from '@ember/service';
|
|
import {tracked} from '@glimmer/tracking';
|
|
import {use} from 'ember-could-get-used-to-this';
|
|
|
|
export default class MembersActivityController extends Controller {
|
|
@service router;
|
|
@service settings;
|
|
@service store;
|
|
|
|
queryParams = ['excludedEvents', 'member'];
|
|
|
|
@tracked excludedEvents = null;
|
|
@tracked member = null;
|
|
|
|
@use memberRecord = new MemberFetcher(() => [this.member]);
|
|
|
|
// we don't want to show or allow filtering of certain events in some situations
|
|
// - no member selected = don't show email events, they flood the list and the API can't paginate correctly
|
|
// - newsletter is disabled = don't show email or newletter events
|
|
get hiddenEvents() {
|
|
const hiddenEvents = [];
|
|
|
|
if (!this.member) {
|
|
hiddenEvents.push(...EMAIL_EVENTS);
|
|
}
|
|
|
|
if (this.settings.editorDefaultEmailRecipients === 'disabled') {
|
|
hiddenEvents.push(...EMAIL_EVENTS, ...NEWSLETTER_EVENTS);
|
|
}
|
|
|
|
return hiddenEvents;
|
|
}
|
|
|
|
get fullExcludedEvents() {
|
|
return (this.excludedEvents || '').split(',').concat(this.hiddenEvents);
|
|
}
|
|
|
|
@action
|
|
changeExcludedEvents(newList) {
|
|
this.router.transitionTo({queryParams: {excludedEvents: newList}});
|
|
}
|
|
|
|
@action
|
|
changeMember(member) {
|
|
this.router.transitionTo({queryParams: {member: member?.id}});
|
|
}
|
|
}
|