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

refactor(1576): Upgrade react-router packages and refactor related components #1506

Conversation

dependabot[bot]
Copy link

@dependabot dependabot bot commented on behalf of github Dec 20, 2021

Summary of Changes

This dependabot PR was co-opted for react-router upgrades and refactoring.

Pull request closes #1576

Acceptance criteria as stated in the issue

How to Test

List the steps to test the PR
These steps are generic, please adjust as necessary.

cd tdrs-frontend && docker-compose -f docker-compose.yml -f docker-compose.local.yml up -d
cd tdrs-backend && docker-compose -f docker-compose.yml -f docker-compose.local.yml up -d 
  1. Open http://localhost:3000/ and sign in.
  2. All functionality should remain unchanged.

Deliverables

More details on how deliverables herein are assessed included here.

Deliverable 1: Accepted Features

Checklist of ACs:

  • react-router and react-router-dom are ugraded to latest major version
  • package.json is updated
  • package-lock.json is updated
  • All existing behavior and application functionality should remain identical
  • Testing Checklist has been run and all tests pass
  • README is updated, if necessary
  • lfrohlich and/or adpennington confirmed that ACs are met.

Deliverable 2: Tested Code

  • Are all areas of code introduced in this PR meaningfully tested?
    • If this PR introduces backend code changes, are they meaningfully tested?
    • If this PR introduces frontend code changes, are they meaningfully tested?
  • Are code coverage minimums met?
    • Frontend coverage: [97.31%] (see CodeCov Report comment in PR)
    • Backend coverage: [insert coverage %] (see CodeCov Report comment in PR)

Deliverable 3: Properly Styled Code

  • Are backend code style checks passing on CircleCI?
  • Are frontend code style checks passing on CircleCI?
  • Are code maintainability principles being followed?

Deliverable 4: Accessible

  • Does this PR complete the epic?
  • Are links included to any other gov-approved PRs associated with epic?
  • Does PR include documentation for Raft's a11y review?
  • Did automated and manual testing with iamjolly and ttran-hub using Accessibility Insights reveal any errors introduced in this PR?

n/a: no user facing changes

Deliverable 5: Deployed

  • Was the code successfully deployed via automated CircleCI process to development on Cloud.gov?

Deliverable 6: Documented

  • Does this PR provide background for why coding decisions were made?
  • If this PR introduces backend code, is that code easy to understand and sufficiently documented, both inline and overall?
  • If this PR introduces frontend code, is that code easy to understand and sufficiently documented, both inline and overall?
  • If this PR introduces dependencies, are their licenses documented?
  • Can reviewer explain and take ownership of these elements presented in this code review?

Deliverable 7: Secure

  • Does the OWASP Scan pass on CircleCI?
  • Do manual code review and manual testing detect any new security issues?
  • If new issues detected, is investigation and/or remediation plan documented?

Deliverable 8: User Research

Research product(s) clearly articulate(s):

  • the purpose of the research
  • methods used to conduct the research
  • who participated in the research
  • what was tested and how
  • impact of research on TDP
  • (if applicable) final design mockups produced for TDP development

@dependabot dependabot bot added dependencies Pull requests that update a dependency file frontend raft review This issue is ready for raft review labels Dec 20, 2021
@dependabot dependabot bot requested a review from a team December 20, 2021 06:21
@dependabot dependabot bot force-pushed the dependabot/npm_and_yarn/tdrs-frontend/raft-tdp-main/react-router-dom-6.2.1 branch 2 times, most recently from c034753 to 9e91149 Compare December 22, 2021 17:08
@dependabot dependabot bot force-pushed the dependabot/npm_and_yarn/tdrs-frontend/raft-tdp-main/react-router-dom-6.2.1 branch from 9e91149 to db1e594 Compare January 18, 2022 17:16
@dependabot dependabot bot force-pushed the dependabot/npm_and_yarn/tdrs-frontend/raft-tdp-main/react-router-dom-6.2.1 branch 4 times, most recently from 946352e to f7ff522 Compare January 25, 2022 15:11
@jorgegonzalez
Copy link

@dependabot rebase

