这是indexloc提供的服务,不要输入任何密码
Skip to content

Add a flexible way for customization react-admin data provider (primaryKey, ...) #2088

@mnlbox

Description

@mnlbox

I think maybe we can pass this type of config as a data provider constructor? 🤔 For example pass an array of resource and configurations like custom primary key for a table. (React-Admin only support id as a primary key field name)

For example I want use React-Admin with an exist database and can't modify all primary key's to id. Also it's difficult to create custom data provider and check all resource name with switch / case or if / else to override primarykey.

We need a check that if any config present in config object for this resource or not. If any config exists use that else we can use default configurations (for example id as default primary key).

My dream implementation is like this:

const headers = {
    "Content-Type": "application/json",
    "X-Hasura-Access-Key": "admin"
};

const configs = {
    "online_exam.difficulty": {
         primaryKey: "title",
         // other customization can be add here in future
    },
    "online_exam.subject":  {
         primaryKey: "name",
         // other customization can be add here in future
    },
};

const App = () => (
    <Admin
        title="Online Exam"
        dataProvider={hasuraDataProvider('http://localhost:8080', headers, configs)}
        dashboard={Dashboard}
    >
        <Resource name="online_exam.difficulty" icon={ModeIcon} list={DifficultyList} show={DifficultyShow} create={DifficultyCreate} edit={DifficultyEdit} options={{ label: 'Difficulty' }}/>
        <Resource name="online_exam.subject" icon={ModeIcon} list={SubjectList} show={SubjectShow} create={SubjectCreate} edit={SubjectEdit} options={{ label: 'Subject' }}/>

    </Admin>
);

export default App;

See configs and const and new hasuraDataProvider constructor. (dataProvider={hasuraDataProvider('http://localhost:8080', headers, configs)})

Related issues: marmelab/react-admin#3172, #2068

Please tell me your idea.
@praveenweb

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions