Skip to content

Commit

Permalink
Fix inference types
Browse files Browse the repository at this point in the history
  • Loading branch information
djhi committed Feb 4, 2021
1 parent f2af29e commit b89ed15
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/ra-core/src/inference/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import getElementsFromRecords from './getElementsFromRecords';
import InferredElement from './InferredElement';

export * from './inferTypeFromValues';
export * from './types';

export { getElementsFromRecords, InferredElement };
16 changes: 9 additions & 7 deletions packages/ra-ui-materialui/src/detail/editFieldTypes.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { ReactNode } from 'react';
import { ReactNode, ReactElement } from 'react';
import SimpleForm from '../form/SimpleForm';
import SimpleFormIterator from '../form/SimpleFormIterator';
import ArrayInput from '../input/ArrayInput';
Expand All @@ -12,9 +12,9 @@ import ReferenceArrayInput, {
} from '../input/ReferenceArrayInput';
import SelectInput from '../input/SelectInput';
import TextInput from '../input/TextInput';
import { InferredElement, InputProps } from 'ra-core';
import { InferredElement, InferredTypeMap, InputProps } from 'ra-core';

export default {
const editFieldTypes: InferredTypeMap = {
form: {
component: SimpleForm,
representation: (
Expand Down Expand Up @@ -74,7 +74,7 @@ ${children.map(child => ` ${child.getRepresentation()}`).join('\n')}
}">${children.getRepresentation()}</ReferenceInput>`,
},
referenceChild: {
component: (props: InputProps) => (
component: (props: { children: ReactNode } & InputProps) => (
<SelectInput optionText="id" {...props} />
), // eslint-disable-line react/display-name
representation: () => `<SelectInput optionText="id" />`,
Expand All @@ -85,9 +85,9 @@ ${children.map(child => ` ${child.getRepresentation()}`).join('\n')}
`<ReferenceArrayInput source="${props.source}" reference="${props.reference}"><TextInput source="id" /></ReferenceArrayInput>`,
},
referenceArrayChild: {
component: (props: InputProps) => (
<SelectInput optionText="id" {...props} />
), // eslint-disable-line react/display-name
component: (
props: { children: ReactNode } & InputProps
): ReactElement => <SelectInput optionText="id" {...props} />, // eslint-disable-line react/display-name
representation: () => `<SelectInput optionText="id" />`,
},
richText: {
Expand All @@ -106,3 +106,5 @@ ${children.map(child => ` ${child.getRepresentation()}`).join('\n')}
`<TextInput source="${props.source}" />`,
},
};

export default editFieldTypes;
14 changes: 10 additions & 4 deletions packages/ra-ui-materialui/src/detail/showFieldTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import RichTextField from '../field/RichTextField';
import SimpleShowLayout, { SimpleShowLayoutProps } from './SimpleShowLayout';
import TextField from '../field/TextField';
import UrlField from '../field/UrlField';
import { InferredElement, InputProps } from 'ra-core';
import { InferredElement, InferredTypeMap, InputProps } from 'ra-core';

export default {
const showFieldTypes: InferredTypeMap = {
show: {
component: (props: SimpleShowLayoutProps) => (
<SimpleShowLayout {...props} />
Expand Down Expand Up @@ -71,7 +71,9 @@ ${children.map(child => ` ${child.getRepresentation()}`).join('\n')}
`<ReferenceField source="${props.source}" reference="${props.reference}"><TextField source="id" /></ReferenceField>`,
},
referenceChild: {
component: (props: InputProps) => <TextField source="id" {...props} />, // eslint-disable-line react/display-name
component: (props: { children: ReactNode } & InputProps) => (
<TextField source="id" {...props} />
), // eslint-disable-line react/display-name
representation: () => `<TextField source="id" />`,
},
referenceArray: {
Expand All @@ -80,7 +82,9 @@ ${children.map(child => ` ${child.getRepresentation()}`).join('\n')}
`<ReferenceArrayField source="${props.source}" reference="${props.reference}"><TextField source="id" /></ReferenceArrayField>`,
},
referenceArrayChild: {
component: (props: InputProps) => <TextField source="id" {...props} />, // eslint-disable-line react/display-name
component: (props: { children: ReactNode } & InputProps) => (
<TextField source="id" {...props} />
), // eslint-disable-line react/display-name
representation: () => `<TextField source="id" />`,
},
richText: {
Expand All @@ -99,3 +103,5 @@ ${children.map(child => ` ${child.getRepresentation()}`).join('\n')}
`<UrlField source="${props.source}" />`,
},
};

export default showFieldTypes;

0 comments on commit b89ed15

Please sign in to comment.