From 9ee66f8b85621d3d9640554434f11dee97ef3416 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Wed, 4 Aug 2021 12:20:34 +0530 Subject: [PATCH] Added filtering on members list via URL param refs https://github.com/TryGhost/Team/issues/942 - adds `?filter` param to members list page which allows directly filtering list via NQL filter syntax --- ghost/admin/app/controllers/members.js | 20 ++++++++++++++------ ghost/admin/app/routes/members.js | 3 ++- ghost/admin/app/templates/members.hbs | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/ghost/admin/app/controllers/members.js b/ghost/admin/app/controllers/members.js index 53112f1b20..56077e0054 100644 --- a/ghost/admin/app/controllers/members.js +++ b/ghost/admin/app/controllers/members.js @@ -37,12 +37,14 @@ export default class MembersController extends Controller { 'label', {paidParam: 'paid'}, {searchParam: 'search'}, - {orderParam: 'order'} + {orderParam: 'order'}, + {filterParam: 'filter'} ]; @tracked members = A([]); @tracked searchText = ''; @tracked searchParam = ''; + @tracked filterParam = ''; @tracked paidParam = null; @tracked label = null; @tracked orderParam = null; @@ -90,7 +92,7 @@ export default class MembersController extends Controller { } get showingAll() { - return !this.searchParam && !this.paidParam && !this.label; + return !this.searchParam && !this.paidParam && !this.label && !this.filterParam; } get availableOrders() { @@ -146,11 +148,11 @@ export default class MembersController extends Controller { } get isFiltered() { - return !!(this.label || this.paidParam || this.searchParam); + return !!(this.label || this.paidParam || this.searchParam || this.filterParam); } getApiQueryObject({params, extraFilters = []} = {}) { - let {label, paidParam, searchParam} = params ? params : this; + let {label, paidParam, searchParam, filterParam} = params ? params : this; let filters = []; @@ -168,6 +170,10 @@ export default class MembersController extends Controller { } } + if (filterParam) { + filters.push(filterParam); + } + let searchQuery = searchParam ? {search: searchParam} : {}; return Object.assign({}, {filter: filters.join('+')}, searchQuery); @@ -277,7 +283,7 @@ export default class MembersController extends Controller { @task({restartable: true}) *fetchMembersTask(params) { // params is undefined when called as a "refresh" of the model - let {label, paidParam, searchParam, orderParam} = typeof params === 'undefined' ? this : params; + let {label, paidParam, searchParam, orderParam, filterParam} = typeof params === 'undefined' ? this : params; if (!searchParam) { this.resetSearch(); @@ -291,11 +297,13 @@ export default class MembersController extends Controller { || label !== this._lastLabel || paidParam !== this._lastPaidParam || searchParam !== this._lastSearchParam - || orderParam !== this._orderParam; + || orderParam !== this._orderParam + || filterParam !== this._lastFilterParam; this._lastLabel = label; this._lastPaidParam = paidParam; this._lastSearchParam = searchParam; this._lastOrderParam = orderParam; + this._lastFilterParam = filterParam; // unless we have a forced reload, do not re-fetch the members list unless it's more than a minute old // keeps navigation between list->details->list snappy diff --git a/ghost/admin/app/routes/members.js b/ghost/admin/app/routes/members.js index ababd35707..e20a0af848 100644 --- a/ghost/admin/app/routes/members.js +++ b/ghost/admin/app/routes/members.js @@ -8,7 +8,8 @@ export default class MembersRoute extends AuthenticatedRoute { label: {refreshModel: true}, searchParam: {refreshModel: true, replace: true}, paidParam: {refreshModel: true}, - orderParam: {refreshModel: true} + orderParam: {refreshModel: true}, + filterParam: {refreshModel: true, replace: true} }; // redirect to posts screen if: diff --git a/ghost/admin/app/templates/members.hbs b/ghost/admin/app/templates/members.hbs index 67209b4e30..4405a5df8d 100644 --- a/ghost/admin/app/templates/members.hbs +++ b/ghost/admin/app/templates/members.hbs @@ -184,4 +184,4 @@ @close={{this.toggleLabelModal}} @modifier="action wide" /> -{{/if}} \ No newline at end of file +{{/if}}