Skip to content
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

Add support for admin configuration through props instead of elements #8944

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

djhi
Copy link
Collaborator

@djhi djhi commented May 24, 2023

Problem

There are rules dictating the allowed children for the Admin components because those are configuration elements. You can't just pass any react elements. This is in part because that's how React Router works when you favor JSX for your routing configuration.

This can come as a surprise for newcomers as you actually have to read the documentation to know about them.

Solution

You can now pass your resources and custom routes as objects through the admin props. This make them explicit (resources, customRoutes and customRoutesWithoutLayout) and discoverable via your IDE autocompletion.

It looks like this:

export const App = () => (
    <Admin
        dataProvider={dataProvider}
        authProvider={authProvider}
        resources={(permissions: any) => ({
            posts: {
                edit: EditGuesser,
                list: ListGuesser,
            },
            comments: {
                list: ListGuesser,
                edit: EditGuesser,
                show: ShowGuesser,
            },
        })}
        customRoutes={(permissions: any) => [
            { path: 'custom', element: <div>Custom route</div> },
        ]}
        customRoutesWithoutLayout={[
            {
                path: 'custom-no-layout',
                element: <div>Custom route no layout</div>,
            },
        ]}
    />
);

TODO

  • Implementation
  • Tests
  • Documentation

@djhi djhi added the WIP Work In Progress label May 24, 2023
Base automatically changed from next to master May 25, 2023 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WIP Work In Progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant