api-platform / admin

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

CreateGuesser / EditGuesser formId attribute to bind outher input elements #540

Closed PawelSuwinski closed 3 months ago

PawelSuwinski commented 3 months ago

Possibility to set guesser's form id using formId attribute. It allows to place any input element outside the form.

Example of submit button on the AppBar (just to show the idea, whole implementation uses React.createPortal() and a bit more code):

const AppBar  = () => (
   /...
  <SaveButton form="user-form" />
);
// ...

const UserCreate = () => (
    <CreateGuesser formId="user-form" (...)>
     // ...
    </CreateGuesser>
);

obraz

fzaninotto commented 3 months ago

In my opinion, the Guesser should only get you started, and then you should paste its code and customize it. Otherwise, it will become some kind of "god component", which goes against the philosophy of react-admin.

PawelSuwinski commented 3 months ago

In my opinion, the Guesser should only get you started, and then you should paste its code and customize it. Otherwise, it will become some kind of "god component", which goes against the philosophy of react-admin.

In generall you are right but api-platform Guessers are something more than RA Guessers. There is a override-code message that hints the customization (https://github.com/api-platform/admin/blob/4645fb57ad8a9b443321677ba3cd3fe9c2e8cb33/src/CreateGuesser.tsx#L26) but there are also introsopection, transform, save and other callbacks that form needs, and it was afterall the goal of the api-platform, as a kind of low-code, not to assembly to many things by hand (hydra, schema.org etc). Maybe it should be named in other way then guessers, or all those callbacks should be exported as hooks, but now it is not.

PawelSuwinski commented 3 months ago

@fzaninotto your comment made me want to do some refactoring (#542) to makes easier to write custom form components, so please give some feedback about that.