-
Notifications
You must be signed in to change notification settings - Fork 59
improvement(example): Move Auth0Provider plumbing out of example.js a… #175
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
improvement(example): Move Auth0Provider plumbing out of example.js a… #175
Conversation
…nd to ConnectedRouter.
Codecov Report
@@ Coverage Diff @@
## add-trip-rq-history #175 +/- ##
======================================================
- Coverage 9.94% 9.91% -0.04%
======================================================
Files 117 117
Lines 4131 4144 +13
Branches 1095 1101 +6
======================================================
Hits 411 411
- Misses 3224 3237 +13
Partials 496 496
Continue to review full report at Codecov.
|
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.
This approach feels better to me. See comments about moving utils to actions and renaming some things.
lib/util/auth.js
Outdated
| * @param dispatch The dispatch method to carry out the actions. | ||
| */ | ||
| export function getAuth0Callbacks (reduxStore) { | ||
| export function getAuth0Callbacks (dispatch) { |
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.
These callbacks are effectively actions, right? I feel like there are some gymnastics happening to try to make everything a util function instead of an action. I don't really like the idea of passing dispatch from the component as a param here. I think this is a spot where things could be simplified by making these actions and connecting them in mapDispatchToProps. Conventions exist for a reason: we do things in a common predictable way so that the app can be navigated easily by the rest of the team. Also, I don't think we need to combine them all into a getAuth0Callbacks function.
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.
Sample code legacy...
| const { dispatch, persistence, routerConfig } = this.props | ||
| // Initialize Auth0Provider in this component so it is available everywhere. | ||
| const auth0Config = getAuth0Config(persistence) | ||
| const auth0Callbacks = getAuth0Callbacks(dispatch) |
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.
As mentioned in another comment, these callbacks should be connected to the component as actions.
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.
Good point. Very good point.
| domain={auth0Config.domain} | ||
| clientId={auth0Config.clientId} | ||
| redirectUri={URL_ROOT} | ||
| {...auth0Callbacks} |
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.
Please avoid spreading these props. There's only three of them and our goal should be readable, maintainable code.
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.
This and turning the auth0 callbacks into actions are addressed in 0cf1737.
lib/components/app/app-nav.js
Outdated
| <div | ||
| className={`icon-${branding}`} | ||
| // This style is applied here because it is only intended for | ||
| // desktop view. |
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.
Not sure this comment is necessary since this file is only intended for Desktop use as far as I can tell.
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.
At some point we'll have to figure out combining this and the mobile navigation bar.
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.
Looks great! Just a couple of minor comments that need addressing. Also, it looks like the build is failing.
lib/components/app/desktop-nav.js
Outdated
| * The desktop navigation bar, featuring a sign-in button/menu. | ||
| * TODO: merge with the mobile navigation bar. | ||
| */ | ||
| const DesktopNav = ({ otpConfig, title }) => { |
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.
I'm still a little confused as to why there is a title prop. Shouldn't this be taking the title from otpConfig?
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.
I don't know! OpenTripPlanner was hardcoded as title before, and trimet-mod-otp implementations don't use a title at all, so I was trying to accommodate both.
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.
OK, so previously example.js just had a very barebones navbar and was just serving as an example for how to piece together otp-react-redux components within a web frame. However, now that we have otp-ui, I think it's OK for example.js to change from that original purpose somewhat. That's all just backstory to give you a little more context. It looks like the goal here is to make this DesktopNav available to trimet-mod-otp, right? So, in that case, we basically only want one or the other between branding and title, right? So, keep the title prop, but do not have a defaultValue. If titleis missing, usebrandingif it's available. If both are missing just useOpenTripPlanner`. But please (!) add some comments explaining this stuff.
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.
Using title from otpConfig in bb9f9e8.
lib/actions/auth.js
Outdated
| /** | ||
| * This function is called by the Auth0Provider component, with the described parameter(s), | ||
| * after the user signs in. | ||
| * @param {Error} err |
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.
copy pasta param?
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.
Pasta is sticky...
lib/actions/auth.js
Outdated
| // Here, we save the URL hash prior to login (contains a combination of itinerary search, stop/trip view, etc.), | ||
| // so that the AfterLoginScreen can redirect back there when logged-in user info is fetched. | ||
| // (For routing, it is easier to deal with the path without the hash sign.) | ||
| const urlHashWithoutHash = (appState.urlHash.split('#')[1] || '/') |
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.
Is it possible for the split to yield an array of length = 1? I'm wondering if it's risky to try to access the second element (for fear of array out of index error). Is a better string operation to use here appState.urlHash.replace('#', '')?
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.
I agree it'd be good to avoid array index out of bounds exceptions, although, I think a brute force replacement of the hash character isn't nuanced enough.
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.
Using substring instead of array.split in bb9f9e8.
evansiroky
left a comment
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.
What Landon said. 😆
landonreed
left a comment
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.
This looks great, @binh-dam-ibigroup. Thanks for all the work on this.
|
🎉 This PR is included in version 1.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This pull request addresses this comment: #167 (comment) and moves the plumbing to set up
Auth0Providerto theConnectedRoutercomponent.