Migrated users.index controller to Octane patterns

refs https://github.com/TryGhost/Ghost/issues/14101

- dropped use of `{{action}}`
- dropped use of computed properties in favor of getters
This commit is contained in:
Kevin Ansfield 2022-08-30 16:35:28 +01:00
parent 5eec9c8ce2
commit 5bd66fd8b7
4 changed files with 54 additions and 66 deletions

View File

@ -957,3 +957,9 @@ remove|ember-template-lint|no-nested-interactive|23|28|23|28|5cf783a5684dda03670
add|ember-template-lint|no-passed-in-event-handlers|72|20|72|20|e639a281bd34eefbe403ddf46501154b89a1f477|1661212800000|1671584400000|1676768400000|app/components/modal-webhook-form.hbs
remove|ember-template-lint|no-action|1|40|1|40|180177e5e700535031498faa0ea4f1715555bfad|1658102400000|1668474000000|1673658000000|app/templates/pages-loading.hbs
remove|ember-template-lint|no-action|1|40|1|40|180177e5e700535031498faa0ea4f1715555bfad|1658102400000|1668474000000|1673658000000|app/templates/posts-loading.hbs
remove|ember-template-lint|no-action|30|67|30|67|84cad828f9f84f35c077dfea0661dac1ccbbcc79|1658102400000|1668474000000|1673658000000|app/templates/settings/staff/index.hbs
remove|ember-template-lint|no-action|37|118|37|118|f00cc934ece7532a0c6ac89df3a05ff04b1f1501|1658102400000|1668474000000|1673658000000|app/templates/settings/staff/index.hbs
remove|ember-template-lint|no-action|44|19|44|19|40bf79016dee9fe1dca46383af6c4c35a5441ea9|1658102400000|1668474000000|1673658000000|app/templates/settings/staff/index.hbs
remove|ember-template-lint|no-action|50|19|50|19|de05e88a1b6b658430d78f36b93dfa372903c26d|1658102400000|1668474000000|1673658000000|app/templates/settings/staff/index.hbs
remove|ember-template-lint|no-action|89|103|89|103|8a5526f86c3c3289a47e2e033e39292ceaa3999e|1658102400000|1668474000000|1673658000000|app/templates/settings/staff/index.hbs
remove|ember-template-lint|no-action|92|105|92|105|8ef55f22a4332a43d47b2508c5903048f972cefa|1658102400000|1668474000000|1673658000000|app/templates/settings/staff/index.hbs

View File

