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

Actual react-router-dom upgrade #6504

Merged
merged 13 commits into from Aug 3, 2023
Merged

Actual react-router-dom upgrade #6504

merged 13 commits into from Aug 3, 2023

Conversation

absoludity
Copy link
Contributor

@absoludity absoludity commented Jul 21, 2023

Description of the change

After the prequal work, this PR does the actual upgrade of react-router-dom, including updating all the use of Route, as well as removing connected-react-router and the remaining container components. Mostly following from their docs for the upgrade at: https://reactrouter.com/en/main/upgrading/v5#upgrade-to-react-router-v6 with some custom changes required by our specific test infrastructure.

Benefits

Finally upgrade react-router and upgrade to hook-based components (something that has been long-running tech-debt slowing us down).

Possible drawbacks

There could be some fall-out of small UX issues that weren't caught in CI. I know of one that I'll fix straight away (two requests sent off for available packages when viewing the catalog - one for all apps in all namespaces).

Applicable issues

@netlify
Copy link

netlify bot commented Jul 21, 2023

Deploy Preview for kubeapps-dev canceled.

Name Link
🔨 Latest commit ea6ebde
🔍 Latest deploy log https://app.netlify.com/sites/kubeapps-dev/deploys/64cb5b44b72fcd00085607bf

@absoludity absoludity changed the title WIP: working through failig tests... only 165 to go :/ Actual react-router-dom upgrade Jul 25, 2023
@absoludity
Copy link
Contributor Author

Painful day of debugging why updated tests using react-router-dom were now failing with what, after some painful investigation and pinpointing, seemed to be a clarity design system issue where browser-specific calls were being made (ie. that fail in nodejs and cause the test runner to barf). As always, solution was pretty simple (polyfill in tests and jest mock for the other occurrence), so that I can continue easily enough now. Though 135 tests left to update.

@absoludity
Copy link
Contributor Author

So all the test code has now been updated for react-router v6 - great, but although the unit tests pass, the actual code fails because connected-react-router never updated to support v6 (and in reality, why should it - it's supporting the old non-hook way of maintaining state).

The end result is we need to remove it, which is only 4 containers left using mapStateToProps etc.

@absoludity
Copy link
Contributor Author

So as well as removing/converting the last containers to proper components, removing the connected-react-router required adding our own custom hook (see hooks/push) so that we can update the browser history using the new navigate from react-router v6 while still dispatching a location changed action (as connected-react-router used to do) when the location is changed, so our reducers still have something to act on when it changes. Still need to verify it works and debug if not (once merge conflicts are resolved).

Signed-off-by: Michael Nelson <minelson@vmware.com>
Signed-off-by: Michael Nelson <minelson@vmware.com>
Signed-off-by: Michael Nelson <minelson@vmware.com>
Signed-off-by: Michael Nelson <minelson@vmware.com>
Signed-off-by: Michael Nelson <minelson@vmware.com>
Signed-off-by: Michael Nelson <minelson@vmware.com>
Signed-off-by: Michael Nelson <minelson@vmware.com>
Signed-off-by: Michael Nelson <minelson@vmware.com>
Signed-off-by: Michael Nelson <minelson@vmware.com>
Signed-off-by: Michael Nelson <minelson@vmware.com>
Signed-off-by: Michael Nelson <minelson@vmware.com>
Signed-off-by: Michael Nelson <minelson@vmware.com>
@absoludity
Copy link
Contributor Author

FINALLY!! :P (there's still at least one issue, but I'll fix that separately ... just that when viewing the installed apps, two requests are sent off, one for all namespaces, so the view gets updated with apps from all namespaces after initially rendering).

@absoludity
Copy link
Contributor Author

@antgamdia It won't be fun, so no problem if you're not keen, but feel free to take a look if you're interested. I'll plan to land it tomorrow with any recommendations :)

@absoludity absoludity merged commit 7b4a984 into main Aug 3, 2023
39 checks passed
@absoludity absoludity deleted the react-router-upgrade-2 branch August 3, 2023 21:03
Copy link
Contributor

@antgamdia antgamdia left a comment

Choose a reason for hiding this comment

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

Sorry I didn't get to finish the review in time! Big +1 and thanks for such an effort in refactoring the whole UI "backstage". It's great to finally be able to move to the most recent react-router version!

@@ -165,6 +166,7 @@ function ContextSelector() {
className="clr-page-size-select"
onChange={selectNamespace}
value={namespace}
data-testid="select-namespace"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this field really intended?

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, this was one that I really struggled to find a way to reference it by role or label in our tests, without a test-id (I didn't want to restructure the markup as part of the change). I just took another look and found I can add an aria-label attribute to the select for cluster and namespace, which is better than adding a test-id (since it'll actually function with a correct label text, accessibility-wise). We could also update the span elements to be labels but I didn't want to update the markup and, it seems, was being lazy, then I thought you're going to review this too and it's what you'd do, so I've done that instead... good reason for having reviewers. Pushing to a different PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation and follow-up PR. Happy to be back again!

@@ -261,7 +263,7 @@ export default function OperatorNew() {
</div>
</div>
<div className="clr-form-control">
<CdsButton type="submit" disabled={disableInstall}>
<CdsButton type="submit" aria-disabled={disableInstall}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this change? From what I can see in a quick search, it seems both aria-disabled and disabled actually disable the input... however, the aria- one does not prevent the element to be announced in a screen reader. Is this the motivation of the change? If so, perhaps we should extend it to the rest of the inputs, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, I'm guessing I was trying to get it to appear in the screen.getByRole() for a react testing library test. Removing and seeing if tests pass. They do - updated.

@@ -0,0 +1,45 @@
// Copyright 2018-2023 the Kubeapps contributors.
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically this file is new, it should be just 2023 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Woops, yes, I usually just copy-n-paste an existing header. Seems I fixed this while removing react-router dependencies.

absoludity added a commit that referenced this pull request Aug 7, 2023
Signed-off-by: Michael Nelson <minelson@vmware.com>
absoludity added a commit that referenced this pull request Aug 7, 2023
### Description of the change

Addresses a couple of small points from the review on #6504 .

Turns out it didn't need any extra style - looks identical with the
label element (verified in the debugger that it does have the label
element etc.):
<img width="325" alt="Screenshot 2023-08-07 at 11 21 09 am"
src="https://github.com/vmware-tanzu/kubeapps/assets/497518/25fc16b7-168c-4f21-8f79-f6227237503a">
<img width="325" alt="Screenshot 2023-08-07 at 11 22 29 am"
src="https://github.com/vmware-tanzu/kubeapps/assets/497518/bcf3dbd1-4033-42bc-a60c-6d44600b4e8f">


### Benefits

Removed unnecessary test-ids and more accessible UX.

### Possible drawbacks

<!-- Describe any known limitations with your change -->

### Applicable issues

<!-- Enter any applicable Issues here (You can reference an issue using
#) -->

- ref #6187 

### Additional information

<!-- If there's anything else that's important and relevant to your pull
request, mention that information here.-->

---------

Signed-off-by: Michael Nelson <minelson@vmware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upgrade to react-router-6
3 participants