Skip to content

Commit

Permalink
Fixed missing invite role name on team screen
Browse files Browse the repository at this point in the history
no issue
- removed the rename of `role_id` to `role` in the invite serialiser to let Ember Data do it's thing with the `invite.role` relationship
- added a guard to the team screen background reloading to ensure that role data is present in the store before loading invites so that Ember Data doesn't trigger unnecessary requests to find missing relationship data
  • Loading branch information
kevinansfield committed Jan 14, 2019
1 parent 15188d9 commit fe1365d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
16 changes: 10 additions & 6 deletions app/controllers/team/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ export default Controller.extend({
backgroundUpdate: task(function* () {
let users = this.fetchUsers.perform();
let invites = this.fetchInvites.perform();
let roles = this.fetchRoles.perform();

try {
yield RSVP.all([users, invites, roles]);
yield RSVP.all([users, invites]);
} catch (error) {
this.send('error', error);
}
Expand All @@ -78,10 +77,15 @@ export default Controller.extend({
return;
}

return yield this.store.query('invite', {limit: 'all'});
}),
// ensure roles are loaded before invites. Invites do not have embedded
// role records which means Ember Data will try to fetch the roles
// automatically when invite.role is queried, loading roles first makes
// them available in memory and cuts down on network noise
let knownRoles = this.store.peekAll('role');
if (knownRoles.length <= 1) {
yield this.store.query('role', {limit: 'all'});
}

fetchRoles: task(function* () {
return yield this.store.findAll('role');
return yield this.store.query('invite', {limit: 'all'});
})
});
2 changes: 1 addition & 1 deletion app/models/invite.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint camelcase: [2, {properties: "never"}] */
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import {belongsTo} from 'ember-data/relationships';
Expand All @@ -13,6 +12,7 @@ export default Model.extend({
updatedAtUTC: attr('moment-utc'),
updatedBy: attr('number'),
status: attr('string'),

role: belongsTo('role', {async: false}),

ajax: service(),
Expand Down
1 change: 0 additions & 1 deletion app/serializers/invite.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import ApplicationSerializer from 'ghost-admin/serializers/application';

export default ApplicationSerializer.extend({
attrs: {
role: {key: 'role_id'},
createdAtUTC: {key: 'created_at'},
updatedAtUTC: {key: 'updated_at'}
}
Expand Down

0 comments on commit fe1365d

Please sign in to comment.