Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed PromiseObject related errors thrown from members activity list #15641

Merged
merged 1 commit into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions ghost/admin/app/controllers/members-activity.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
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;
Expand All @@ -14,6 +16,8 @@ export default class MembersActivityController extends Controller {
@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
Expand All @@ -35,16 +39,6 @@ export default class MembersActivityController extends Controller {
return (this.excludedEvents || '').split(',').concat(this.hiddenEvents);
}

get memberRecord() {
if (!this.member) {
return null;
}

// TODO: {reload: true} here shouldn't be needed but without it
// the template renders nothing if the record is already in the store
return this.store.findRecord('member', this.member, {reload: true});
}

@action
changeExcludedEvents(newList) {
this.router.transitionTo({queryParams: {excludedEvents: newList}});
Expand Down
26 changes: 26 additions & 0 deletions ghost/admin/app/helpers/member-fetcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {Resource} from 'ember-could-get-used-to-this';
import {inject as service} from '@ember/service';
import {tracked} from '@glimmer/tracking';

class MemberFetcher extends Resource {
@service store;

@tracked loadedMember = null;

get value() {
return this.loadedMember;
}

async setup() {
const [memberId] = this.args.positional;

if (!memberId) {
return;
}

const record = await this.store.findRecord('member', memberId);
this.loadedMember = record;
}
}

export default MemberFetcher;