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): route onEnter/onLeave with dispatch #1082

Merged
merged 11 commits into from
Feb 19, 2018

Conversation

jsomsanith-tlnd
Copy link
Contributor

What is the problem this PR is trying to solve?
This is not possible to dispatch an action in cmf router onEnter/onLeave hook.

What is the chosen solution to this problem?
Reshape the onEnter/onLeave functions to pass redux dispatch function

Please check if the PR fulfills these requirements

  • The PR commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Related design / discussions / pages (not in jira), if any, are all linked or available in the PR

[x] This PR introduces a breaking change
The onEnter/onLeave functions arguments have changed

@build-travis-ci
Copy link
Collaborator

:octocat: Demo is available here


✖ 8 problems (3 errors, 5 warnings)
/home/travis/build/Talend/ui/packages/cmf/src/UIRouter.js
27:78 error 'dispatch' is missing in props validation react/prop-types

Choose a reason for hiding this comment

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

can you clean the lint errors ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I haven't turned on eslint on my new computer, sorry for that

> eslint --config ../../.eslintrc src

The react/require-extension rule is deprecated. Please use the import/extensions rule from eslint-plugin-import instead.

/home/travis/build/Talend/ui/packages/containers/src/ActionSplitDropdown/ActionSplitDropdown.test.js
4:10 error 'ActionSplitDropdown' is defined but never used no-unused-vars

/home/travis/build/Talend/ui/packages/containers/src/DeleteResource/deleteResource.sagas.js
106:4 warning Unexpected console statement no-console

Choose a reason for hiding this comment

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

can you remove the console

Copy link
Contributor Author

Choose a reason for hiding this comment

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

WTF Oo, haven't touched this file
I'll fix it

@build-travis-ci
Copy link
Collaborator

:octocat: Demo is available here

1 similar comment
@build-travis-ci
Copy link
Collaborator

:octocat: Demo is available here

@build-travis-ci
Copy link
Collaborator

:octocat: Demo is available here

@build-travis-ci
Copy link
Collaborator

:octocat: Demo is available here

@build-travis-ci
Copy link
Collaborator

:octocat: Demo is available here

@build-travis-ci
Copy link
Collaborator

:octocat: Demo is available here

const routes = api.route.getRoutesFromSettings(context, props.routes);
if (routes.path === '/' && !!routes.component) {
return (<BaseRouter routes={routes} history={props.history} />);
const routes = api.route.getRoutesFromSettings(context, props.routes, props.dispatch);
Copy link
Contributor

Choose a reason for hiding this comment

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

The UIRouter is just connected, not cmfConnected so you don't have props.dispatch.
You may have it from the context if you add the store to it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes but it's ok IMO. The entry point to cmf store is still redux, so dispatching an action from react-redux is the same as dispatching an action from cmf redux.

{
"routes": {
"path": "/",
...
Copy link
Contributor

Choose a reason for hiding this comment

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

stop using three dots, looks weird

@@ -130,3 +130,49 @@ CMF uses [React router](https://github.com/ReactTraining/react-router). The defi
}
}
```

You can use onEnter/onLeave lifecycle hooks. To do that, you need to
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use onEnter/onLeave lifecycle hooks. To do that, you need to:


You can use onEnter/onLeave lifecycle hooks. To do that, you need to
* register a route function in CMF registry
* add the route function id in your route setting
Copy link
Contributor

Choose a reason for hiding this comment

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

dd the route function id in your route settings

@build-travis-ci
Copy link
Collaborator

:octocat: Demo is available here

@jmfrancois jmfrancois merged commit 3cd4221 into master Feb 19, 2018
@jmfrancois jmfrancois deleted the jsomsanith/feat/cmf/route_onenter_with_dispatch branch February 19, 2018 09:54
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