Skip to content

Commit

Permalink
feat: Show|Create|EditGuesser viewComponent prop (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelSuwinski authored Mar 6, 2024
1 parent 295369b commit b995088
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/CreateGuesser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const IntrospectedCreateGuesser = ({
warnWhenUnsavedChanges,
sanitizeEmptyValues = true,
formComponent,
viewComponent,
children,
...props
}: IntrospectedCreateGuesserProps) => {
Expand Down Expand Up @@ -162,7 +163,7 @@ export const IntrospectedCreateGuesser = ({
const FormType = hasFormTab ? TabbedForm : SimpleForm;

return (
<Create resource={resource} {...props}>
<Create resource={resource} component={viewComponent} {...props}>
<FormType
onSubmit={save}
mode={mode}
Expand Down
2 changes: 2 additions & 0 deletions src/EditGuesser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const IntrospectedEditGuesser = ({
toolbar,
warnWhenUnsavedChanges,
formComponent,
viewComponent,
sanitizeEmptyValues = true,
children,
...props
Expand Down Expand Up @@ -197,6 +198,7 @@ export const IntrospectedEditGuesser = ({
id={id}
mutationMode={mutationMode}
redirect={redirectTo}
component={viewComponent}
transform={(data: Partial<RaRecord>) => ({
...data,
extraInformation: { hasFileField },
Expand Down
3 changes: 2 additions & 1 deletion src/ShowGuesser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const IntrospectedShowGuesser = ({
writableFields,
schema,
schemaAnalyzer,
viewComponent,
children,
...props
}: IntrospectedShowGuesserProps) => {
Expand All @@ -70,7 +71,7 @@ export const IntrospectedShowGuesser = ({
const ShowLayout = hasTab ? TabbedShowLayout : SimpleShowLayout;

return (
<Show {...props}>
<Show component={viewComponent} {...props}>
<ShowLayout>{fieldChildren}</ShowLayout>
</Show>
);
Expand Down
9 changes: 6 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ type CreateFormProps = Omit<
CreateProps & SimpleFormProps & TabbedFormProps,
'children'
> &
Partial<PickRename<CreateProps, 'component', 'viewComponent'>> &
Partial<
PickRename<SimpleFormProps & TabbedFormProps, 'component', 'formComponent'>
> & {
Expand All @@ -389,6 +390,7 @@ type EditFormProps = Omit<
EditProps & SimpleFormProps & TabbedFormProps,
'children'
> &
Partial<PickRename<EditProps, 'component', 'viewComponent'>> &
Partial<
PickRename<SimpleFormProps & TabbedFormProps, 'component', 'formComponent'>
> & {
Expand Down Expand Up @@ -422,9 +424,10 @@ export type ListGuesserProps = Omit<
type ShowFormProps = Omit<
ShowProps & SimpleFormProps & TabbedFormProps,
'children'
> & {
children?: ReactNode;
};
> &
Partial<PickRename<ShowProps, 'component', 'viewComponent'>> & {
children?: ReactNode;
};

export type IntrospectedShowGuesserProps = ShowFormProps &
IntrospectedGuesserProps;
Expand Down

0 comments on commit b995088

Please sign in to comment.