-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
[Feature Request] Less coupled {List|Edit|Show|Create}Controller(s) for customRoutes #2903
Comments
Well, actually we did get the same issue on a heavily customized react-admin app. We don't have any plans yet but this is definitely on our radar. Feel free to share how you would implement that or even submit a PR! |
Great, I will get back with a proposal soon. |
Thanks for the suggestion. ListController uses the URL to initialize filters, sort and pagination, and allows users to share URLs and use the back button. We want that functionality, so the coupling with the location is necessary. I don’t want to add another level of indirection to make ListController dépend not on Location but on a wrapper - the code is already complex enough. So for your use case, I suggest you write a custom controller. You can publish it as a standalone package if you want, but we won’t add it to the core. |
It seems we disagree with @djhi, so I reopen this issue to continue the discussion. |
Thanks for both opinions. To be honest I am not familiar enough to simply tell how it should be done, if it should be done with an existing class and how it can have side effect with the rest of the react-admin. I am asking advices. All I know is adding this feature will make much sens for all I agree the code is quite complex, perhaps creating a separate component is the best solution. With the existing source, here's the few I can see:
For initialization, we can do this into - function mapStateToProps(state, props) {
+ function mapStateToProps(state, { query, ...props }) {
const resourceState = state.admin.resources[props.resource];
return {
- query: selectQuery(props),
+ query: query || selectQuery(props),
params: resourceState.list.params,
ids: resourceState.list.ids,
selectedIds: resourceState.list.selectedIds,
total: resourceState.list.total,
data: resourceState.data,
isLoading: state.admin.loading > 0,
filterValues: resourceState.list.params.filter,
version: state.admin.ui.viewVersion,
};
}
For this, we only have one resource state per resource, if you want to display multiple time the same entity in the same page, it may cause issue. If I got it right, I am not sure how this will behave if we keep it like this, can the buffer conflict if multiple list are present?
The back button and user to share url is because we store the query filter state into the url params, in this version, we could try to disable the params usage from the URL params and use a new state in redux store made for that purpose. |
The problem is that all list actions (filtering, sorting, paginating) are redirections, and the URL is the single source of truth in the ListController as it's written. What you are describing requires altering the component in many ways, and it's in essence, another ListController. You'll have to make choices about what to track in the URL and what not to track (and break the back button feature). And what may make sense for your use case (e.g. displaying several lists in a page) may not make sense for others. In fact, your use case may be closer to a So instead of trying to modify the |
From my point of view, this RFC ends up with: "we're not convinced, please open a PR when you're confident you have something good". We need to keep the number of open issues low to keep a good mental health, so I'm going to close this one. We'll continue the discussion when you open a PR ;) |
Sure, I am still working on it. I will get back when I will have something for you. Thanks. |
I wonder because of your comment, how do you create more than one list views for an entity with the current react-admin? This is common in backoffice application without calling heavily customized. I assumed you create many resources but #3020 proved me I was wrong. |
FYI, this has been implemented in #5741 |
We use a lot of
customRoutes
in our application and we want to display resources data in it.The
{List|Edit|Show|Create}Controller
are tightly coupled to the URL which doesn't permitcustomRoutes
to use them correctly.This is why we are interested to create custom controllers that would be less coupled, and would let us feed the query manually. We will still have a link to create and edit some resources, but the default filtering will be different, and the path to retrieve the data might be too.
It will become a requirement for us, If you are interested in such a component to be added into ra-core/ra-ui-materialui, I can probably try to make a proposition soon.
The text was updated successfully, but these errors were encountered: