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',
{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

View File

@ -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:

View File

@ -184,4 +184,4 @@
@close={{this.toggleLabelModal}}
@modifier="action wide"
/>
{{/if}}
{{/if}}