@ -28,7 +28,9 @@ export default class GhUserInvited extends Component {
}
@action
resend() {
resend(event) {
event?.preventDefault();
const invite = this.args.invite;
const notifications = this.notifications;
@ -56,7 +58,9 @@ export default class GhUserInvited extends Component {
}
@action
revoke() {
revoke(event) {
event?.preventDefault();
const invite = this.args.invite;
const email = invite.email;
const notifications = this.notifications;

View File

@ -1,78 +1,57 @@
import classic from 'ember-classic-decorator';
import {action, computed} from '@ember/object';
import {alias, filterBy, sort} from '@ember/object/computed';
import {inject as service} from '@ember/service';
/* eslint-disable ghost/ember/alias-model-in-controller */
import Controller from '@ember/controller';
import RSVP from 'rsvp';
import {action} from '@ember/object';
import {inject as service} from '@ember/service';
import {task} from 'ember-concurrency';
import {tracked} from '@glimmer/tracking';
@classic
export default class IndexController extends Controller {
@service session;
@service store;
showInviteUserModal = false;
showResetAllPasswordsModal = false;
inviteOrder = null;
userOrder = null;
@tracked showInviteUserModal = false;
@tracked showResetAllPasswordsModal = false;
init() {
super.init(...arguments);
this.inviteOrder = ['email'];
this.userOrder = ['name', 'email'];
inviteOrder = ['email'];
userOrder = ['name', 'email'];
allInvites = this.store.peekAll('invite');
allUsers = this.store.peekAll('user');
get currentUser() {
return this.model;
}
@alias('model')
currentUser;
@sort('filteredInvites', 'inviteOrder')
sortedInvites;
@sort('activeUsers', 'userOrder')
sortedActiveUsers;
@sort('suspendedUsers', 'userOrder')
sortedSuspendedUsers;
@filterBy('invites', 'isNew', false)
filteredInvites;
@computed
get invites() {
return this.store.peekAll('invite');
return this.allInvites
.filter(i => !i.isNew)
.sortBy(...this.inviteOrder);
}
@computed
get allUsers() {
return this.store.peekAll('user');
}
@computed('allUsers.@each.status')
get activeUsers() {
return this.allUsers.filter((user) => {
return user.status !== 'inactive';
});
return this.allUsers
.filter(u => u.status !== 'inactive')
.sortBy(...this.userOrder);
}
@computed('allUsers.@each.status')
get suspendedUsers() {
return this.allUsers.filter((user) => {
return user.status === 'inactive';
});
return this.allUsers
.filter(u => u.status === 'inactive')
.sortBy(...this.userOrder);
}
@action
toggleInviteUserModal() {
this.toggleProperty('showInviteUserModal');
this.showInviteUserModal = !this.showInviteUserModal;
}
@action
toggleResetAllPasswordsModal() {
this.toggleProperty('showResetAllPasswordsModal');
this.showResetAllPasswordsModal = !this.showResetAllPasswordsModal;
}
@task(function* () {
@task
*backgroundUpdate() {
let users = this.fetchUsers.perform();
let invites = this.fetchInvites.perform();
@ -81,15 +60,15 @@ export default class IndexController extends Controller {
} catch (error) {
this.send('error', error);
}
})
backgroundUpdate;
}
@task(function* () {
@task
*fetchUsers() {
yield this.store.query('user', {limit: 'all'});
})
fetchUsers;
}
@task(function* () {
@task
*fetchInvites() {
if (this.currentUser.isAuthorOrContributor) {
return;
}
@ -100,6 +79,5 @@ export default class IndexController extends Controller {
yield this.store.query('role', {limit: 'all'});
return yield this.store.query('invite', {limit: 'all'});
})
fetchInvites;
}
}

View File

@ -29,27 +29,27 @@
@classNames="gh-member-actions-menu dropdown-menu dropdown-triangle-top-right"
>
<li>
<button type="button" {{on "click" (action "toggleResetAllPasswordsModal")}}>
<button type="button" {{on "click" this.toggleResetAllPasswordsModal}}>
<span>Reset all passwords</span>
</button>
</li>
</GhDropdown>
</span>
{{/if}}
<button class="gh-btn gh-btn-primary" data-test-button="invite-staff-user" type="button" {{on "click" (action "toggleInviteUserModal")}}><span>Invite people</span></button>
<button class="gh-btn gh-btn-primary" data-test-button="invite-staff-user" type="button" {{on "click" this.toggleInviteUserModal}}><span>Invite people</span></button>
</section>
{{/unless}}
</GhCanvasHeader>
{{#if this.showInviteUserModal}}
<GhFullscreenModal @modal="invite-new-user"
@close={{action "toggleInviteUserModal"}}
@close={{this.toggleInviteUserModal}}
@modifier="action wide invite-user" />
{{/if}}
{{#if this.showResetAllPasswordsModal}}
<GhFullscreenModal @modal="reset-all-passwords"
@close={{action "toggleResetAllPasswordsModal"}}
@close={{this.toggleResetAllPasswordsModal}}
@modifier="action wide" />
{{/if}}
@ -61,7 +61,7 @@
<h4 class="gh-main-section-header small">Invited users</h4>
<div class="apps-grid">
{{#each this.sortedInvites as |invite|}}
{{#each this.invites as |invite|}}
<GhUserInvited @invite={{invite}} @reload={{route-action "reload"}} as |component|>
<div class="apps-grid-cell" data-test-invite-id="{{invite.id}}">
<article class="apps-card-app">
@ -88,10 +88,10 @@
{{#if component.isSending}}
<span>Sending Invite...</span>
{{else}}
<a class="apps-configured-action red-hover" href="#revoke" {{action "revoke" target=component}} data-test-revoke-button>
<a class="apps-configured-action red-hover" href="#revoke" {{on "click" component.revoke}} data-test-revoke-button>
Revoke
</a>
<a class="apps-configured-action green-hover" href="#resend" {{action "resend" target=component}} data-test-resend-button>
<a class="apps-configured-action green-hover" href="#resend" {{on "click" component.resend}} data-test-resend-button>
Resend
</a>
@ -118,7 +118,7 @@
<GhUserListItem @user={{this.currentUser}} @component={{component}} />
</GhUserActive>
{{else}}
{{#vertical-collection this.sortedActiveUsers
{{#vertical-collection this.activeUsers
key="id"
containerSelector=".gh-main"
estimateHeight=75
@ -138,7 +138,7 @@
<section class="apps-grid-container gh-active-users" data-test-suspended-users>
<span class="apps-grid-title">Suspended users</span>
<div class="apps-grid">
{{#each this.sortedSuspendedUsers key="id" as |user|}}
{{#each this.suspendedUsers key="id" as |user|}}
<GhUserActive @user={{user}} as |component|>
<GhUserListItem @user={{user}} @component={{component}} />
</GhUserActive>