Skip to content

Commit 26acc5d

Browse files
committed
Update ListGuesser with DataTable
1 parent b8c3940 commit 26acc5d

File tree

2 files changed

+60
-45
lines changed

2 files changed

+60
-45
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import { listFieldTypes } from './listFieldTypes';
1818
import { capitalize, singularize } from 'inflection';
1919

2020
/**
21-
* List component rendering a <Datagrid> based on the result of the
21+
* List component rendering a <DataTable> based on the result of the
2222
* dataProvider.getList() call.
2323
*
2424
* The result (choice and type of columns) isn't configurable, but the
25-
* <ListGuesser> outputs the <Datagrid> it has guessed to the console so that
25+
* <ListGuesser> outputs the <DataTable> it has guessed to the console so that
2626
* developers can start from there.
2727
*
2828
* To be used as the list prop of a <Resource>.
Lines changed: 58 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,118 @@
11
import * as React from 'react';
2-
import { Datagrid } from './datagrid';
2+
import { DataTable } from './datatable';
33
import { SingleFieldList } from './SingleFieldList';
44
import {
55
ArrayField,
66
BooleanField,
77
ChipField,
88
DateField,
99
EmailField,
10-
NumberField,
1110
ReferenceField,
1211
ReferenceArrayField,
13-
TextField,
1412
UrlField,
1513
ArrayFieldProps,
1614
} from '../field';
1715

1816
export const listFieldTypes = {
1917
table: {
2018
component: props => {
21-
return <Datagrid {...props} />;
19+
return <DataTable {...props} />;
2220
},
23-
representation: (_props, children) => ` <Datagrid>
21+
representation: (_props, children) => ` <DataTable>
2422
${children.map(child => ` ${child.getRepresentation()}`).join('\n')}
25-
</Datagrid>`,
23+
</DataTable>`,
2624
},
2725
array: {
2826
component: ({ children, ...props }: ArrayFieldProps) => {
2927
const childrenArray = React.Children.toArray(children);
3028
return (
31-
<ArrayField {...props}>
32-
<SingleFieldList>
33-
<ChipField
34-
source={
35-
childrenArray.length > 0 &&
36-
React.isValidElement(childrenArray[0]) &&
37-
childrenArray[0].props.source
38-
}
39-
/>
40-
</SingleFieldList>
41-
</ArrayField>
29+
<DataTable.Col {...props}>
30+
<ArrayField {...props}>
31+
<SingleFieldList>
32+
<ChipField
33+
source={
34+
childrenArray.length > 0 &&
35+
React.isValidElement(childrenArray[0]) &&
36+
childrenArray[0].props.source
37+
}
38+
/>
39+
</SingleFieldList>
40+
</ArrayField>
41+
</DataTable.Col>
4242
);
4343
},
4444
representation: (props, children) =>
45-
`<ArrayField source="${
45+
`<DataTable.Col source="${props.source}"><ArrayField source="${
4646
props.source
4747
}"><SingleFieldList><ChipField source="${
4848
children.length > 0 && children[0].getProps().source
49-
}" /></SingleFieldList></ArrayField>`,
49+
}" /></SingleFieldList></ArrayField></DataTable.Col>`,
5050
},
5151
boolean: {
52-
component: BooleanField,
53-
representation: props => `<BooleanField source="${props.source}" />`,
52+
component: props => <DataTable.Col {...props} field={BooleanField} />,
53+
representation: props =>
54+
`<DataTable.Col source="${props.source}" field={BooleanField} />`,
5455
},
5556
date: {
56-
component: DateField,
57-
representation: props => `<DateField source="${props.source}" />`,
57+
component: props => <DataTable.Col {...props} field={DateField} />,
58+
representation: props =>
59+
`<DataTable.Col source="${props.source}" field={DateField} />`,
5860
},
5961
email: {
60-
component: EmailField,
61-
representation: props => `<EmailField source="${props.source}" />`,
62+
component: props => <DataTable.Col {...props} field={EmailField} />,
63+
representation: props =>
64+
`<DataTable.Col source="${props.source}" field={EmailField} />`,
6265
},
6366
id: {
64-
component: TextField,
65-
representation: props => `<TextField source="${props.source}" />`,
67+
component: props => <DataTable.Col {...props} />,
68+
representation: props => `<DataTable.Col source="${props.source}" />`,
6669
},
6770
number: {
68-
component: NumberField,
69-
representation: props => `<NumberField source="${props.source}" />`,
71+
component: DataTable.NumberCol,
72+
representation: props =>
73+
`<DataTable.NumberCol source="${props.source}" />`,
7074
},
7175
reference: {
72-
component: ReferenceField,
76+
component: props => (
77+
<DataTable.Col {...props}>
78+
<ReferenceField {...props} />
79+
</DataTable.Col>
80+
),
7381
representation: props =>
74-
`<ReferenceField source="${props.source}" reference="${props.reference}" />`,
82+
`<DataTable.Col source="${props.source}"><ReferenceField source="${props.source}" reference="${props.reference}" /></DataTable.Col>`,
7583
},
7684
referenceChild: {
77-
component: () => <TextField source="id" />,
78-
representation: () => `<TextField source="id" />`,
85+
component: () => <DataTable.Col source="id" />,
86+
representation: () => `<DataTable.Col source="id" />`,
7987
},
8088
referenceArray: {
81-
component: ReferenceArrayField,
89+
component: props => (
90+
<DataTable.Col {...props}>
91+
<ReferenceArrayField {...props} />
92+
</DataTable.Col>
93+
),
8294
representation: props =>
83-
`<ReferenceArrayField source="${props.source}" reference="${props.reference}" />`,
95+
`<DataTable.Col source="${props.source}"><ReferenceArrayField source="${props.source}" reference="${props.reference}" /></DataTable.Col>`,
8496
},
8597
referenceArrayChild: {
8698
component: () => (
87-
<SingleFieldList>
88-
<ChipField source="id" />
89-
</SingleFieldList>
99+
<DataTable.Col>
100+
<SingleFieldList>
101+
<ChipField source="id" />
102+
</SingleFieldList>
103+
</DataTable.Col>
90104
),
91105
representation: () =>
92-
`<SingleFieldList><ChipField source="id" /></SingleFieldList>`,
106+
`<DataTable.Col><SingleFieldList><ChipField source="id" /></SingleFieldList></DataTable.Col>`,
93107
},
94108
richText: undefined, // never display a rich text field in a datagrid
95109
string: {
96-
component: TextField,
97-
representation: props => `<TextField source="${props.source}" />`,
110+
component: DataTable.Col,
111+
representation: props => `<DataTable.Col source="${props.source}" />`,
98112
},
99113
url: {
100-
component: UrlField,
101-
representation: props => `<UrlField source="${props.source}" />`,
114+
component: props => <DataTable.Col {...props} field={UrlField} />,
115+
representation: props =>
116+
`<DataTable.Col source="${props.source}" field={UrlField} />`,
102117
},
103118
};

0 commit comments

Comments
 (0)