Add quick filter for contribution kind

This commit is contained in:
2019-07-06 16:16:28 +02:00
parent abb7d95804
commit edd7ffd3c5
5 changed files with 42 additions and 14 deletions
+13 -5
View File
@@ -9,6 +9,11 @@ export default Component.extend({
tagName: 'div', tagName: 'div',
classNames: ['contributions'], classNames: ['contributions'],
showQuickFilter: false,
hideSmallContributions: false,
contributorId: null,
contributionKind: null,
kredits: service(), kredits: service(),
contributorsSorting: Object.freeze(['name:asc']), contributorsSorting: Object.freeze(['name:asc']),
@@ -23,11 +28,11 @@ export default Component.extend({
}); });
}), }),
showQuickFilter: false, contributionKinds: computed('contributions.[]', function() {
hideSmallContributions: false, return this.contributions.mapBy('kind').uniq();
contributorId: null, }),
contributionsFiltered: computed('contributions.[]', 'hideSmallContributions', 'contributorId', function() { contributionsFiltered: computed('contributions.[]', 'hideSmallContributions', 'contributorId', 'contributionKind', function() {
return this.contributions.filter(c => { return this.contributions.filter(c => {
let included = true; let included = true;
@@ -35,7 +40,10 @@ export default Component.extend({
c.amount <= 500) { included = false; } c.amount <= 500) { included = false; }
if (isPresent(this.contributorId) && if (isPresent(this.contributorId) &&
(c.contributorId.toString() !== this.contributorId.toString())) { included = false; } c.contributorId.toString() !== this.contributorId.toString()) { included = false; }
if (isPresent(this.contributionKind) &&
c.kind !== this.contributionKind) { included = false; }
return included; return included;
}); });
@@ -11,6 +11,16 @@
</select> </select>
</label> </label>
<label class="filter-contribution-kind">
Kind:
<select onchange={{action (mut contributionKind) value="target.value"}}>
<option value="" selected>all</option>
{{#each contributionKinds as |kind|}}
<option value={{kind}} selected={{eq contributionKind kind}}>{{capitalize-string kind}}</option>
{{/each}}
</select>
</label>
<label class="filter-contribution-size"> <label class="filter-contribution-size">
{{input type="checkbox" checked=hideSmallContributions}} {{input type="checkbox" checked=hideSmallContributions}}
Hide small contributions Hide small contributions
+7
View File
@@ -0,0 +1,7 @@
import Helper from '@ember/component/helper';
export default Helper.extend({
compute([string]) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
});
+9 -9
View File
@@ -3,15 +3,15 @@ import Model from 'kredits-web/models/contribution';
const items = []; const items = [];
const data = [ const data = [
{ id: 1, contributorId: 1, confirmedAtBlock: 1000, claimed: false, vetoed: false, amount: 1500 }, { id: 1, contributorId: 1, confirmedAtBlock: 1000, claimed: false, vetoed: false, amount: 1500, kind: 'dev' },
{ id: 2, contributorId: 1, confirmedAtBlock: 1000, claimed: false, vetoed: false, amount: 5000 }, { id: 2, contributorId: 1, confirmedAtBlock: 1000, claimed: false, vetoed: false, amount: 5000, kind: 'ops' },
{ id: 3, contributorId: 2, confirmedAtBlock: 1000, claimed: false, vetoed: false, amount: 1500 }, { id: 3, contributorId: 2, confirmedAtBlock: 1000, claimed: false, vetoed: false, amount: 1500, kind: 'ops' },
{ id: 4, contributorId: 2, confirmedAtBlock: 1000, claimed: false, vetoed: false, amount: 1500 }, { id: 4, contributorId: 2, confirmedAtBlock: 1000, claimed: false, vetoed: false, amount: 1500, kind: 'docs' },
{ id: 5, contributorId: 1, confirmedAtBlock: 1000, claimed: false, vetoed: false, amount: 5000 }, { id: 5, contributorId: 1, confirmedAtBlock: 1000, claimed: false, vetoed: false, amount: 5000, kind: 'design' },
{ id: 6, contributorId: 1, confirmedAtBlock: 1000, claimed: false, vetoed: true, amount: 500 }, { id: 6, contributorId: 1, confirmedAtBlock: 1000, claimed: false, vetoed: true, amount: 500, kind: 'dev' },
{ id: 7, contributorId: 3, confirmedAtBlock: 2000, claimed: false, vetoed: false, amount: 5000 }, { id: 7, contributorId: 3, confirmedAtBlock: 2000, claimed: false, vetoed: false, amount: 5000, kind: 'dev' },
{ id: 8, contributorId: 1, confirmedAtBlock: 2000, claimed: false, vetoed: false, amount: 1500 }, { id: 8, contributorId: 1, confirmedAtBlock: 2000, claimed: false, vetoed: false, amount: 1500, kind: 'community' },
{ id: 9, contributorId: 3, confirmedAtBlock: 2000, claimed: false, vetoed: true, amount: 1500 }, { id: 9, contributorId: 3, confirmedAtBlock: 2000, claimed: false, vetoed: true, amount: 1500, kind: 'docs' },
]; ];
data.forEach(attrs => items.push(Model.create(attrs))); data.forEach(attrs => items.push(Model.create(attrs)));
@@ -27,5 +27,8 @@ module('Integration | Component | contribution-list', function(hooks) {
await click('.filter-contribution-size input'); await click('.filter-contribution-size input');
assert.equal(this.element.querySelectorAll('li').length, 4, 'hide small contributions'); assert.equal(this.element.querySelectorAll('li').length, 4, 'hide small contributions');
await fillIn('.filter-contribution-kind select', 'dev');
assert.equal(this.element.querySelectorAll('li').length, 1, 'select kind');
}); });
}); });