Add check that active summary isn’t filtered out

This commit is contained in:
Buck Doyle
2020-11-09 11:47:54 -06:00
parent 20d32fd101
commit 3206e97064
3 changed files with 32 additions and 1 deletions

View File

@@ -179,6 +179,20 @@ export default class OptimizeController extends Controller {
@action
setFacetQueryParam(queryParam, selection) {
this[queryParam] = serialize(selection);
this.ensureActiveSummaryIsNotExcluded();
}
@action
ensureActiveSummaryIsNotExcluded() {
scheduleOnce('actions', () => {
if (!this.filteredSummaries.includes(this.activeRecommendationSummary)) {
const firstFilteredSummary = this.filteredSummaries.objectAt(0);
if (firstFilteredSummary) {
this.transitionToSummary(firstFilteredSummary);
}
}
});
}
}

View File

@@ -6,6 +6,7 @@
{{#if @model}}
<SearchBox
data-test-recommendation-summaries-search
@onChange={{this.ensureActiveSummaryIsNotExcluded}}
@searchTerm={{mut this.searchTerm}}
@placeholder="Search {{this.model.length}} {{pluralize "recommendation" this.model.length}}..." />
{{/if}}

View File

@@ -366,7 +366,18 @@ module('Acceptance | optimize search and facets', function(hooks) {
window.localStorage.nomadTokenSecret = managementToken.secretId;
});
test('search field narrows summary table results and displays a no matches message when there are none', async function(assert) {
test('search field narrows summary table results, changes the active summary if it no longer matches, and displays a no matches message when there are none', async function(assert) {
server.createList('job', 1, {
name: 'zzzzzz',
createRecommendations: true,
groupsCount: 1,
groupTaskCount: 6,
});
// Ensure this jobs recommendations are sorted to the top of the table
const futureSubmitTime = (Date.now() + 10000) * 1000000;
server.db.recommendations.update({ submitTime: futureSubmitTime });
server.createList('job', 1, {
name: 'oooooo',
createRecommendations: true,
@@ -383,6 +394,8 @@ module('Acceptance | optimize search and facets', function(hooks) {
await Optimize.visit();
assert.equal(Optimize.card.slug.jobName, 'zzzzzz');
assert.equal(Optimize.search.placeholder, `Search ${Optimize.recommendationSummaries.length} recommendations...`);
await Optimize.search.fillIn('ooo');
@@ -390,6 +403,9 @@ module('Acceptance | optimize search and facets', function(hooks) {
assert.equal(Optimize.recommendationSummaries.length, 2);
assert.ok(Optimize.recommendationSummaries[0].slug.startsWith('oooooo'));
assert.equal(Optimize.card.slug.jobName, 'oooooo');
assert.ok(currentURL().includes('oooooo'));
await Optimize.search.fillIn('qqq');
assert.notOk(Optimize.card.isPresent);