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

Allow passing a custom resource prop to Create / Edit #5662

Closed
danjebs opened this issue Dec 13, 2020 · 3 comments · Fixed by #5730
Closed

Allow passing a custom resource prop to Create / Edit #5662

danjebs opened this issue Dec 13, 2020 · 3 comments · Fixed by #5730
Assignees

Comments

@danjebs
Copy link

danjebs commented Dec 13, 2020

Hi guys, loving using React-Admin! The look on my clients' faces was priceless - "Will it actually be this fast? 🤯 "

I have a feature request for a now-deprecated feature to be re-enabled, although maybe you will have a compelling clarification of why it was removed. Apologies if this has been covered elsewhere, I couldn't find another discussion pertaining to this.

Is your feature request related to a problem? Please describe.
In prior versions of React Admin (I was using 3.7.0), I was able to make Create/Edit forms within complex objects, for simple objects within it. For example, in the image below, a Program could open a Drawer component which allowed for adding ProgramDates or FAQs related to theProgram. As a Program is a complex object with many relations within it, this prevented the user from having to switch contexts to fill out a very simple form.
Screen Shot 2020-12-13 at 10 43 28 AM

This was achieved by the following:

const ProgramDateDetailCreate = ({ programId, onSuccess }) => (
  <Create
    {...{onSuccess}}
    basePath='/ProgramDateDetail'
    resource='ProgramDateDetail'
    undoable={false}
  >
    <SimpleForm defaultValue={{ programId }}>
      // inputs go here
    </SimpleForm>
  </Create>
)

export default ProgramDateDetailCreate

In newer versions of React-Admin, the resource that I pass is overwritten by the resource in the URL and therefore the submit sends to the "wrong" endpoint.

Describe the solution you'd like
The ability to override the resource prop in the CreateContext or EditContext. I understand there may be some issues that this causes - but I think having the option, with the caveat that some redirects etc won't work, is worthwhile. Perhaps the prop could be called dangerouslySetResource so that you can absolve responsibility for bugs arising from it 😅

Describe alternatives you've considered
I attempted to use the useCreate and useEdit hooks, but they remove the convenience of SimpleForm and lead to a duplication of components.

Additional context
The frustrating part about this bug is that I didn't upgrade and it still affected the app - even with my dependencies locked at 3.7.0, it still broke the app when I re0built my Docker container (and re-ram npm install). And that's probably more of an issue with NPM, though. Luckily the app is still in QA, but a change like this that could break the an app and require a re-write of many pages makes me nervous.

EDITS
Grammar, adding name for override prop, adding edits

@danjebs
Copy link
Author

danjebs commented Dec 13, 2020

Related (I think) to #5648

@koaladlt
Copy link

koaladlt commented Sep 20, 2021

Hey @danjebs, were you able to find a workaround to this? I'm in the same situation.

@danjebs
Copy link
Author

danjebs commented Sep 20, 2021

Unfortunately not - I ended up switching to having the forms on their own pages. I thought they allowed using drawers again but I didn't double back and re-change it since I had already converted them and it seems this isn't entirely approved of. But...I thought it would be doable since 3.11.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants