From d67bfd59dae2656f0d9af60aeaa4c744bb23dc5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Sun, 16 Feb 2025 13:45:48 +0400 Subject: [PATCH 1/4] Hide contributors with 0 kredits in toplist --- app/controllers/dashboard.js | 5 +- app/templates/dashboard.hbs | 2 +- tests/unit/controllers/dashboard-test.js | 60 ++++++++++++------------ 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/app/controllers/dashboard.js b/app/controllers/dashboard.js index 0de990e..45e07a4 100644 --- a/app/controllers/dashboard.js +++ b/app/controllers/dashboard.js @@ -25,7 +25,10 @@ export default Controller.extend({ kreditsToplistSorting: computed('showUnconfirmedKredits', function(){ return this.showUnconfirmedKredits ? ['amountTotal:desc'] : ['amountConfirmed:desc']; }), - kreditsToplist: sort('kreditsByContributor', 'kreditsToplistSorting'), + kreditsToplist: computed('kreditsByContributor', function(){ + return this.kreditsByContributor.filter(c => c.amountTotal > 0); + }), + kreditsToplistSorted: sort('kreditsToplist', 'kreditsToplistSorting'), showUnconfirmedKredits: true, hideUnconfirmedKredits: not('showUnconfirmedKredits'), diff --git a/app/templates/dashboard.hbs b/app/templates/dashboard.hbs index 4f050af..6d10ddf 100644 --- a/app/templates/dashboard.hbs +++ b/app/templates/dashboard.hbs @@ -11,7 +11,7 @@ {{/if}}
- diff --git a/tests/unit/controllers/dashboard-test.js b/tests/unit/controllers/dashboard-test.js index fde691a..1d6ed63 100644 --- a/tests/unit/controllers/dashboard-test.js +++ b/tests/unit/controllers/dashboard-test.js @@ -1,29 +1,31 @@ -// import { isEmpty, isPresent } from '@ember/utils'; -// import { module, test } from 'qunit'; -// import { setupTest } from 'ember-qunit'; -// import Contributor from 'kredits-web/models/contributor'; -// -// module('Unit | Controller | index', function(hooks) { -// setupTest(hooks); -// -// let addFixtures = function(controller) { -// [ -// { github_username: "neo", github_uid: "318", totalKreditsEarned: 10000 }, -// { github_username: "morpheus", github_uid: "843", totalKreditsEarned: 15000 }, -// { github_username: "trinity", github_uid: "123", totalKreditsEarned: 5000 }, -// { github_username: "mouse", github_uid: "696", totalKreditsEarned: 0 } -// ].forEach(fixture => { -// controller.get('kredits.contributors').push(Contributor.create(fixture)); -// }); -// }; -// -// test('doesn\'t contain people with 0 balance', function(assert) { -// let controller = this.owner.lookup('controller:index'); -// addFixtures(controller); -// -// let contributorsSorted = controller.get('contributorsSorted'); -// -// assert.ok(isPresent(contributorsSorted.findBy('github_username', 'neo'))); -// assert.ok(isEmpty(contributorsSorted.findBy('github_username', 'mouse'))); -// }); -// }); +import { isEmpty } from '@ember/utils'; +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; +import Contributor from 'kredits-web/models/contributor'; + +module('Unit | Controller | Dashboard', function(hooks) { + setupTest(hooks); + + let addFixtures = function(controller) { + [ + { github_username: "neo", github_uid: "318", totalKreditsEarned: 10000 }, + { github_username: "morpheus", github_uid: "843", totalKreditsEarned: 15000 }, + { github_username: "trinity", github_uid: "123", totalKreditsEarned: 5000 }, + { github_username: "mouse", github_uid: "696", totalKreditsEarned: 0 } + ].forEach(fixture => { + controller.get('kredits.contributors').push(Contributor.create(fixture)); + }); + }; + + test('doesn\'t contain people with 0 balance', function(assert) { + const controller = this.owner.lookup('controller:dashboard'); + addFixtures(controller); + + const kreditsToplistSorted = controller.get('kreditsToplistSorted'); + + assert.equal(kreditsToplistSorted.length, 3, + 'kreditsToplist contains all contributors with kredits'); + assert.ok(isEmpty(kreditsToplistSorted.findBy('github_username', 'mouse')), + 'kreditsToplist does not contain contributors with 0 kredits'); + }); +}); From 636c79ecc7696421a238e53b6640828e6dcc8b9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Sun, 16 Feb 2025 13:52:58 +0400 Subject: [PATCH 2/4] Port component to native class --- app/components/contributor-list/component.js | 22 ++++++++------------ 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/app/components/contributor-list/component.js b/app/components/contributor-list/component.js index 3f72fb3..f39632b 100644 --- a/app/components/contributor-list/component.js +++ b/app/components/contributor-list/component.js @@ -1,18 +1,14 @@ -import Component from '@ember/component'; +import Component from '@glimmer/component'; +import { action } from '@ember/object'; import { inject as service } from '@ember/service'; -export default Component.extend({ - tagName: '', +export default class ContributorComponent extends Component { + @service router; - router: service(), - - selectedContributorId: null, - - actions: { - - openContributorDetails(contributor) { - this.router.transitionTo('dashboard.contributors.show', contributor); - } + selectedContributorId = null; + @action + openContributorDetails(contributor) { + this.router.transitionTo('dashboard.contributors.show', contributor); } -}); +} From 14da36b8064455636e65b2181c28d0f67f63dafe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Sun, 16 Feb 2025 14:21:51 +0400 Subject: [PATCH 3/4] Only show top 10 contributors by default Don't waste so much screen real estate. Add button to show all to the end of the toplist. --- app/components/contributor-list/component.js | 33 ++++++++++++++++++-- app/components/contributor-list/template.hbs | 9 +++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/app/components/contributor-list/component.js b/app/components/contributor-list/component.js index f39632b..925647e 100644 --- a/app/components/contributor-list/component.js +++ b/app/components/contributor-list/component.js @@ -1,14 +1,43 @@ import Component from '@glimmer/component'; import { action } from '@ember/object'; import { inject as service } from '@ember/service'; +import { tracked } from '@glimmer/tracking'; export default class ContributorComponent extends Component { @service router; - selectedContributorId = null; + @tracked selectedContributorId = null; + @tracked showToplistOnly = true; + + get contributorList () { + return this.args.contributorList; + } + + get contributorTop10 () { + return this.contributorList ? + this.contributorList.slice(0, 10) : []; + } + + get contributors () { + return this.showToplistOnly ? + this.contributorTop10 : this.contributorList; + } + + get hiddenContributorsAmount () { + return this.contributorList.length - 10; + } + + get showAllButtonText () { + return `Show ${this.hiddenContributorsAmount} more contributors`; + } @action - openContributorDetails(contributor) { + openContributorDetails (contributor) { this.router.transitionTo('dashboard.contributors.show', contributor); } + + @action + showAllContributors () { + this.showToplistOnly = false; + } } diff --git a/app/components/contributor-list/template.hbs b/app/components/contributor-list/template.hbs index 0f105d9..e51aee0 100644 --- a/app/components/contributor-list/template.hbs +++ b/app/components/contributor-list/template.hbs @@ -2,7 +2,7 @@ - {{#each @contributorList as |c|}} + {{#each this.contributors as |c|}} @@ -21,5 +21,12 @@ {{/each}} + {{#if this.showToplistOnly}} + + + {{this.showAllButtonText}} + + + {{/if}} From 62388a0488f7d62c6906feccedd89302c7781536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Mon, 17 Feb 2025 09:09:52 +0400 Subject: [PATCH 4/4] Improve test descriptions --- tests/unit/controllers/dashboard-test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/controllers/dashboard-test.js b/tests/unit/controllers/dashboard-test.js index 1d6ed63..050a998 100644 --- a/tests/unit/controllers/dashboard-test.js +++ b/tests/unit/controllers/dashboard-test.js @@ -17,15 +17,15 @@ module('Unit | Controller | Dashboard', function(hooks) { }); }; - test('doesn\'t contain people with 0 balance', function(assert) { + test('kreditsToplistSorted()', function(assert) { const controller = this.owner.lookup('controller:dashboard'); addFixtures(controller); const kreditsToplistSorted = controller.get('kreditsToplistSorted'); assert.equal(kreditsToplistSorted.length, 3, - 'kreditsToplist contains all contributors with kredits'); + 'contains all contributors with kredits'); assert.ok(isEmpty(kreditsToplistSorted.findBy('github_username', 'mouse')), - 'kreditsToplist does not contain contributors with 0 kredits'); + 'does not contain contributors with 0 kredits'); }); });