Skip to content

Commit ea93745

Browse files
committed
make the representation prettier with indentation + use children instead of field prop
1 parent 96899d3 commit ea93745

File tree

1 file changed

+48
-16
lines changed

1 file changed

+48
-16
lines changed

packages/ra-ui-materialui/src/list/listFieldTypes.tsx

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,46 @@ ${children.map(child => ` ${child.getRepresentation()}`).join('\n')}
4343
);
4444
},
4545
representation: (props, children) =>
46-
`<DataTable.Col source="${props.source}"><ArrayField source="${
47-
props.source
48-
}"><SingleFieldList><ChipField source="${
49-
children.length > 0 && children[0].getProps().source
50-
}" /></SingleFieldList></ArrayField></DataTable.Col>`,
46+
`<DataTable.Col source="${props.source}">
47+
<ArrayField source="${props.source}">
48+
<SingleFieldList>
49+
<ChipField source="${children.length > 0 && children[0].getProps().source}" />
50+
</SingleFieldList>
51+
</ArrayField>
52+
</DataTable.Col>`,
5153
},
5254
boolean: {
53-
component: props => <DataTable.Col {...props} field={BooleanField} />,
55+
component: props => (
56+
<DataTable.Col {...props}>
57+
<BooleanField {...props} />
58+
</DataTable.Col>
59+
),
5460
representation: props =>
55-
`<DataTable.Col source="${props.source}" field={BooleanField} />`,
61+
`<DataTable.Col source="${props.source}" />
62+
<BooleanField source="${props.source}" />
63+
</DataTable.Col>`,
5664
},
5765
date: {
58-
component: props => <DataTable.Col {...props} field={DateField} />,
66+
component: props => (
67+
<DataTable.Col {...props}>
68+
<DateField {...props} />
69+
</DataTable.Col>
70+
),
5971
representation: props =>
60-
`<DataTable.Col source="${props.source}" field={DateField} />`,
72+
`<DataTable.Col source="${props.source}" />
73+
<DateField source="${props.source}" />
74+
</DataTable.Col>`,
6175
},
6276
email: {
63-
component: props => <DataTable.Col {...props} field={EmailField} />,
77+
component: props => (
78+
<DataTable.Col {...props}>
79+
<EmailField {...props} />
80+
</DataTable.Col>
81+
),
6482
representation: props =>
65-
`<DataTable.Col source="${props.source}" field={EmailField} />`,
83+
`<DataTable.Col source="${props.source}" />
84+
<EmailField source="${props.source}" />
85+
</DataTable.Col>`,
6686
},
6787
id: {
6888
component: props => <DataTable.Col {...props} />,
@@ -80,7 +100,9 @@ ${children.map(child => ` ${child.getRepresentation()}`).join('\n')}
80100
</DataTable.Col>
81101
),
82102
representation: props =>
83-
`<DataTable.Col source="${props.source}"><ReferenceField source="${props.source}" reference="${props.reference}" /></DataTable.Col>`,
103+
`<DataTable.Col source="${props.source}">
104+
<ReferenceField source="${props.source}" reference="${props.reference}" />
105+
</DataTable.Col>`,
84106
},
85107
referenceChild: {
86108
component: () => <TextField source="id" />,
@@ -93,7 +115,9 @@ ${children.map(child => ` ${child.getRepresentation()}`).join('\n')}
93115
</DataTable.Col>
94116
),
95117
representation: props =>
96-
`<DataTable.Col source="${props.source}"><ReferenceArrayField source="${props.source}" reference="${props.reference}" /></DataTable.Col>`,
118+
`<DataTable.Col source="${props.source}">
119+
<ReferenceArrayField source="${props.source}" reference="${props.reference}" />
120+
</DataTable.Col>`,
97121
},
98122
referenceArrayChild: {
99123
component: () => (
@@ -102,16 +126,24 @@ ${children.map(child => ` ${child.getRepresentation()}`).join('\n')}
102126
</SingleFieldList>
103127
),
104128
representation: () =>
105-
`<SingleFieldList><ChipField source="id" /></SingleFieldList>`,
129+
`<SingleFieldList>
130+
<ChipField source="id" />
131+
</SingleFieldList>`,
106132
},
107133
richText: undefined, // never display a rich text field in a datagrid
108134
string: {
109135
component: DataTable.Col,
110136
representation: props => `<DataTable.Col source="${props.source}" />`,
111137
},
112138
url: {
113-
component: props => <DataTable.Col {...props} field={UrlField} />,
139+
component: props => (
140+
<DataTable.Col {...props}>
141+
<UrlField {...props} />
142+
</DataTable.Col>
143+
),
114144
representation: props =>
115-
`<DataTable.Col source="${props.source}" field={UrlField} />`,
145+
`<DataTable.Col source="${props.source}" />
146+
<UrlField source="${props.source}" />
147+
</DataTable.Col>`,
116148
},
117149
};

0 commit comments

Comments
 (0)