Add redirect to parent when filter excludes all

This commit is contained in:
Buck Doyle 2020-11-10 09:38:46 -06:00
parent 7ed1f4dda8
commit 3ef7f9f89e
3 changed files with 15 additions and 2 deletions

View file

@ -182,6 +182,15 @@ export default class OptimizeController extends Controller {
this.ensureActiveSummaryIsNotExcluded(); this.ensureActiveSummaryIsNotExcluded();
} }
@action
transitionToFirstSummary() {
const firstFilteredSummary = this.filteredSummaries.objectAt(0);
if (firstFilteredSummary) {
this.transitionToSummary(firstFilteredSummary);
}
}
@action @action
ensureActiveSummaryIsNotExcluded() { ensureActiveSummaryIsNotExcluded() {
scheduleOnce('actions', () => { scheduleOnce('actions', () => {
@ -190,6 +199,8 @@ export default class OptimizeController extends Controller {
if (firstFilteredSummary) { if (firstFilteredSummary) {
this.transitionToSummary(firstFilteredSummary); this.transitionToSummary(firstFilteredSummary);
} else {
this.transitionToRoute('optimize');
} }
} }
}); });

View file

@ -1,8 +1,9 @@
import Route from '@ember/routing/route'; import Route from '@ember/routing/route';
export default class OptimizeIndexRoute extends Route { export default class OptimizeIndexRoute extends Route {
async redirect() { async activate() {
const summaries = this.modelFor('optimize'); // This runs late in the loading lifecycle to ensure .filteredSummaries is populated
const summaries = this.controllerFor('optimize').filteredSummaries;
if (summaries.length) { if (summaries.length) {
const firstSummary = summaries.objectAt(0); const firstSummary = summaries.objectAt(0);

View file

@ -411,6 +411,7 @@ module('Acceptance | optimize search and facets', function(hooks) {
assert.notOk(Optimize.card.isPresent); assert.notOk(Optimize.card.isPresent);
assert.ok(Optimize.empty.isPresent); assert.ok(Optimize.empty.isPresent);
assert.equal(Optimize.empty.headline, 'No Matches'); assert.equal(Optimize.empty.headline, 'No Matches');
assert.equal(currentURL(), '/optimize?search=qqq');
}); });
test('processing a summary moves to the next one in the sorted list', async function(assert) { test('processing a summary moves to the next one in the sorted list', async function(assert) {