Skip to content

Commit c2d8edc

Browse files
authored
Merge pull request marmelab#10682 from marmelab/fix-guessers-reference-array
Fix `<ShowGuesser>` print incorrect code for reference arrays
2 parents 526a0d3 + 05232c3 commit c2d8edc

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

packages/ra-ui-materialui/src/detail/EditGuesser.spec.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ describe('<EditGuesser />', () => {
1919
score: 3,
2020
body: "Queen, tossing her head through the wood. 'If it had lost something; and she felt sure it.",
2121
created_at: new Date('2012-08-02'),
22+
tags_ids: [1, 2],
2223
},
2324
}),
2425
getMany: () => Promise.resolve({ data: [] }),
@@ -35,7 +36,7 @@ describe('<EditGuesser />', () => {
3536
});
3637
expect(logSpy).toHaveBeenCalledWith(`Guessed Edit:
3738
38-
import { DateInput, Edit, NumberInput, ReferenceInput, SimpleForm, TextInput } from 'react-admin';
39+
import { DateInput, Edit, NumberInput, ReferenceArrayInput, ReferenceInput, SimpleForm, TextInput } from 'react-admin';
3940
4041
export const CommentEdit = () => (
4142
<Edit>
@@ -46,6 +47,7 @@ export const CommentEdit = () => (
4647
<NumberInput source="score" />
4748
<TextInput source="body" />
4849
<DateInput source="created_at" />
50+
<ReferenceArrayInput source="tags_ids" reference="tags" />
4951
</SimpleForm>
5052
</Edit>
5153
);`);

packages/ra-ui-materialui/src/detail/ShowGuesser.spec.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ describe('<ShowGuesser />', () => {
1919
score: 3,
2020
body: "Queen, tossing her head through the wood. 'If it had lost something; and she felt sure it.",
2121
created_at: new Date('2012-08-02'),
22+
tags_ids: [1, 2],
2223
},
2324
}),
2425
};
@@ -34,7 +35,7 @@ describe('<ShowGuesser />', () => {
3435
});
3536
expect(logSpy).toHaveBeenCalledWith(`Guessed Show:
3637
37-
import { DateField, NumberField, ReferenceField, Show, SimpleShowLayout, TextField } from 'react-admin';
38+
import { DateField, NumberField, ReferenceArrayField, ReferenceField, Show, SimpleShowLayout, TextField } from 'react-admin';
3839
3940
export const CommentShow = () => (
4041
<Show>
@@ -45,6 +46,7 @@ export const CommentShow = () => (
4546
<NumberField source="score" />
4647
<TextField source="body" />
4748
<DateField source="created_at" />
49+
<ReferenceArrayField source="tags_ids" reference="tags" />
4850
</SimpleShowLayout>
4951
</Show>
5052
);`);

packages/ra-ui-materialui/src/detail/showFieldTypes.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ import {
1414
RichTextField,
1515
TextField,
1616
UrlField,
17+
ChipField,
1718
} from '../field';
1819
import { SimpleShowLayout, SimpleShowLayoutProps } from './SimpleShowLayout';
1920
import { InferredElement, InferredTypeMap, InputProps } from 'ra-core';
21+
import { SingleFieldList } from '../list';
2022

2123
export const showFieldTypes: InferredTypeMap = {
2224
show: {
@@ -81,14 +83,16 @@ ${children.map(child => ` ${child.getRepresentation()}`).join('\n')}
8183
referenceArray: {
8284
component: ReferenceArrayField,
8385
representation: (props: ReferenceArrayFieldProps) =>
84-
`<ReferenceArrayField source="${props.source}" reference="${props.reference}"><TextField source="id" /></ReferenceArrayField>`,
86+
`<ReferenceArrayField source="${props.source}" reference="${props.reference}" />`,
8587
},
8688
referenceArrayChild: {
87-
component: (
88-
props: { children: ReactNode } & Omit<InputProps, 'source'> &
89-
Partial<Pick<InputProps, 'source'>>
90-
) => <TextField source="id" {...props} />,
91-
representation: () => `<TextField source="id" />`,
89+
component: () => (
90+
<SingleFieldList>
91+
<ChipField source="id" />
92+
</SingleFieldList>
93+
),
94+
representation: () =>
95+
`<SingleFieldList><ChipField source="id" /></SingleFieldList>`,
9296
},
9397
richText: {
9498
component: RichTextField,

packages/ra-ui-materialui/src/list/ListGuesser.spec.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ describe('<ListGuesser />', () => {
2020
score: 3,
2121
body: "Queen, tossing her head through the wood. 'If it had lost something; and she felt sure it.",
2222
created_at: new Date('2012-08-02'),
23+
tags_ids: [1, 2],
2324
},
2425
],
2526
total: 1,
@@ -38,7 +39,7 @@ describe('<ListGuesser />', () => {
3839
});
3940
expect(logSpy).toHaveBeenCalledWith(`Guessed List:
4041
41-
import { Datagrid, DateField, List, NumberField, ReferenceField, TextField } from 'react-admin';
42+
import { Datagrid, DateField, List, NumberField, ReferenceArrayField, ReferenceField, TextField } from 'react-admin';
4243
4344
export const CommentList = () => (
4445
<List>
@@ -49,6 +50,7 @@ export const CommentList = () => (
4950
<NumberField source="score" />
5051
<TextField source="body" />
5152
<DateField source="created_at" />
53+
<ReferenceArrayField source="tags_ids" reference="tags" />
5254
</Datagrid>
5355
</List>
5456
);`);

0 commit comments

Comments
 (0)