api-platform / admin

A beautiful and fully-featured administration interface builder for hypermedia APIs
https://api-platform.com/docs/admin/
MIT License
481 stars 130 forks source link

ResourceGuesser does not display referenced data suggestions for ManyToOne relations #442

Closed Gamesh closed 2 years ago

Gamesh commented 2 years ago

Package versions

Description
Can't get ManyToOne fields to work. All automatically rendered fields seems to have empty selections. Tried manually overriding the CreateGuesser but it also does not display any suggestions. It just does not seems to render any suggestions even through the response returns data

How to reproduce

Admin List

<React.StrictMode>
    <HydraAdmin entrypoint="/api">
      <ResourceGuesser name="warehouse_parts" create={WarehouseParts} />
    </HydraAdmin>
  </React.StrictMode>

Warehouse part create guesser

const WarehouseParts = (props: any) => (
  <CreateGuesser {...props}>
    <InputGuesser source="part"/>
  </CreateGuesser>
)

Full Response gist: https://gist.github.com/Gamesh/17d91dd5bea51edc4377b4d2afb8e00e

Looks like this for other relations as well even if i don't change anything and only use ResourceGuesser with no customisations 5rfwbqiu4N

Gamesh commented 2 years ago

Ah it appears that if you don't expose a relation as a resource then you can't create relations or use that resource for autocomplete. So the solution here was to add <ResourceGuesser name="parts" />

which kind of sucks as you can't selectively expose only a subset of resources. It's all or nothing, defeats the purpose of customizing

gartner commented 2 years ago

Instead of a ResourceGuesser, you can just add a <Resource ...> imported from react-admin. React-admin, used for the amin interface, requires a Resource to be present for things like related inputs to work. But a <Resource ..> that does not have an edit/create/list prop, will not display in the menu. See https://marmelab.com/react-admin/doc/3.19/Inputs.html#reference-inputs

Gamesh commented 2 years ago

Ah i see, good to know, thanks for the tip