Bumps [react-router-dom](https://github.com/remix-run/react-router/tree/HEAD/packages/react-router-dom) from 5.3.0 to 6.2.1.
- [Release notes](https://github.com/remix-run/react-router/releases)
- [Commits](https://github.com/remix-run/react-router/commits/v6.2.1/packages/react-router-dom)

---
updated-dependencies:
- dependency-name: react-router-dom
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
@dependabot dependabot bot force-pushed the dependabot/npm_and_yarn/tdrs-frontend/raft-tdp-main/react-router-dom-6.2.1 branch from f7ff522 to fee4a9b Compare January 25, 2022 17:04
@jorgegonzalez jorgegonzalez force-pushed the dependabot/npm_and_yarn/tdrs-frontend/raft-tdp-main/react-router-dom-6.2.1 branch from 6413396 to 9591ea8 Compare January 25, 2022 18:38
@jorgegonzalez
Copy link

react-router and react-router-dom need to be upgraded in parallel, and doing so has required some minor refactoring; I'm making a separate issue to track this work.

@jorgegonzalez
Copy link

Additionally, a package we use connected-react-router does not support these versions so we are migrating to an alternative with a similar api.

supasate/connected-react-router#543

https://github.com/lagunovsky/redux-react-router

@jorgegonzalez jorgegonzalez linked an issue Jan 26, 2022 that may be closed by this pull request
11 tasks
@jorgegonzalez jorgegonzalez changed the title Bump react-router-dom from 5.3.0 to 6.2.1 in /tdrs-frontend refactor(1576): Upgrade react-router packages and refactor related components Jan 26, 2022
…into dependabot/npm_and_yarn/tdrs-frontend/raft-tdp-main/react-router-dom-6.2.1
@jorgegonzalez jorgegonzalez force-pushed the dependabot/npm_and_yarn/tdrs-frontend/raft-tdp-main/react-router-dom-6.2.1 branch from 0a947d7 to 19ead36 Compare February 2, 2022 18:07
@codecov
Copy link

codecov bot commented Feb 2, 2022

Codecov Report

Merging #1506 (197110a) into raft-tdp-main (c660b81) will decrease coverage by 0.26%.
The diff coverage is 80.00%.

Impacted file tree graph

@@                Coverage Diff                @@
##           raft-tdp-main    #1506      +/-   ##
=================================================
- Coverage          97.58%   97.31%   -0.27%     
=================================================
  Files                 80       80              
  Lines               1902     1902              
  Branches             249      249              
=================================================
- Hits                1856     1851       -5     
- Misses                22       24       +2     
- Partials              24       27       +3     
Flag Coverage Δ
dev-backend 99.10% <ø> (ø)
dev-frontend 94.01% <80.00%> (-0.75%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...end/src/components/LoginCallback/LoginCallback.jsx 50.00% <0.00%> (-50.00%) ⬇️
...rontend/src/components/EditProfile/EditProfile.jsx 100.00% <100.00%> (ø)
tdrs-frontend/src/components/Header/Header.jsx 100.00% <100.00%> (ø)
...ontend/src/components/PrivateRoute/PrivateRoute.js 100.00% <100.00%> (ø)
tdrs-frontend/src/components/Routes/Routes.js 100.00% <100.00%> (ø)
...-frontend/src/components/SplashPage/SplashPage.jsx 100.00% <100.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 c660b81...197110a. Read the comment docs.

/* istanbul ignore if */
if (menuRef.current.classList.contains('is-visible')) {
e.preventDefault()
console.log('is visible')
Copy link
Collaborator

@andrew-jameson andrew-jameson Feb 2, 2022

Choose a reason for hiding this comment

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

Is logging now handled elsewhere? Or was this unnecessary before?

Choose a reason for hiding this comment

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

Logging to the console like this is generally unnecessary

Copy link
Collaborator

@andrew-jameson andrew-jameson left a comment

Choose a reason for hiding this comment

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

Found no issues locally, LGTM

@@ -144,7 +144,7 @@ function EditProfile() {
}

if (requestedAccess && sttAssigned) {
return <Redirect to="/request" />
return <Navigate to="/request" />

Choose a reason for hiding this comment

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

All instances of Redirect are converted to Navigate

@@ -450,15 +452,39 @@ describe('EditProfile', () => {
],
},
})
const wrapper = mount(

render(

Choose a reason for hiding this comment

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

Note that we are rewriting enzyme tests with react-testing-library everywhere possible when we encounter them

</PrivateRoute>
}
/>
<Route

Choose a reason for hiding this comment

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

Route can only exist as a child of Routes now

Comment on lines +26 to +73
const keyListenersMap = useMemo(() => {
let tabIndex = 0
/* istanbul ignore next */
const handleTabKey = (e) => {
/* istanbul ignore if */
if (menuRef.current.classList.contains('is-visible')) {
e.preventDefault()
const focusableMenuElements = [
...menuRef.current.querySelectorAll('button'),
...menuRef.current.querySelectorAll('a'),
]

const firstElement = focusableMenuElements[0]
const lastIndex = focusableMenuElements.length - 1
const lastElement = focusableMenuElements[lastIndex]
const lastIndex = focusableMenuElements.length - 1

if (focusableMenuElements.includes(document.activeElement)) {
if (!e.shiftKey && tabIndex >= lastIndex) {
tabIndex = 0
} else if (e.shiftKey && tabIndex === 0) {
tabIndex = lastIndex
} else if (e.shiftKey) {
tabIndex -= 1
if (focusableMenuElements.includes(document.activeElement)) {
if (!e.shiftKey && tabIndex >= lastIndex) {
tabIndex = 0
} else if (e.shiftKey && tabIndex === 0) {
tabIndex = lastIndex
} else if (e.shiftKey) {
tabIndex -= 1
} else {
tabIndex += 1
}
} else {
tabIndex += 1
tabIndex = 0
}
} else {
tabIndex = 0

focusableMenuElements[tabIndex].focus()
}

focusableMenuElements[tabIndex].focus()
return false
}

return false
}

const keyListenersMap = new Map([[9, handleTabKey]])
return new Map([[9, handleTabKey]])
}, [menuRef])

/* istanbul ignore next */
useEffect(() => {
function keyListener(e) {
const listener = keyListenersMap.get(e.keyCode)
return listener && listener(e)
}

document.addEventListener('keydown', keyListener)

return () => document.removeEventListener('keydown', keyListener)
}, [])
}, [keyListenersMap])

Choose a reason for hiding this comment

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

All of this is just refactored for clarity and to remove unneeded logic and linter warnings

@@ -15,39 +18,62 @@ describe('LoginCallback.js', () => {
const store = mockStore({
auth: { authenticated: true, user: { email: 'hi@bye.com' } },
})
const wrapper = mount(

render(

Choose a reason for hiding this comment

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

Again, migrate from enzyme's mount to render

) : null
}

PrivateRoute.propTypes = {

Choose a reason for hiding this comment

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

We need to move away from PropTypes as this is unhelpful noise.

<IdleTimer />
</PrivateTemplate>
</Route>
<PrivateTemplate title={title}>

Choose a reason for hiding this comment

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

Note we are no longer wrapping this with Route, and it is handled higher up in the tree

<NoMatch />
</Route>
</Switch>
<Routes>

Choose a reason for hiding this comment

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

Switch is now Routes

@@ -2,7 +2,7 @@ import React from 'react'
import ReactDOM from 'react-dom'
import axios from 'axios'

import { ConnectedRouter as Router } from 'connected-react-router'
import { ReduxRouter as Router } from '@lagunovsky/redux-react-router'

Choose a reason for hiding this comment

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

The replacement for connected-react-router has a very similar api and only requires a few additions to our root Router and Reducer below

…into dependabot/npm_and_yarn/tdrs-frontend/raft-tdp-main/react-router-dom-6.2.1
@jorgegonzalez jorgegonzalez added QASP Review and removed raft review This issue is ready for raft review labels Feb 3, 2022
"file-type": "^16.5.3",
"history": "^4.7.2",
"history": "^5.2.0",

Choose a reason for hiding this comment

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

This was updated as the older version caused a conflict with the new one needed in react-router-dom

Copy link
Collaborator

@ADPennington ADPennington left a comment

Choose a reason for hiding this comment

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

lgtm @jorgegonzalez 👍🏾

@andrew-jameson andrew-jameson merged commit 4eef5d2 into raft-tdp-main Feb 4, 2022
@andrew-jameson andrew-jameson deleted the dependabot/npm_and_yarn/tdrs-frontend/raft-tdp-main/react-router-dom-6.2.1 branch February 4, 2022 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file frontend Ready to Merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upgrade react-router packages and refactor related components
3 participants