Multiple Datamanagers
As often required (e.g. clubapp.admin, light.admin), an admin should be able to work with multiple datamanagers at the same time. The current approach with useDatamanager does only support one datamanager.
#
Problemreact-admin is only intended to be used with a flat resource structure. That means, the routes will always be:
When targetting multiple datamanagers, we are dealing with a deep structure:
The above routing cannot map this structure out of the box. So, to solve this, we either need
- Nested Resources Feature in react-admin, which is currently not planned, see here and here
- the nesting as part of :resource and/or :id + a data provider that handles it
- the admin as a subroute of a custom routing
As #1 is unlikely and #3 requires a lot of customization work, let's look at #2.
#
SolutionAs sugessted here, we can make the entry list work when passing the dataManagerID as a filter param:
#
ListThe filter can then be used in a custom list:
#
getListFinally, the dataManagerID must be handled by the dataProvider:
The above provider just handles the dataManagerID filter, while the rest of the logic can be delegated to dataProvider.
#
EditNow for the Edit view:
#
getOneThe Edit component will trigger dataProvider.getOne to be loaded. The Problem: We do not have a filter param, as it is only part of List. We need some way to pass the dataManagerID.. Solution: Use "absolute" entry ids of the form "shortID|entryID":
These ids can then be split in getOne:
#
AppThe best thing about this: It actually works! The App code looks like this:
#
Whats missing- Create: how to know which dm to use when having no id?
- A way to load the field config dynamically. EntryList / EntryEdit do not work without a static PublicAPI available at dataProvider.api.
- Caching (new PublicAPI is created everytime)