Skip to content

Commit

Permalink
CC-6116: filter bar results text (#55)
Browse files Browse the repository at this point in the history
* Update filter-bar default results text

* Remove log
  • Loading branch information
WenInCode committed Aug 29, 2023
1 parent 9c6df91 commit 6fd15c9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/selfish-mice-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hashicorp/consul-ui-toolkit': patch
---

Update default `Cut::FilterBar` results text when no count is passed in.
23 changes: 17 additions & 6 deletions documentation/tests/integration/components/filter-bar-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,32 +327,43 @@ module('Integration | Component | cut/filter-bar', function (hooks) {
);
});

test('shows a default results text if no count is passed in', async function (assert) {
await setupTest.call(this);
test('shows a default results text if no count is passed in and no filters are selected', async function (assert) {
await setupTest.call(this, { config: {} });

assert.dom('[data-test-filter-bar-results]').hasText('Showing all results');
});

test('shows a default results text with the name if the name is passed in with no count', async function (assert) {
await setupTest.call(this, { name: 'nacho' });
await setupTest.call(this, { config: {}, name: 'nacho' });

assert.dom('[data-test-filter-bar-results]').hasText('Showing all nachos');
});

test('shows a default filters applied text when there are filters applied and no count is passed in', async function (assert) {
await setupTest.call(this, { name: 'nacho' });

assert.dom('[data-test-filter-bar-results]').hasText('Filters applied:');
});

test('shows a result count with a default text for the name if you pass in a count but no name', async function (assert) {
await setupTest.call(this, { count: 3 });
await setupTest.call(this, { config: {}, count: 3 });

assert.dom('[data-test-filter-bar-results]').hasText('Showing 3 results');
});

test('shows a result count with a name if you pass in a count and a name', async function (assert) {
await setupTest.call(this, { count: 1, name: 'song' });
await setupTest.call(this, { config: {}, count: 1, name: 'song' });

assert.dom('[data-test-filter-bar-results]').hasText('Showing 1 song');
});

test('shows a result count with a total if you pass in a total and a count', async function (assert) {
await setupTest.call(this, { count: 5, totalCount: 10, name: 'song' });
await setupTest.call(this, {
config: {},
count: 5,
totalCount: 10,
name: 'song',
});

assert
.dom('[data-test-filter-bar-results]')
Expand Down
2 changes: 2 additions & 0 deletions toolkit/src/components/cut/filter-bar/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
@totalCount
(concat ' of ' @totalCount)
}}
{{else if this.isFiltering}}
Filters applied:
{{else}}
Showing all
{{if @name (pluralize @name) 'results'}}
Expand Down
4 changes: 4 additions & 0 deletions toolkit/src/components/cut/filter-bar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ export default class FilterBarComponent extends Component<FilterBarSignature> {
return typeof this.args.count === 'number';
}

get isFiltering(): boolean {
return Object.keys(this.args.config?.filters || {}).length > 0;
}

isChecked(localConfig: FilterConfig, filter: string, value: unknown) {
if (Array.isArray(localConfig?.filters?.[filter])) {
return !!(localConfig?.filters?.[filter] as Filter[]).find(
Expand Down

1 comment on commit 6fd15c9

@vercel
Copy link

@vercel vercel bot commented on 6fd15c9 Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.