marmelab / react-admin

A frontend Framework for single-page applications on top of REST/GraphQL APIs, using TypeScript, React and Material Design
http://marmelab.com/react-admin
MIT License
24.8k stars 5.23k forks source link

ReferenceManyField uncaught at handleFetch TypeError: payload.data.map is not a function #1327

Closed l0ne closed 6 years ago

l0ne commented 6 years ago

Hello! I try to implement datagrid in tabbed form.

What you were expecting: Request to api looks good: http://localhost:3001/api/v1/projectRounds?_end=25&_order=DESC&_sort=id&_start=0&projectId=505

What happened instead: If I try response: [{"id":13,"projectId":505,"createdAt":"2017-11-17T00:24:34.000Z"}]

In console I have error: Uncaught TypeError: Cannot read property 'data' of undefined at oneToMany.js:47

try response: {"data":[{"id":13,"projectId":505,"createdAt":"2017-11-17T00:24:34.000Z"}],"total":1}

Having: uncaught at handleFetch TypeError: payload.data.map is not a function at ./node_modules/admin-on-rest/lib/reducer/admin/references/oneToMany.js.exports.default (http://localhost:3000/static/js/bundle.js:16316:125)

...
<FormTab label="Project rounds">
    <ReferenceManyField reference="projectRounds" target="projectId" addLabel={false}>
        <Datagrid>
            <TextField source="id" />
        </Datagrid>
     </ReferenceManyField>
</FormTab>
...

Environment

fzaninotto commented 6 years ago

Hi, and thanks for your question. As explained in the admin-on-rest contributing guide, the right place to ask a "How To" question, get usage advice, or troubleshoot your own code, is StackOverFlow.

This makes your question easy to find by the core team, and the developer community. Unlike Github, StackOverFlow has great SEO, gamification, voting, and reputation. That's why we chose it, and decided to keep GitHub issues only for bugs and feature requests.

So I'm closing this issue, and inviting you to ask your question at:

http://stackoverflow.com/questions/tagged/admin-on-rest

And once you get a response, please continue to hang out on the admin-on-rest channel in StackOverflow. That way, you can help newcomers and share your expertise!

l0ne commented 6 years ago

Hi, thanks for answer!

I think it's not "How To" question becouse I faced with error from you library. I used you admin-on-rest demo and documentation for try it. Request to json file in you demo working correct, but not correct working GET_MANY_REFERENCE with response from rest api. Crashing application when response processing.

Also, if the data in the response is not the same like need you component, can you add a  conditions for check without crashing the application?

Thank you very much!

fzaninotto commented 6 years ago

I consider it's a not bug because it works on the demo:

https://github.com/marmelab/admin-on-rest-demo/blob/a67978a6f69e7dfbb937f66baaa49e787e5853ec/src/visitors/index.js#L82-L93

https://marmelab.com/admin-on-rest-demo/#/

Therefore I believe there is an error in your restClient. I advise to ask for help in stackOverflow for properly configuring it.