From e28a96097082f38377ce93c7bb688babc1e20d4b Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Mon, 30 Apr 2018 13:54:09 +0100 Subject: [PATCH] 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 --- .../app/components/gh-psm-authors-input.js | 17 ++++++++++++----- ghost/admin/app/components/gh-psm-tags-input.js | 15 +++++++++++---- ghost/admin/app/controllers/settings/tags.js | 7 ++++++- ghost/admin/app/controllers/team/index.js | 7 ++++++- ghost/admin/app/routes/settings/tags.js | 6 +++--- ghost/admin/app/routes/team/index.js | 2 +- ghost/admin/package.json | 1 - ghost/admin/yarn.lock | 8 +------- 8 files changed, 40 insertions(+), 23 deletions(-) diff --git a/ghost/admin/app/components/gh-psm-authors-input.js b/ghost/admin/app/components/gh-psm-authors-input.js index a32173004a..092ad71e4b 100644 --- a/ghost/admin/app/components/gh-psm-authors-input.js +++ b/ghost/admin/app/components/gh-psm-authors-input.js @@ -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); diff --git a/ghost/admin/app/components/gh-psm-tags-input.js b/ghost/admin/app/components/gh-psm-tags-input.js index a1d4aeef0a..5fdf17a3de 100644 --- a/ghost/admin/app/components/gh-psm-tags-input.js +++ b/ghost/admin/app/components/gh-psm-tags-input.js @@ -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(); diff --git a/ghost/admin/app/controllers/settings/tags.js b/ghost/admin/app/controllers/settings/tags.js index 2c8486e748..9d7d809967 100644 --- a/ghost/admin/app/controllers/settings/tags.js +++ b/ghost/admin/app/controllers/settings/tags.js @@ -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'); diff --git a/ghost/admin/app/controllers/team/index.js b/ghost/admin/app/controllers/team/index.js index f5e3030de2..e7426207f8 100644 --- a/ghost/admin/app/controllers/team/index.js +++ b/ghost/admin/app/controllers/team/index.js @@ -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'); diff --git a/ghost/admin/app/routes/settings/tags.js b/ghost/admin/app/routes/settings/tags.js index a392285c64..a7634da3ef 100644 --- a/ghost/admin/app/routes/settings/tags.js +++ b/ghost/admin/app/routes/settings/tags.js @@ -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; } }, diff --git a/ghost/admin/app/routes/team/index.js b/ghost/admin/app/routes/team/index.js index 4d704f0437..2b21aaa5c0 100644 --- a/ghost/admin/app/routes/team/index.js +++ b/ghost/admin/app/routes/team/index.js @@ -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'}); diff --git a/ghost/admin/package.json b/ghost/admin/package.json index 6b13b524f6..011163b046 100644 --- a/ghost/admin/package.json +++ b/ghost/admin/package.json @@ -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", diff --git a/ghost/admin/yarn.lock b/ghost/admin/yarn.lock index 6071d9d52b..a64fd7e85f 100644 --- a/ghost/admin/yarn.lock +++ b/ghost/admin/yarn.lock @@ -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"