Removed used of ember-data-filter

closes https://github.com/TryGhost/Ghost/issues/9591
- swapped use of `store.filter` for a combination `store.peekAll` and CPs to filter the result set
This commit is contained in:
Kevin Ansfield 2018-04-30 13:54:09 +01:00
parent 7d95d42eda
commit e28a960970
8 changed files with 40 additions and 23 deletions

View File

@ -11,18 +11,25 @@ export default Component.extend({
tagName: '',
triggerId: '',
// internal attrs
availableAuthors: null,
// closure actions
updateAuthors() {},
// live-query of all users for author input autocomplete
availableAuthors: computed(function () {
return this.get('store').filter('user', {limit: 'all'}, () => true);
}),
availableAuthorNames: computed('availableAuthors.@each.name', function () {
return this.get('availableAuthors').map(author => author.get('name').toLowerCase());
}),
init() {
this._super(...arguments);
// perform a background query to fetch all users and set `availableAuthors`
// to a live-query that will be immediately populated with what's in the
// store and be updated when the above query returns
this.store.query('user', {limit: 'all'});
this.set('availableAuthors', this.store.peekAll('user'));
},
actions: {
updateAuthors(newAuthors) {
this.updateAuthors(newAuthors);

View File

@ -10,15 +10,22 @@ export default Component.extend({
post: null,
tagName: '',
// live-query of all tags for tag input autocomplete
availableTags: computed(function () {
return this.get('store').filter('tag', {limit: 'all'}, () => true);
}),
// internal attrs
availableTags: null,
availableTagNames: computed('availableTags.@each.name', function () {
return this.get('availableTags').map(tag => tag.get('name').toLowerCase());
}),
init() {
this._super(...arguments);
// perform a background query to fetch all users and set `availableTags`
// to a live-query that will be immediately populated with what's in the
// store and be updated when the above query returns
this.store.query('tag', {limit: 'all'});
this.set('availableTags', this.store.peekAll('tag'));
},
actions: {
matchTags(tagName, term) {
return tagName.toLowerCase() === term.trim().toLowerCase();

View File

@ -1,5 +1,6 @@
import Controller, {inject as controller} from '@ember/controller';
import {alias, equal, sort} from '@ember/object/computed';
import {computed} from '@ember/object';
import {run} from '@ember/runloop';
export default Controller.extend({
@ -12,8 +13,12 @@ export default Controller.extend({
tagListFocused: equal('keyboardFocus', 'tagList'),
tagContentFocused: equal('keyboardFocus', 'tagContent'),
filteredTags: computed('tags.@each.isNew', function () {
return this.get('tags').filterBy('isNew', false);
}),
// TODO: replace with ordering by page count once supported by the API
sortedTags: sort('tags', function (a, b) {
sortedTags: sort('filteredTags', function (a, b) {
let idA = +a.get('id');
let idB = +b.get('id');

View File

@ -1,5 +1,6 @@
/* eslint-disable ghost/ember/alias-model-in-controller */
import Controller from '@ember/controller';
import {computed} from '@ember/object';
import {inject as service} from '@ember/service';
import {sort} from '@ember/object/computed';
@ -21,10 +22,14 @@ export default Controller.extend({
this.userOrder = ['name', 'email'];
},
sortedInvites: sort('invites', 'inviteOrder'),
sortedInvites: sort('filteredInvites', 'inviteOrder'),
sortedActiveUsers: sort('activeUsers', 'userOrder'),
sortedSuspendedUsers: sort('suspendedUsers', 'userOrder'),
filteredInvites: computed('invites.@each.isNew', function () {
return this.get('invites').filterBy('isNew', false);
}),
actions: {
toggleInviteUserModal() {
this.toggleProperty('showInviteUserModal');

View File

@ -34,12 +34,12 @@ export default AuthenticatedRoute.extend(CurrentUserSettings, ShortcutsRoute, {
// pausing to show the loading spinner if no tags have been loaded yet
model() {
let promise = this.store.query('tag', {limit: 'all', include: 'count.posts'});
let filter = this.store.filter('tag', tag => !tag.get('isNew'));
let tags = this.store.peekAll('tag');
if (this.store.peekAll('tag').get('length') === 0) {
return promise.then(() => filter);
return promise.then(() => tags);
} else {
return filter;
return tags;
}
},

View File

@ -31,7 +31,7 @@ export default AuthenticatedRoute.extend(styleBody, CurrentUserSettings, Infinit
// authors do not have permission to hit the invites or suspended users endpoint
if (!user.get('isAuthorOrContributor')) {
modelPromises.invites = this.store.query('invite', {limit: 'all'})
.then(() => this.store.filter('invite', invite => !invite.get('isNew')));
.then(() => this.store.peekAll('invite'));
// fetch suspended users separately so that infinite scroll still works
modelPromises.suspendedUsers = this.store.query('user', {limit: 'all', filter: 'status:inactive'});

View File

@ -69,7 +69,6 @@
"ember-composable-helpers": "2.1.0",
"ember-concurrency": "0.8.17",
"ember-data": "3.1.1",
"ember-data-filter": "1.13.0",
"ember-drag-drop": "0.4.7",
"ember-element-resize-detector": "0.1.5",
"ember-export-application-global": "2.0.0",

View File

@ -3333,7 +3333,7 @@ ember-cli-babel@6.12.0, ember-cli-babel@^6.0.0, ember-cli-babel@^6.0.0-beta.10,
ember-cli-version-checker "^2.1.0"
semver "^5.4.1"
ember-cli-babel@^5.0.0, ember-cli-babel@^5.1.5, ember-cli-babel@^5.1.6, ember-cli-babel@^5.1.7, ember-cli-babel@^5.2.4:
ember-cli-babel@^5.1.5, ember-cli-babel@^5.1.6, ember-cli-babel@^5.1.7, ember-cli-babel@^5.2.4:
version "5.2.8"
resolved "https://registry.yarnpkg.com/ember-cli-babel/-/ember-cli-babel-5.2.8.tgz#0356b03cc3fdff5d0f2ecaa46a0e1cfaebffd876"
dependencies:
@ -3824,12 +3824,6 @@ ember-cookies@^0.3.0:
ember-cli-babel "^6.8.2"
ember-getowner-polyfill "^1.1.0 || ^2.0.0"
ember-data-filter@1.13.0:
version "1.13.0"
resolved "https://registry.yarnpkg.com/ember-data-filter/-/ember-data-filter-1.13.0.tgz#54f9d54706d8ff61e9f0522660c86ec8de34def1"
dependencies:
ember-cli-babel "^5.0.0"
ember-data@3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/ember-data/-/ember-data-3.1.1.tgz#8c17c97a4932b0a0a405cc3e38c43140880366d2"