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 all commits
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
21 changes: 17 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: resultsGroupLabel('Jobs', jobResults, this.jobSearch.listSearched),
options: jobResults,
},
{
groupName: `Clients (${nodeResults.length})`,
groupName: resultsGroupLabel('Clients', nodeResults, this.nodeSearch.listSearched),
options: nodeResults,
},
];
Expand Down Expand Up @@ -179,3 +180,15 @@ class NodeSearch extends EmberObject.extend(Searchable) {
fuzzySearchEnabled = true;
includeFuzzySearchMatches = true;
}

function resultsGroupLabel(type, renderedResults, allResults) {
let countString;

if (renderedResults.length < allResults.length) {
countString = `showing ${renderedResults.length} of ${allResults.length}`;
} else {
countString = renderedResults.length;
}

return `${type} (${countString})`;
}
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 (showing 10 of 15)');
assert.equal(jobs.options.length, 10);
});
});
});

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

Expand Down