react-admin
react-admin copied to clipboard
`<ReferenceField>` generates a link even though there is nothing to link to
When I hover over a ReferenceField, it shows the link as #/rhymes/32
.
But, when clicking on it, the network request made is /rhymes/list?pagination={"page":1,"perPage":10}&sort={"field":"id","order":"ASC"}&filter={}
(i.e. the default list request).
This results in the page changing to the first page of that resource, which does not even contain the specific entity.
Version: 4.3.0
Please follow issue template and provide a reproduction sandbox
Sorry, that website is awful, just constantly burns CPU and RAM (GBs). I can't create a fork before it crashes on this machine. The full JS file is: https://pastebin.com/6Thf1pxi
I've just been going through the tutorial, so maybe there's something later that will make it work..
Actually for my peace of mind I tried out on our simple example, but couldn't reproduce your issue.
If ever, after completing the tutorial, you're still having this issue, then please create a reproduction case, either on codesandbox or on stackblitz if it works better for you: https://stackblitz.com/github/marmelab/react-admin/tree/master/examples/simple
Also, please note that the resulting code of the tutorial can be found here: https://github.com/marmelab/react-admin/tree/master/examples/tutorial You can use it to compare it with your code if needed.
OK, it's working now that there is an edit view. So, my 2 suggestions would be to move the editing step before the reference step in the tutorial, and update the code to not create a hyperlink if there is no view for it to navigate to.
Maybe a show view would also make it work? But, that doesn't appear anywhere in the tutorial (even though it is in the example code you linked).
Regarding your 2 suggestions:
- inverting these two sections in the tutorial would break the logic of first presenting the Field components, then the Input components. I think it would make things more confusing
- RA already offers plenty of options to change the link of a ReferenceField to your liking. Sure we could automatically detect that the referenced resource has no Edit view, but this doesn't sound like a priority enhancement to me
I'm leaving this issue open as enhancement request in case you (or someone else) want to provide a PR for this. In case there are no updates for some time, I'll eventually close it.
I'd say that the problem comes from the fact that ReferenceField
creates a link regardless of the availability of the target. If there is no edit
or show
view for the reference, ReferenceField
shouldn't render a link, just plain text.
So I'm marking this as a bug.
I'd say that the problem comes from the fact that
ReferenceField
creates a link regardless of the availability of the target. If there is noedit
orshow
view for the reference,ReferenceField
shouldn't render a link, just plain text.
Yes, that's exactly what I meant. Why link to something that doesn't exist? Perhaps it's not a priority, as a complete application probably won't run into this.
As for the tutorial, maybe instead of moving the edit step, a new step could be added before the relationships step that introduces the show view? That would ensure the reference link actually works, and would fill out the tutorial (I'm a little confused why it's not anywhere in the tutorial already).
I'm a little confused why it's not anywhere in the tutorial already
I don't understand what you're talking about. What is missing from the tutorial according to you?
I don't understand what you're talking about. What is missing from the tutorial according to you?
Ctrl+F: "show" The only mention of the show view is:
<Resource>
also defines the React components to use for each CRUD operation (list, create, edit, and show).
There is no demonstration of actually adding a show view. Which is why I reached this situation of adding the reference fields without a show or edit view. I just assumed there would be a step demonstrating a show view in the tutorial.
You're right, the tutorial doesn't explain how to add a Show view. But the tutorial is already long enough, and can't explain everything in the framework.
If you have suggestions about how to improve the documentation, it's in the same repository as the code. Feel free to open a PR!