Skip to content

Commit

Permalink
Use the model hook and setupController hook instead of afterModel
Browse files Browse the repository at this point in the history
This is a more idiomatic way to handle the QP resetting in the
application controller.
  • Loading branch information
DingoEatingFuzz committed Aug 13, 2018
1 parent 95e8259 commit 3192267
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions ui/app/routes/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ui/tests/acceptance/regions-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3192267

Please sign in to comment.