-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UI: Region Switcher #4572
UI: Region Switcher #4572
Changes from 30 commits
ccae1fb
dc1a031
27308a8
200b3c3
2e26a61
840069d
8d36ac8
8c3e5b2
47210b3
3f26214
610db7c
95fcbda
d77504c
134ab34
7e6f02d
4715696
a5da73d
61bdc3b
4473bb9
c5439df
d690709
ae0bf90
fe315fe
822d998
b767a87
362aff0
c55df8f
dbc18c9
ae464a0
95e8259
3192267
a61ad7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import Component from '@ember/component'; | ||
|
||
export default Component.extend({ | ||
'data-test-global-header': true, | ||
|
||
onHamburgerClick() {}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Component from '@ember/component'; | ||
import { computed } from '@ember/object'; | ||
import { inject as service } from '@ember/service'; | ||
|
||
export default Component.extend({ | ||
system: service(), | ||
router: service(), | ||
store: service(), | ||
|
||
sortedRegions: computed('system.regions', function() { | ||
return this.get('system.regions') | ||
.toArray() | ||
.sort(); | ||
}), | ||
|
||
gotoRegion(region) { | ||
this.get('router').transitionTo('jobs', { | ||
queryParams: { region }, | ||
}); | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,68 @@ | ||
import { inject as service } from '@ember/service'; | ||
import { next } from '@ember/runloop'; | ||
import Route from '@ember/routing/route'; | ||
import { AbortError } from 'ember-data/adapters/errors'; | ||
import RSVP from 'rsvp'; | ||
|
||
export default Route.extend({ | ||
config: service(), | ||
system: service(), | ||
store: service(), | ||
|
||
queryParams: { | ||
region: { | ||
refreshModel: true, | ||
}, | ||
}, | ||
|
||
resetController(controller, isExiting) { | ||
if (isExiting) { | ||
controller.set('error', null); | ||
} | ||
}, | ||
|
||
beforeModel(transition) { | ||
return RSVP.all([this.get('system.regions'), this.get('system.defaultRegion')]).then( | ||
promises => { | ||
if (!this.get('system.shouldShowRegions')) return promises; | ||
|
||
const queryParam = transition.queryParams.region; | ||
const defaultRegion = this.get('system.defaultRegion.region'); | ||
const currentRegion = this.get('system.activeRegion') || defaultRegion; | ||
|
||
// Only reset the store if the region actually changed | ||
if ( | ||
(queryParam && queryParam !== currentRegion) || | ||
(!queryParam && currentRegion !== defaultRegion) | ||
) { | ||
this.get('system').reset(); | ||
this.get('store').unloadAll(); | ||
} | ||
|
||
this.set('system.activeRegion', queryParam || defaultRegion); | ||
|
||
return promises; | ||
} | ||
); | ||
}, | ||
|
||
// setupController doesn't refire when the model hook refires as part of | ||
// a query param change | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😳 Is that because the model hook is missing from this route? My understanding of the rule was that If you had a trivial model hook, maybe that would cause model(params) {
return params.region;
}, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Innnnterresting. I'll give it a try. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It works 🙌 |
||
afterModel(model, transition) { | ||
const queryParam = transition.queryParams.region; | ||
const controller = this.controllerFor('application'); | ||
|
||
// 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); | ||
}); | ||
} | ||
|
||
return this._super(...arguments); | ||
}, | ||
|
||
actions: { | ||
didTransition() { | ||
if (!this.get('config.isTest')) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It didn't make it all the way through the branch, but I just wanted to throw out a 👍 for the
afterSetup
route hook approach you originally took to replace this observer:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which one was that? I have already suppressed all memories of this code 😅