React Admin DataProvider Mixer
npm i --save ra-data-mixer
// in src/App.tsx
import React from "react";
import { Admin, Resource } from "react-admin";
import mixerProvider, { Mixer } from "ra-data-mixer";
import { PostList } from "./posts";
const provider1 = ...;
const provider2 = ...;
const mixer: Mixer = (resource) =>
(({
posts: provider1,
users: provider2,
} as any)[resource]);
const App = () => (
<Admin dataProvider={mixerProvider(mixer)}>
<Resource name="posts" list={PostList} />
</Admin>
);
export default App;
You can mix same resources with different filters on different names:
// in src/App.tsx
import mixerProvider, { Mixer } from "ra-data-mixer";
const myProvider = ...;
const mixer: Mixer = (resource) =>
(({
managers: [myProvider, "users", (params) => ({
...params,
filter: {
...params.filter,
role: "manager"
}
})],
reporters: [myProvider, "users", (params) => ({
...params,
filter: {
...params.filter,
role: "reporter"
}
})],
} as any)[resource]);
In this example, managers
and reporters
resources are using a same resource named users
with different filters
This project is licensed under the MIT license.
Copyright (c) KoLiBer ([email protected])