Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: Add truncation of rendered search results #8571

Merged
merged 2 commits into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions ui/app/components/global-search/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Searchable from 'nomad-ui/mixins/searchable';
import classic from 'ember-classic-decorator';

const SLASH_KEY = 191;
const MAXIMUM_RESULTS = 10;

@classNames('global-search-container')
export default class GlobalSearchControl extends Component {
Expand Down Expand Up @@ -60,16 +61,16 @@ export default class GlobalSearchControl extends Component {
set(this, 'jobs', jobs.toArray());
set(this, 'nodes', nodes.toArray());

const jobResults = this.jobSearch.listSearched;
const nodeResults = this.nodeSearch.listSearched;
const jobResults = this.jobSearch.listSearched.slice(0, MAXIMUM_RESULTS);
const nodeResults = this.nodeSearch.listSearched.slice(0, MAXIMUM_RESULTS);

return [
{
groupName: `Jobs (${jobResults.length})`,
groupName: `Jobs (${this.jobSearch.listSearched.length})`,
options: jobResults,
},
{
groupName: `Clients (${nodeResults.length})`,
groupName: `Clients (${this.nodeSearch.listSearched.length})`,
options: nodeResults,
},
];
Expand Down
19 changes: 19 additions & 0 deletions ui/tests/acceptance/search-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,25 @@ module('Acceptance | search', function(hooks) {
});
});

test('results are truncated at 10 per group', async function(assert) {
server.create('node', { name: 'xyz' });

for (let i = 0; i < 15; i++) {
server.create('job', { id: `job-${i}`, namespaceId: 'default' });
}

await visit('/');

await selectSearch(PageLayout.navbar.search.scope, 'job');

PageLayout.navbar.search.as(search => {
search.groups[0].as(jobs => {
assert.equal(jobs.name, 'Jobs (15)');
assert.equal(jobs.options.length, 10);
});
});
});

test('clicking the search field starts search immediately', async function(assert) {
await visit('/');

Expand Down