Skip to content

Conversation

@binh-dam-ibigroup
Copy link
Collaborator

This pull request addresses this comment: #167 (comment) and moves the plumbing to set up Auth0Provider to the ConnectedRouter component.

@codecov-commenter
Copy link

codecov-commenter commented Jun 15, 2020

Codecov Report

Merging #175 into add-trip-rq-history will decrease coverage by 0.03%.
The diff coverage is 0.00%.

Impacted file tree graph

@@                  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              
Impacted Files Coverage Δ
lib/components/app/app-nav.js 0.00% <0.00%> (ø)
lib/components/app/responsive-webapp.js 0.00% <0.00%> (ø)
lib/index.js 0.00% <0.00%> (ø)
lib/util/auth.js 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5f39e30...b7a04bc. Read the comment docs.

Copy link
Member

@landonreed landonreed left a 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) {
Copy link
Member

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.

Copy link
Collaborator Author

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)
Copy link
Member

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.

Copy link
Collaborator Author

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}
Copy link
Member

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.

Copy link
Collaborator Author

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.

<div
className={`icon-${branding}`}
// This style is applied here because it is only intended for
// desktop view.
Copy link
Member

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.

Copy link
Collaborator Author

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.

Copy link
Member

@landonreed landonreed left a 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.

* The desktop navigation bar, featuring a sign-in button/menu.
* TODO: merge with the mobile navigation bar.
*/
const DesktopNav = ({ otpConfig, title }) => {
Copy link
Member

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?

Copy link
Collaborator Author

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.

Copy link
Member

@landonreed landonreed Jun 19, 2020

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.

Copy link
Collaborator Author

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.

/**
* This function is called by the Auth0Provider component, with the described parameter(s),
* after the user signs in.
* @param {Error} err
Copy link
Member

Choose a reason for hiding this comment

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

copy pasta param?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Pasta is sticky...

// 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] || '/')
Copy link
Member

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('#', '')?

Copy link
Contributor

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.

Copy link
Collaborator Author

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.

Copy link
Contributor

@evansiroky evansiroky left a comment

Choose a reason for hiding this comment

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

What Landon said. 😆

@evansiroky evansiroky removed their assignment Jun 22, 2020
Copy link
Member

@landonreed landonreed left a 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.

@landonreed landonreed removed their assignment Jun 22, 2020
@binh-dam-ibigroup binh-dam-ibigroup merged commit ae3c44d into add-trip-rq-history Jun 22, 2020
@binh-dam-ibigroup binh-dam-ibigroup deleted the auth0provider-inside-router branch June 22, 2020 20:28
@landonreed
Copy link
Member

🎉 This PR is included in version 1.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants