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

Make ShowBase, CreateBase and EditBase components support resource override via props #7652

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions packages/ra-core/src/controller/create/CreateBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from './useCreateController';
import { CreateContextProvider } from './CreateContextProvider';
import { RaRecord } from '../../types';
import { ResourceContextProvider } from '../../core';

/**
* Call useCreateController and put the value in a CreateContext
Expand Down Expand Up @@ -39,8 +40,19 @@ import { RaRecord } from '../../types';
export const CreateBase = <RecordType extends RaRecord = any>({
children,
...props
}: CreateControllerProps<RecordType> & { children: ReactNode }) => (
<CreateContextProvider value={useCreateController(props)}>
{children}
</CreateContextProvider>
);
}: CreateControllerProps<RecordType> & { children: ReactNode }) => {
const controllerProps = useCreateController<RecordType>(props);
const body = (
<CreateContextProvider value={controllerProps}>
{children}
</CreateContextProvider>
);
return props.resource ? (
// support resource override via props
<ResourceContextProvider value={props.resource}>
{body}
</ResourceContextProvider>
) : (
body
);
};
22 changes: 17 additions & 5 deletions packages/ra-core/src/controller/edit/EditBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ReactNode } from 'react';
import { RaRecord } from '../../types';
import { useEditController, EditControllerProps } from './useEditController';
import { EditContextProvider } from './EditContextProvider';
import { ResourceContextProvider } from '../../core';

/**
* Call useEditController and put the value in a EditContext
Expand Down Expand Up @@ -37,8 +38,19 @@ import { EditContextProvider } from './EditContextProvider';
export const EditBase = <RecordType extends RaRecord = any>({
children,
...props
}: { children: ReactNode } & EditControllerProps<RecordType>) => (
<EditContextProvider value={useEditController<RecordType>(props)}>
{children}
</EditContextProvider>
);
}: { children: ReactNode } & EditControllerProps<RecordType>) => {
const controllerProps = useEditController<RecordType>(props);
const body = (
<EditContextProvider value={controllerProps}>
{children}
</EditContextProvider>
);
return props.resource ? (
// support resource override via props
<ResourceContextProvider value={props.resource}>
{body}
</ResourceContextProvider>
) : (
body
);
};
22 changes: 17 additions & 5 deletions packages/ra-core/src/controller/show/ShowBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ReactElement } from 'react';
import { RaRecord } from '../../types';
import { useShowController, ShowControllerProps } from './useShowController';
import { ShowContextProvider } from './ShowContextProvider';
import { ResourceContextProvider } from '../../core';

/**
* Call useShowController and put the value in a ShowContext
Expand Down Expand Up @@ -37,8 +38,19 @@ import { ShowContextProvider } from './ShowContextProvider';
export const ShowBase = <RecordType extends RaRecord = any>({
children,
...props
}: { children: ReactElement } & ShowControllerProps<RecordType>) => (
<ShowContextProvider value={useShowController<RecordType>(props)}>
{children}
</ShowContextProvider>
);
}: { children: ReactElement } & ShowControllerProps<RecordType>) => {
const controllerProps = useShowController<RecordType>(props);
const body = (
<ShowContextProvider value={controllerProps}>
{children}
</ShowContextProvider>
);
return props.resource ? (
// support resource override via props
<ResourceContextProvider value={props.resource}>
{body}
</ResourceContextProvider>
) : (
body
);
};