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

Missing resources in props for Menu #1196

Closed
rudovjan opened this issue Nov 2, 2017 · 8 comments · Fixed by #1197
Closed

Missing resources in props for Menu #1196

rudovjan opened this issue Nov 2, 2017 · 8 comments · Fixed by #1197
Assignees

Comments

@rudovjan
Copy link

rudovjan commented Nov 2, 2017

What you were expecting:
Resources are passed in props to custom menu component

What happened instead:
Resources are undefined

Steps to reproduce:

const myMenu = ({ resources }) => { console.log(resources); return ''; };

return (
<Admin menu={myMeny} restClient={restClient('http://localhost:4000/api/fakeService')}>
  <Resource name="endpoint" />
</Admin>)
  • Admin-on-rest version: ^1.3.2
  • React version: ^15.3.0

Thank you very much,
Jan

@fzaninotto
Copy link
Member

You need to grab the resources from the state in your custom menu, as in https://github.com/marmelab/admin-on-rest/blob/master/src/mui/layout/Menu.js#L66

@fzaninotto
Copy link
Member

Reopening, I realize the doc is misleading on that point. It's indeed a documentation bug.

https://marmelab.com/admin-on-rest/Admin.html#menu

@rudovjan
Copy link
Author

rudovjan commented Nov 2, 2017

Thank you very much! That makes sense 💯

@alextsoi
Copy link

alextsoi commented Nov 5, 2017

If I make my own menu, the compiler will throw an error.
Line 61: 'getResources' is not defined no-undef

I think it comes from the sample code in the documentation
const mapStateToProps = state => ({ resources: getResources(state), })

But I don't know how to import the correct getResources from the 'admin-on-rest' module.

@djhi
Copy link
Contributor

djhi commented Nov 5, 2017

@alextsoi please ask the question on StackOverflow

@fzaninotto
Copy link
Member

Sorry, my mistake, I'll update the doc

@fzaninotto fzaninotto reopened this Nov 6, 2017
@solocommand
Copy link

Is getResources actually required? It seems to work OK with the mapStateToProps removed.

Otherwise, getResources will need to be publicized: it is a named export from /reducer/index.js, and only the default export from that file is available as createAppReducer in /index.js.

@lucapette
Copy link

@fzaninotto we have just solved it as import { getResources } from "admin-on-rest/lib/reducer"; in our of our projects (thank you very much for admin-on-rest!), but to be honest I'm not so sure that's the right approach. If it is, happy to open a pr to fix the docs!

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 a pull request may close this issue.

6 participants