From 8ca806f8f8eb326a52c44f3ef13378106b91fad1 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Mon, 13 Aug 2018 16:18:06 -0700 Subject: [PATCH] Use the model hook and setupController hook instead of afterModel This is a more idiomatic way to handle the QP resetting in the application controller. --- ui/app/routes/application.js | 15 ++++++++------- ui/tests/acceptance/regions-test.js | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ui/app/routes/application.js b/ui/app/routes/application.js index 6119eb4ce..477d30c49 100644 --- a/ui/app/routes/application.js +++ b/ui/app/routes/application.js @@ -46,14 +46,15 @@ export default Route.extend({ ); }, - // setupController doesn't refire when the model hook refires as part of - // a query param change - afterModel(model, transition) { - const queryParam = transition.queryParams.region; - const controller = this.controllerFor('application'); + // Model is being used as a way to transfer the provided region + // query param to update the controller state. + model(params) { + return params.region; + }, + + setupController(controller, model) { + const queryParam = model; - // The default region shouldn't show up as a query param since - // it's superfluous. if (queryParam === this.get('system.defaultRegion.region')) { next(() => { controller.set('region', null); diff --git a/ui/tests/acceptance/regions-test.js b/ui/tests/acceptance/regions-test.js index 9fae4d6a3..2a392eed1 100644 --- a/ui/tests/acceptance/regions-test.js +++ b/ui/tests/acceptance/regions-test.js @@ -137,7 +137,7 @@ test('switching regions to the default region, unsets the region query param', f selectChoose('[data-test-region-switcher]', defaultRegion); andThen(() => { - assert.equal(currentURL(), '/jobs', 'No region query param for the default region'); + assert.notOk(currentURL().includes('region='), 'No region query param for the default region'); assert.equal( window.localStorage.nomadActiveRegion, defaultRegion,