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
This commit is contained in:
Rishabh 2021-08-04 12:20:34 +05:30
parent cf6ef942a5
commit 9ee66f8b85
3 changed files with 17 additions and 8 deletions

View File

@ -37,12 +37,14 @@ export default class MembersController extends Controller {
'label', 'label',
{paidParam: 'paid'}, {paidParam: 'paid'},
{searchParam: 'search'}, {searchParam: 'search'},
{orderParam: 'order'} {orderParam: 'order'},
{filterParam: 'filter'}
]; ];
@tracked members = A([]); @tracked members = A([]);
@tracked searchText = ''; @tracked searchText = '';
@tracked searchParam = ''; @tracked searchParam = '';
@tracked filterParam = '';
@tracked paidParam = null; @tracked paidParam = null;
@tracked label = null; @tracked label = null;
@tracked orderParam = null; @tracked orderParam = null;
@ -90,7 +92,7 @@ export default class MembersController extends Controller {
} }
get showingAll() { get showingAll() {
return !this.searchParam && !this.paidParam && !this.label; return !this.searchParam && !this.paidParam && !this.label && !this.filterParam;
} }
get availableOrders() { get availableOrders() {
@ -146,11 +148,11 @@ export default class MembersController extends Controller {
} }
get isFiltered() { get isFiltered() {
return !!(this.label || this.paidParam || this.searchParam); return !!(this.label || this.paidParam || this.searchParam || this.filterParam);
} }
getApiQueryObject({params, extraFilters = []} = {}) { getApiQueryObject({params, extraFilters = []} = {}) {
let {label, paidParam, searchParam} = params ? params : this; let {label, paidParam, searchParam, filterParam} = params ? params : this;
let filters = []; let filters = [];
@ -168,6 +170,10 @@ export default class MembersController extends Controller {
} }
} }
if (filterParam) {
filters.push(filterParam);
}
let searchQuery = searchParam ? {search: searchParam} : {}; let searchQuery = searchParam ? {search: searchParam} : {};
return Object.assign({}, {filter: filters.join('+')}, searchQuery); return Object.assign({}, {filter: filters.join('+')}, searchQuery);
@ -277,7 +283,7 @@ export default class MembersController extends Controller {
@task({restartable: true}) @task({restartable: true})
*fetchMembersTask(params) { *fetchMembersTask(params) {
// params is undefined when called as a "refresh" of the model // 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) { if (!searchParam) {
this.resetSearch(); this.resetSearch();
@ -291,11 +297,13 @@ export default class MembersController extends Controller {
|| label !== this._lastLabel || label !== this._lastLabel
|| paidParam !== this._lastPaidParam || paidParam !== this._lastPaidParam
|| searchParam !== this._lastSearchParam || searchParam !== this._lastSearchParam
|| orderParam !== this._orderParam; || orderParam !== this._orderParam
|| filterParam !== this._lastFilterParam;
this._lastLabel = label; this._lastLabel = label;
this._lastPaidParam = paidParam; this._lastPaidParam = paidParam;
this._lastSearchParam = searchParam; this._lastSearchParam = searchParam;
this._lastOrderParam = orderParam; 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 // 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 // keeps navigation between list->details->list snappy

View File

@ -8,7 +8,8 @@ export default class MembersRoute extends AuthenticatedRoute {
label: {refreshModel: true}, label: {refreshModel: true},
searchParam: {refreshModel: true, replace: true}, searchParam: {refreshModel: true, replace: true},
paidParam: {refreshModel: true}, paidParam: {refreshModel: true},
orderParam: {refreshModel: true} orderParam: {refreshModel: true},
filterParam: {refreshModel: true, replace: true}
}; };
// redirect to posts screen if: // redirect to posts screen if: