Added <GhMembersFilterCount @filter="..." />

no issue

- added generic members filter component
- updated `<GhRecipientFilterCount />` to use the new generic component with `subscribed:true` added to the filter
This commit is contained in:
Kevin Ansfield 2021-06-11 12:19:44 +01:00
parent 937eac51ad
commit 9adfad67d2
5 changed files with 31 additions and 31 deletions

View File

@ -0,0 +1 @@
{{this.memberCount}}

View File

@ -0,0 +1,23 @@
import Component from '@glimmer/component';
import {inject as service} from '@ember/service';
import {task} from 'ember-concurrency-decorators';
import {tracked} from '@glimmer/tracking';
export default class GhMembersFilterCountComponent extends Component {
@service membersCountCache;
@tracked memberCount;
constructor() {
super(...arguments);
this.getMembersCountTask.perform();
}
@task
*getMembersCountTask() {
this.memberCount = yield this.membersCountCache.countString(
this.args.filter,
{knownCount: this.args.knownCount}
);
}
}

View File

@ -1 +1,5 @@
{{this.recipientCount}}
{{#if @filter}}
<GhMembersFilterCount @filter={{concat "subscribed:true+(" @filter ")"}} @knownCount={{@knownCount}} />
{{else}}
no members
{{/if}}

View File

@ -1,28 +0,0 @@
import Component from '@glimmer/component';
import {inject as service} from '@ember/service';
import {task} from 'ember-concurrency-decorators';
import {tracked} from '@glimmer/tracking';
export default class GhRecipientFilterCountComponent extends Component {
@service membersCountCache;
@tracked recipientCount;
constructor() {
super(...arguments);
this.getRecipientCountTask.perform();
}
@task
*getRecipientCountTask() {
if (!this.args.filter) {
this.recipientCount = 'no members';
return;
}
this.recipientCount = yield this.membersCountCache.countString(
`subscribed:true+(${this.args.filter})`,
{knownCount: this.args.knownCount}
);
}
}

View File

@ -24,14 +24,14 @@ export default class MembersCountCacheService extends Service {
return count;
}
async countString(filter, {knownCount} = {}) {
async countString(filter = '', {knownCount} = {}) {
const user = await this.session.user;
const basicFilter = filter.replace(/^subscribed:true\+\((.*)\)$/, '$1');
const filterParts = basicFilter.split(',');
const isFree = filterParts.length === 1 && filterParts[0] === 'status:free';
const isPaid = filterParts.length === 1 && filterParts[0] === 'status:-free';
const isAll = filterParts.includes('status:free') && filterParts.includes('status:-free');
const isAll = !filter || (filterParts.includes('status:free') && filterParts.includes('status:-free');)
// editors don't have permission to browse members so can't retrieve a count
// TODO: remove when editors have relevant permissions or we have a different way of fetching counts