-
-
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
[RFC] Close expanded panels on list change #6167
Comments
Thanks for your suggestion! I'm not sure it make sense to reset the expanded state on filter in all cases. I agree with you that it should be configurable. As the expanded state is stored in Redux, I believe we need to expose an action that allows to reset this state. That way you will be able to dispatch it when the user changes the filter in a custom component via a |
Implemented in #6603 You can refer to |
@WiXSL @fzaninotto #6603 seems unrelated to this issue, I think this should be reopened? As far as I can tell, there’s still no official way to reset the expanded state 🤔. |
React-admin now exposes a
|
Thanks @fzaninotto. Checking the comments and source code though: react-admin/packages/ra-core/src/controller/list/useExpanded.tsx Lines 53 to 94 in 4ac02b5
…this only appears to let you control expanded rows that you already know the ID for ahead of time—it doesn’t report on currently expanded IDs. So it doesn’t look like there’s an official way to reset all expanded rows (unless you know all their IDs). I think in that case the current user land workaround is to access/alter the store directly, but it’s brittle relying on the preference key: const resource = useResourceContext()
const [expandedIds, setExpandedIds] = useStore(
`${resource}.datagrid.expanded`, // Could change in ra-core updates
[],
)
// Clear/Reset expanded rows
setExpandedIds([]) |
Right. But as the expanded ids are stored in the store, you can easily do it with const useCollapseAll = ( resource ) => {
const [expandedIds, setExpandedIds] = useStore<Identifier[]>(
`${resource}.datagrid.expanded`,
[]
);
return () => {
setExpandedIds([]);
};
} |
Is your feature request related to a problem? Please describe.
One of my resource has a filter which when changes its value, changes list completely so expanded panels makes no sense.
Describe the solution you'd like
My suggestion is adding param
closeExpandedOnRefresh
toDatagrid
(List
?) to close all expanded panels when resource is refreshed. Currently, AFAIK there's no possibility to add such functionality manually.Additional context
Adding RFC as I'm not sure if this make sense for you. I don't want to pollute framework with features that serves only small fraction of users. Maybe instead would be better to add
onChange
callback to list and additionally expose hook for closing panels.Anyways I'm willing to help!
The text was updated successfully, but these errors were encountered: