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

Add the ability to override form layouts in a simpler way #4116

Merged
merged 26 commits into from
Dec 9, 2019
Merged

Conversation

fzaninotto
Copy link
Member

@fzaninotto fzaninotto commented Dec 5, 2019

  • Add ability to customize Edit, Create, and Show root component
  • Make handleSubmitWithRedirect optional in Toolbar
  • Create FormWithRedirect component in ra-core to refactor common form code and make custom form layouts easier
  • Document the way to build a custom form layout
  • Use the previous changes to improve use of screen real estate in demo/Customers/Edit view
  • Fix demo/Customer/Create form to match the Edit one

before

Capture d’écran de 2019-12-05 17-16-48

after

Capture d’écran de 2019-12-05 16-52-09

@fzaninotto fzaninotto added this to the 3.1.0 milestone Dec 5, 2019
@fzaninotto fzaninotto added RFR Ready For Review WIP Work In Progress and removed RFR Ready For Review labels Dec 5, 2019
@fzaninotto
Copy link
Member Author

Back to WIP, I'll do the layout of the forms with Box instead of divs with useStyle. In fact, I kind of fell in love with material-ui's Box.

@fzaninotto fzaninotto added the RFR Ready For Review label Dec 5, 2019
@fzaninotto
Copy link
Member Author

And we're back to RFR

@fzaninotto
Copy link
Member Author

After a good night's sleep, I think we can do a better work than inviting people to copy a large bunch of code. Back to WIP.

@fzaninotto fzaninotto removed the RFR Ready For Review label Dec 6, 2019
@fzaninotto fzaninotto changed the title Improve Customer detail in demo Add the ability to override form layouts in a simpler way Dec 7, 2019
@fzaninotto fzaninotto added RFR Ready For Review and removed WIP Work In Progress labels Dec 7, 2019
@fzaninotto
Copy link
Member Author

And Ready For Review

Copy link
Contributor

@djhi djhi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat! 💪

docs/CreateEdit.md Show resolved Hide resolved

This custom form layout component uses the `FormWithRedirect` component, which wraps react-final-form's `Form` component to handle redirection logic. It also uses react-admin's `<SaveButton>` and a `<DeleteButton>`.

**Tip**: When `Input` components have a `resource` prop, they use it to determine the input label. `<SimpleForm>` and `<TabbedForm>` inject this `resource` prop to `Input` components automatically. When you use a custom form layout, pass the `resource` prop manually - unless the `Input` has a `label` prop.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really should use react Context instead :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, v4 ^^

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed ^^

@djhi djhi merged commit 07b5e4c into next Dec 9, 2019
@djhi djhi deleted the demo-customer branch December 9, 2019 13:11
@arkkanoid
Copy link

Hi, Just updating to v3.1.0:

./~/ra-core/esm/form/FormWithRedirect.js
Module parse failed: /usr/src/app/node_modules/ra-core/esm/form/FormWithRedirect.js Unexpected token (53:313)
You may need an appropriate loader to handle this file type.

@fzaninotto
Copy link
Member Author

Weird, the transpilation didn't transform { ...arrayMutators } properly in this file, because it's a default value for a prop... I'll fix it and republish shortly.

Thanks for the report.

@fzaninotto
Copy link
Member Author

Out of curiosity, how did you get this error (webpack/parce, babel settings, browser)? I can't reproduce it on any browser on the react-admin demo, even IE11.

@arkkanoid
Copy link

I upgraded RA from v2.9, after installing the new packages and run yarn start I get this error

@fzaninotto
Copy link
Member Author

FYI this is a bug in TypeScript (microsoft/TypeScript#35771) triggered by a useless convention in react-final-form (final-form/react-final-form#704), but we'll have to fix it in the react-admin code...

fzaninotto added a commit that referenced this pull request Dec 19, 2019
justinr1234 pushed a commit to justinr1234/react-admin that referenced this pull request Dec 22, 2019
JulienMattiussi pushed a commit that referenced this pull request Jan 28, 2020
JulienMattiussi pushed a commit that referenced this pull request Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants