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

ui: Upgrade React version and react-dependent libraries #43846

Merged
merged 9 commits into from
Jan 29, 2020

Conversation

koorosh
Copy link
Collaborator

@koorosh koorosh commented Jan 9, 2020

Current PR has affected a lot of files but most of changes are almost the same
and do not affect business logic.

With current changes, react is upgraded to latest version (16.12.0) and
following libraries are upgraded as well: react-redux, redux, redux-saga.
These upgrades of major versions has required to do some code adjustments
to properly migrate to newest versions.

  • redux. Provide valid type arguments for Dispatch type.
  • redux-saga. Changed import and usage of 'delay' function.
  • react-redux. connect function failed to correctly resolve returned type
    for mapDispatchToProps argument. As result it is provided as a function
    instead of object argument. This hack allows implicitly resolve types.
  • CachedDataReducer class is extended with one more optional type argument
    to specify the list of allowed actionNamespace literals instead of string.
    It was necessary to have strictly defined CachedDataReducer interface.
  • normalizeConnectedComponent function is used to do simple mapping from
    react's ExoticComponent to valid react component. This resolves issue of
    providing ConnectedComponents (which are ExoticComponent's, not regular react
    components) to Route component which has strict type validation of component types.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

const ossName = getComponentName(OSSComponent);
const cclName = getComponentName(CCLComponent);

class LicenseSwap extends React.Component<TProps & OwnProps> {
class LicenseSwap extends React.Component<TProps & OwnProps & any> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Following hack with &any type is required to make changes related to types only and do not rewrite component logic.

@koorosh koorosh marked this pull request as ready for review January 9, 2020 15:28
@koorosh koorosh requested a review from a team January 9, 2020 15:28
@koorosh koorosh force-pushed the ui-react-version-upgrade branch from cd8f3e5 to 9198891 Compare January 23, 2020 11:54
@dhartunian dhartunian changed the base branch from master to staging January 27, 2020 16:38
@dhartunian dhartunian changed the base branch from staging to master January 27, 2020 16:39
Copy link
Collaborator

@dhartunian dhartunian left a comment

Choose a reason for hiding this comment

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

Thanks for this huge undertaking @koorosh! My only major concern is whether the restructuring the mapDispatchToProps is necessary. See my comments for the approach I looked at.

@@ -180,7 +180,7 @@ export class CachedDataReducer<TRequest, TResponseMessage> {
* state given the global state object
*/
refresh = <S>(req?: TRequest, stateAccessor = (state: any, _req: TRequest) => state.cachedData[this.actionNamespace]) => {
return (dispatch: Dispatch<S>, getState: () => any) => {
return (dispatch: Dispatch<Action, TResponseMessage>, getState: () => S) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I noticed that in the rest of the PR that everywhere refreshNodes was used we needed to add the arrow function + bindActionCreators wrapping.

I tried adding a ThunkAction<any, S, any> type to the refresh function like below and it seemed to remove the need for the arrow function wrapping in the connect function, would you mind trying out?

  refresh = <S>(req?: TRequest,
                stateAccessor = (state: any, _req: TRequest) => state.cachedData[this.actionNamespace]):
    ThunkAction<any, S, any> => {
    return (dispatch: Dispatch<Action, S>, getState: () => S) => {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Awesome, it makes code much cleaner! Thanks!

@@ -178,9 +176,9 @@ const eventBoxConnected = connect(
eventsValid: eventsValidSelector(state),
};
},
{
() => ({
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is unnecessary and the one below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agree. Removed unnecessary function wrappers across all project

@koorosh koorosh force-pushed the ui-react-version-upgrade branch from 2f6d900 to 478a7d9 Compare January 28, 2020 11:28
With current changes, react is upgraded to latest version (16.12.0) and
following libraries are upgraded as well: react-redux, redux, redux-saga.
These upgrades of major versions has required to do some code adjustments
to properly migrate to newest versions.
- redux. Provide valid type arguments for Dispatch type.
- redux-saga. Changed import and usage of 'delay' function.
- react-redux. `connect` function failed to correctly resolve returned type
for `mapDispatchToProps` argument. As result it is provided as a function
instead of object argument. This hack allows implicitly resolve types.
- `CachedDataReducer` class is extended with one more optional type argument
to specify the list of allowed `actionNamespace` literals instead of `string`.
It was necessary to have strictly defined CachedDataReducer interface.
- `normalizeConnectedComponent` function is used to do simple mapping from
react's ExoticComponent to valid react component. This resolves issue of
providing ConnectedComponents (which are ExoticComponent's, not regular react
components) to Route component which has strict type validation of component types.

Release note: None
- tests command is disabled for now because current state doesn't
contain all fixes to run tests without failure.
- Decommissioned Node History page was added so code has to be adjusted.

Release note: None
Redux Actions for some components (ClusterOverview, NodesLogs, Statements page, and
Node Maps) were not properly binded. As result component were not provided with data,
and weren't rendered.
To fix this, actions are wrapped with 'bindActionCreators' helper.

Release note: None
- get rid of unnecessary wrapping action creators with
bindActionCreators function
- define correct return type for cachedDataReducer.refresh action

Release note: None
Remove useless function wrapper for action creator object

Release note: None
@koorosh koorosh force-pushed the ui-react-version-upgrade branch from c5d6e00 to 7f94c61 Compare January 28, 2020 12:56
@koorosh koorosh requested a review from dhartunian January 28, 2020 16:45
Copy link
Collaborator

@dhartunian dhartunian left a comment

Choose a reason for hiding this comment

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

👍 LGTM. Thanks for the updates!

@dhartunian
Copy link
Collaborator

bors r+

craig bot pushed a commit that referenced this pull request Jan 29, 2020
43846: ui: Upgrade React version and react-dependent libraries r=dhartunian a=Koorosh

- Has to merged after: #43685
- Depends on cockroachdb/yarn-vendored#13

Current PR has affected a lot of files but most of changes are almost the same
and do not affect business logic.

With current changes, react is upgraded to latest version (16.12.0) and
following libraries are upgraded as well: react-redux, redux, redux-saga.
These upgrades of major versions has required to do some code adjustments
to properly migrate to newest versions.
- redux. Provide valid type arguments for Dispatch type.
- redux-saga. Changed import and usage of 'delay' function.
- react-redux. `connect` function failed to correctly resolve returned type
for `mapDispatchToProps` argument. As result it is provided as a function
instead of object argument. This hack allows implicitly resolve types.
- `CachedDataReducer` class is extended with one more optional type argument
to specify the list of allowed `actionNamespace` literals instead of `string`.
It was necessary to have strictly defined CachedDataReducer interface.
- `normalizeConnectedComponent` function is used to do simple mapping from
react's ExoticComponent to valid react component. This resolves issue of
providing ConnectedComponents (which are ExoticComponent's, not regular react
components) to Route component which has strict type validation of component types.

Co-authored-by: Andrii Vorobiov <[email protected]>
@craig
Copy link
Contributor

craig bot commented Jan 29, 2020

Build succeeded

@craig craig bot merged commit 0a960d3 into cockroachdb:master Jan 29, 2020
craig bot pushed a commit that referenced this pull request Jan 30, 2020
44078: ui: Tests on react-routing components r=dhartunian a=Koorosh

Depends on PR: #43846
`yarn-vendor` PR has to be merged: cockroachdb/yarn-vendored#15

Current PR includes minimal changes to functionality (only those which are required to isolate or get
access to individual components under tests):
- `src/index.tsx` file has been refactored into two parts: rendering to DOM and independent `App` component;
-  <Helmet> component (`react-helmet` library) has been refactored to avoid known issue during tests execution (nfl/react-helmet#373)
- old version of react-router and `connect` component in tandem do not work well because connected
component aren't valid react components. As result validation for correct routing was done by re-exporting wrapped components (instead of connected). It allowed to simplify testing with `enzyme#find` function which requires valid react component as an argument;
- Tests are grouped in suites per route to maintain related tests per route;
- There is two kinds of tests which test correct rendering of component for
specific test and another test which validates correct redirection for routes;
- Tests can be refactored to be constructed from configuration to reduce repeated
tests, but it will be actual after migrating to latest version of react-router lib.

44545: sqlbase: add table generator for edge case datums r=rohany a=rohany

Part of work for #44322.

This PR adds a testing utility to generate a table
full of edge case datums to test a variety of things in the future.

Release note: None

Co-authored-by: Andrii Vorobiov <[email protected]>
Co-authored-by: Rohan Yadav <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants