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.
This commit is contained in:
parent
104e5196a6
commit
8ca806f8f8
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue