0

I have a REST API that lets you access associated resources like this:

  • GET /samples lists all samples
  • GET /samples/1 describes sample 1 in detail
  • GET /samples/1/data lists all data belonging to sample 1

I'm trying to hook this up with react-admin, where I have the following <Admin> component:

<Admin dataProvider={dataProvider}>
    <Resource name="samples" list={SampleList} show={SampleShow} edit={SampleEdit}/>
</Admin>

So, I now want to add a list component for data, but I do not want the user to be able to list all data. I just want the user to be able to see all data associated with a sample: a page representing the GET /samples/1/data URL.

As a consequence, I don't want data appearing as a resource on the sidebar/front page. I just want to have a SampleList and SampleShow components to be able to link to a list of associated data. How can I do this with react-admin?

Migwell
  • 18,631
  • 21
  • 91
  • 160
  • You can create your menu with only the required resources: https://stackoverflow.com/questions/57404053/react-admin-create-a-custom-page-which-can-be-accessed-from-menu-sidebar/57405004#57405004 – MaxAlex Sep 24 '19 at 07:47
  • True, but that doesn't solve the issue of wanting to have a page that only shows the data attached to a single sample.Which the regular List component wouldn't do. – Migwell Sep 24 '19 at 08:02
  • The most similar solution in react-admin is to create a separate 'data' resource and access it through reference input / field. – MaxAlex Sep 24 '19 at 08:59
  • But will the data resource only show data items for my selected sample? If so, that's the solution I'm looking for – Migwell Sep 24 '19 at 09:18
  • Possibly, but the URL format will be different: https://marmelab.com/react-admin//Fields.html#referencefield – MaxAlex Sep 24 '19 at 09:26
  • No, `ReferenceField` doesn't do it. It "fetches a single referenced record, and displays one field of this record". I want to display multiple references records, and ideally on their own page. – Migwell Sep 24 '19 at 09:41

0 Answers0