-
Notifications
You must be signed in to change notification settings - Fork 58
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
Upgrade react-router to v6 #3261
Conversation
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.
Overall LGTM, thanks for putting so much work into this! Just a couple questions and comments.
<ProtectedRoute | ||
requiredPermissions={appPermissions.people.canView} | ||
userPermissions={data.whoami.permissions} | ||
element={<ManagePatientsContainer />} |
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 wonder if it's worth defining this protected route as a variable, since it's repeated under the regular patients
route too.
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.
Yeah not a bad idea! The reason I had to duplicate this route is because v5 supported optional URL params like /patients/:pageNumber?
which would match both /patients
and /patients/1
, but v6 no longer supports that. Hence the need for two routes. But I will definitely DRY it up
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.
Soooo I tried to do this, and for some reason it broke the patients page. It kept throwing "The operation is insecure", and I couldn't figure out why 🤔 so I reverted for now.
element={ | ||
<ProtectedRoute | ||
requiredPermissions={appPermissions.settings.canView} | ||
userPermissions={data.whoami.permissions} |
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.
nit: we may want to extract this data.whoami.permissions out to a variable
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.
Same as above - moving to a shorter named const seemed to cause issues, so I reverted
@@ -31,11 +30,6 @@ const createTelemetryService = () => { | |||
enableAutoRouteTracking: true, | |||
loggingLevelTelemetry: 2, | |||
maxBatchInterval: 0, |
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.
Can you deploy this to one of the lower environments and double-check that the telemetry still works as anticipated?
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 call, I will do that today.
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.
Thanks! Can you let me know what the outcome was?
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.
<Redirect | ||
push | ||
to={{ | ||
pathname: `${window.location.pathname.split("/uac")[1]}/verify`, |
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.
so happy to see these gone!
@@ -108,6 +108,14 @@ const Header: React.FC<{}> = () => { | |||
); | |||
}; | |||
|
|||
const activeNavItem = "active-nav-item prime-nav-link"; |
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.
nice 👍
element={ | ||
<GuardedRoute auth={auth} element={<AoEPatientFormContainer />} /> | ||
} | ||
/> |
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 think we might be able to kill this route, AFAIK we removed the ability for patients to fill out the AoE.
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.
That's true, but I think @zdeveloper may be working on cleaning these routes out in another PR IIRC.
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.
thanks again for walking me through everything!
Kudos, SonarCloud Quality Gate passed! |
This reverts commit 46bb4cd.
Related Issue or Background Info
Changes Proposed
react-router-dom
to version6.2.1
. The major version upgrade from v5 to v6 introduced a number of breaking changes that touch a lot of different parts of the app. I followed this upgrade guide, making the following changes:match
prop down to child routes to access things like location and params. This is a huge improvement for code cleanliness!<Route component={SomeComponent}> />
now becomes<Route element={<SomeComponent />} />
, which allows us to easily pass props into routes! More info on the benefits of this herewithRouter
with hooks<Redirect>
components into<Navigate>
components<GuardedRoute>
and<ProtectedRoute>
components into ones that get passed into an element prop of a<Route />
, rather than returning a<Route />
component themselves. You can read a little more about why this change was made here.<Switch>
elements to<Routes>
- see here, but the new<Routes>
component allows relative routing!PatientApp
used to include an additional<Router>
component with abasename
prop so that we didn't have to prefix every route with/pxp
. With v6 that's no longer needed because<Route>
components can now be nested and the paths always include the parent route's path! The same goes for<Link>
and<Navigate>
components.<Route>
paths no longer need a leading slash, and can end in a wildcard*
to match all subpaths. More infouseHistory
touseNavigate
. More infouseHistory
is no longer available, we can't pass history into our Application Insights config. However, I don't think it was needed in the first place according to this comment. Since we haveenableAutoRouteTracking: true
set, it should already record any route changes automatically (see docs here)<Prompt>
component from this release in order to expedite the release. However, I was able to use a reimplementation found in this GH issue to keep that functionality since we use it in a couple places in the app. However, the team plans to readd it at some point, so I will keep an eye out and be sure to switch to the official API when it comes back.<MemoryRouter>
react-router
dependency. Thereact-router
package includes everything from bothreact-router-dom
andreact-router-native
, but we only usereact-router-dom
. Also updated all imports across the app to usereact-router-dom
REACT_APP_DISABLE_MAINTENANCE_BANNER
environment variable that disables the maintenance banner, because it was causing issues on the e2e tests./reload-app
route which just redirects back to/
. This allows us to retrigger thewhoami
query (for example after spoofing into an org) without actually refreshing the page and having to reload the bundle.Additional Information
<Outlet>
component (docs here). This would allow us to place all of our<Route>
components into a single tree inindex.tsx
, and then use the<Outlet>
component in<Route>
elements to refer to the child routes. This would be another big win for code cleanliness!Screenshots / Demos
Checklist for Author and Reviewer
Infrastructure
terraform-plan
job inside the "Terraform Checks" workflow run for this PR. Confirm that there are no unexpected changes!Design
test
,dev
, orpentest
and smoke-tested by both the engineering and design teamsContent
Support
Testing
Changes are Backwards Compatible
(including re-granting permission to the no-PHI user if need be)
./gradlew liquibaseRollbackSQL
orliquibaseRollback
Security
Cloud
test
,dev
, orpentest
environment for verification