@rck.princy/ra-data-provider-wrapper
v0.0.2
Published
@rck.princy/ra-data-provider-wrapper makes defining data providers in React Admin easy
Downloads
17
Maintainers
Readme
@rck.princy/ra-data-provider-wrapper :hammer:
A wrapper for React Admin DataProvider
that simplifies the integration of multiple ResourceProvider instances (one facade DataProvider).
Features :collision:
- Facade Provider: Automatically manages multiple
ResourceProviders
. - Error Handling: Throws errors for unknown resource names and unimplemented functions
Installation :zap:
npm install @rck.princy/ra-data-provider-wrapper
Usage :seedling:
Creating a resource provider
import { type ResourceProvider } from '@rck.princy/ra-data-provider-wrapper';
export type Dummy = {
id: string;
name: string;
};
export const dummyProvider: ResourceProvider<Dummy> = {
resource: 'dummies',
getList: async ({ filter: _filter, meta: _meta }) => {
return Promise.resolve([
{
id: 'test',
name: 'test',
},
]);
},
getOne: async ({ id }) => {
return Promise.resolve({
id,
name: `name: ${id}`,
});
},
deleteAll: async () => {
//some api calls
return Promise.resolve([]);
},
//others
};
Creating react-admin DataProvider using @rck.princy/ra-data-provider-wrapper
import { type DataProvider } from 'react-admin';
import { createRaProvider } from '@rck.princy/ra-data-provider-wrapper';
import { dummyProvider } from './dummy-provider';
import { personProvider } from './person-provider';
export const raDataProvider = createRaProvider(
[personProvider, dummyProvider],
{
getListOptions: {
defaultPagination: { page: 1, perPage: 5 };
getPageInfo: async (args) => {
return Promise.resolve({
pageInfo: {
hasNextPage: true,
hasPreviousPage: false,
},
});
},
}
}
);
Examples
License
This project is licensed under the MIT License.