Skip to content
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

Merged
merged 32 commits into from
Aug 13, 2018
Merged

UI: Region Switcher #4572

merged 32 commits into from
Aug 13, 2018

Conversation

DingoEatingFuzz
Copy link
Contributor

The UI now supports multi-region Nomad clusters 🎉

It works by providing the region= query param to every API request and on every page URL when the active region isn't the region of the server the UI is served from.

Reviewer notes: This has been an uphill battle against ember's handling of query params and ember data's handling of emptying the store.

image

image

image

This is incredibly tricky with query params, since there is a bundle of
timing issues, lifecycle issues, missing features, and all around
gotchas with query params.

This solution has no observers and no instances of the system service
being set from the jobs controller.

The upside to this is no observers, much easier to follow logic, no more
dependent key chain reactions.
Default params don't make it into arguments which were being splatted
into the call to super.
The default region shouldn't be used as a qp since no qp means the same
thing.
This protects against volatility in the server and, more commonly, ACLs
returning forbidden responses.
The UI will no longer try to redirect to the appropriate namespace or
region if one is found in localStorage. Instead, it will assume that
the lack of query param means the default namespaces or region is
desired.
Without this, the data (query params) get json stringified
@DingoEatingFuzz DingoEatingFuzz requested a review from a team August 10, 2018 18:30
@captainill
Copy link
Member

Looks great visually. The way you've handled in the tablet/mobile menu is 👌too.

Copy link

@alisdair alisdair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good read. Seems clear to me!

},

// setupController doesn't refire when the model hook refires as part of
// a query param change

Choose a reason for hiding this comment

The 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 setupController fires on entering the route, and when model returns a truthy value.

If you had a trivial model hook, maybe that would cause setupController to fire?

model(params) {
  return params.region;
},

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Innnnterresting. I'll give it a try.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works 🙌

import { namespace } from '../adapters/application';

// When the request isn't ok (e.g., forbidden) handle gracefully
const jsonWithDefault = defaultResponse => res =>
res.ok ? res.json() : copy(defaultResponse, true);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👌

return null;
},
set(key, value) {
if (value == null) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this loose equality intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, to be truthy for undefined as well.

@@ -2,6 +2,7 @@ import config from 'nomad-ui/config/environment';

const withNamespaces = getConfigValue('mirageWithNamespaces', false);
const withTokens = getConfigValue('mirageWithTokens', true);
const withRegions = getConfigValue('mirageWithRegions', false);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to add this setting to config/environment.js alongside the other Mirage options?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, definitely. I added it locally, but I so rarely check in changes to the environment file that I forgot I had changes worth committing. Good spot.

});

function forwardNamespace(source, destination) {
return observer(source, `${source}.id`, function() {

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:

👍

Copy link
Contributor Author

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 😅

@DingoEatingFuzz DingoEatingFuzz merged commit 3fd11d4 into master Aug 13, 2018
@DingoEatingFuzz DingoEatingFuzz deleted the f-ui-region-switcher branch August 13, 2018 23:33
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants