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

feat(cmf): react-router v4 integration #324

Closed
wants to merge 53 commits into from

Conversation

jmfrancois
Copy link
Collaborator

@jmfrancois jmfrancois commented Mar 24, 2017

Please check if the PR fulfills these requirements

  • The commit(s) message(s) follows our
    guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Integration has been done in one project (add PR link to it)
  • example app provided
  • versions script updated
  • wrapchildren patch has been removed

What is the current behavior? (You can also link to an open issue here)

we are using react-router v3.X
#90

What is the new behavior?

We have an app under examples/cmf-app, you can install and start (this is the output from yo talend:react-cmf)

react-router v4.0.0 integration.
The concept has completly changed, so we need to re-think our integration.
Now routing is done using , , ... components.
Please check the docs: https://github.com/ReactTraining/react-router
and the migration guide: https://github.com/ReactTraining/react-router/blob/master/packages/react-router/docs/guides/migrating.md

The idea behind this new integration is to keep routes in configuration.

Does this PR introduce a breaking change?

  • Yes
  • No

React-router v4

UIRouter to CMFRouter

The component UIRouter has been renamed to CMFRouter.
But you should not use this component explicitly and let CMF handle this.

Before

import { UIRouter } from '@talend/cmf';

After

import { CMFRouter } from '@talend/cmf';

Optional path parameters

From (/:paramName) to /:paramName?.

Before

// settings.json
{
  "routes": {
    "path": "/",
    "component": "App",
    "childRoutes": [
      {
        "path": "preparations(/:folderId)", // optional parameter
        "component": "HomeListView",
        "view": "preparations",
        "onEnter": "preparation:fetch"
      }
    ]
  }
}

After

// settings.json
{
  "routes": {
    "path": "/",
    "component": "App",
    "childRoutes": [
      {
        "path": "preparations/:folderId?", // optional parameter
        "component": "HomeListView",
        "view": "preparations",
        "onEnter": "preparation:fetch"
      }
    ]
  }
}

onEnter/onLeave router parameters

Now the router parameter has the react-router v4 match object instead of react-router v3 nextState object.

Before

function onEnter({ router, dispatch }) {
	const { nextState, replace } = router;
	const pathParams = nextState.params;
}

After

function onEnter({ router, dispatch }) {
	const { match, replace } = router;
	const pathParams = match.params;
}

HomeListView stacked drawers

The stacked drawers route settings are not hierarchical anymore, they are siblings.

Before

{
  "routes": {
    "path": "/",
    "component": "App",
    "childRoutes": [
      {
        "path": "preparations/:folderId?",
        "component": "HomeListView",
        "view": "home",
        "childRoutes" : [
          {
            "path": "add",
            "component": "FirstDrawer",
            "childRoutes": [
              {
                "path": "dataset/add",
                "component": "SecondDrawer"
              }
            ]
          }
        ]
      }
    ]
  }
}

After

{
  "routes": {
    "path": "/",
    "component": "App",
    "childRoutes": [
      {
        "path": "preparations/:folderId?",
        "component": "HomeListView",
        "view": "home",
        "childRoutes" : [
          {
            "path": "add",
            "component": "FirstDrawer"
          },
          {
            "path": "add/dataset/add",
            "component": "SecondDrawer"
          }
        ]
      }
    ]
  }
}

WithDrawer

This component is used in HomeListView stacked drawers implementation. It used to manage drawers transitions in this entry point, but that not the case anymore.

To ensure that your drawer has an enter/leave animation, wrap it with <Drawer.Animation>. Please read the next section to see how to use it.

Before

function FirstDrawer(props) {
	return (
		<Drawer.Container id="first-drawer" stacked>
            <Drawer.Title title={'First drawer'} />
            <div>
                This is the first drawer, deal with it
            </div>
            <Drawer.Footer>
                <Button onClick={props.gotToPage}>Close</Button>
                <Button bsStyle={'info'} onClick={props.addDataset}>Add Dataset</Button>
            </Drawer.Footer>
        </Drawer.Container>
	);
}

After

function FirstDrawer(props) {
	return (
		<Drawer.Animation className={'tc-with-drawer-wrapper'} onClose={props.gotToPage} >
        	{({ close }) => (
                <Drawer.Container id="first-drawer" stacked>
                    <Drawer.Title title={'First drawer'} />
                    <div>
                        This is the first drawer, deal with it
                    </div>
                    <Drawer.Footer>
                        <Button onClick={close}>Close</Button>
                        <Button bsStyle={'info'} onClick={props.addDataset}>Add Dataset</Button>
                    </Drawer.Footer>
                </Drawer.Container>
            )}
        </Drawer.Animation>
	);
}

Drawer.Animation

<Drawer.Animation> api has changed to manage the open and close animation. The children can now trigger a close animation and callback.

Props Change Description
withTransition Removed Drawer.Animation is animates, if you don't want animation, please don't use it.
onClose Added The action to perform on close. This callback is executed after the animation.
children Changed It's now a render function : ({ close, transitioned, active }) => <React element>.
close(): a function to close the drawer with its animation.
transitioned: boolean that indicates if the animation is finished.
active: boolean that indicates if the drawer is open.

Drawer

It had a z-index set to 100. This is unlikely, but you may experiment issues that some element under the drawer appears on top.
In that case you should rework your HTML markup to not rely on z-indexes. Otherwise, contribute to fix if possible without z-index.

Other information:
Because CMF support custom routing you already use react-router v4 but you can't use customization through the registry, so this is why this PR is still important.

Status
screen shot 2017-03-24 at 21 48 13

@@ -3,8 +3,8 @@
*/
import React from 'react';
import { Provider } from 'react-redux';
import { createHashHistory } from 'history';
Copy link
Contributor

Choose a reason for hiding this comment

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

With this repleacement, our history.js is deprecated but still here but not working, it imports import { hashHistory } from 'react-router'; which is not available anymore.
I suggest to remove it

Copy link
Contributor

Choose a reason for hiding this comment

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

Done

const routes = api.route.getRoutesFromSettings(context, props.routes);
function CMFRouter(props) {
const routes = props.routes;
const history = props.history || createHashHistory();
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not be used explicitly. It is used by App.js which inject the history. We can drop that createHashHistory()

if (props.view && !Component.CMFContainer) {
Component = api.route.connectView(context, Component, props.view);
}
if (props.path === '/') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is only for the root configuration, it would be better to move this directly in CMFRouter

Another thing that we mentionned together was to use the <Redirect> component from react-router instead of our custom one for the / route. This would introduce a breaking change, since settings.json would change for this root route

Copy link
Contributor

@jsomsanith-tlnd jsomsanith-tlnd left a comment

Choose a reason for hiding this comment

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

UIRouter.js needs to be tested

@build-travis-ci
Copy link
Collaborator

:octocat: Demo is available here

@build-travis-ci
Copy link
Collaborator

:octocat: Demo is available here

@jmfrancois jmfrancois closed this Oct 17, 2018
@jsomsanith-tlnd jsomsanith-tlnd deleted the jmfrancois/update-react-router-v4 branch February 20, 2019 09:37
jmfrancois pushed a commit that referenced this pull request Nov 24, 2021
* chore(Storybook): Algolia support

* chore(Storybook): Algolia support

* chore(Storybook): Algolia support

* chore(Storybook): Algolia support

* chore(Storybook): Algolia support

* chore(Storybook): Algolia support

* chore(Storybook): Algolia support

* chore(Storybook): Algolia support

* chore(Storybook): Algolia support

* chore(Storybook): Algolia support

* chore(Storybook): Algolia support

* chore(Storybook): Algolia support

* chore(Storybook): Algolia support

* chore(Storybook): Algolia support

* chore(Storybook): Algolia support

* chore(Storybook): Algolia support

* chore(Storybook): Algolia support

* chore(Storybook): Algolia support

* deps management

* Update .storybook/main.js

* chore(Storybook): Algolia support

* chore(Storybook): Algolia support

* yarn dedup [skip ci]

* chore(Storybook): Algolia support

* chore(Storybook): Algolia support

* chore(Storybook): Algolia support

* chore(Storybook): Algolia support

* chore(Storybook): Algolia support

* chore(Storybook): Algolia support

* chore(Storybook): Algolia support

* chore(Storybook): Algolia support

* chore(Storybook): Algolia support

* Update .storybook/preview.js

* chore(Storybook): Algolia support

* yarn.lock update

* use  process.env

* use process.env prefixed by Storybook

* searchbar placeholder

* do not open on focus

* wrong hit  props

* og

* og

* og

* og

* search bar style

* search bar style

* Update .storybook/preview-head.html

* review

* review

* Update src/docs/SearchBar.component.js

Co-authored-by: Benrajalu <rajalubenoit@gmail.com>

Co-authored-by: Benrajalu <rajalubenoit@gmail.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.

5 participants