|
1 | 1 | import * as React from 'react'; |
2 | | -import { Datagrid } from './datagrid'; |
| 2 | +import { DataTable } from './datatable'; |
3 | 3 | import { SingleFieldList } from './SingleFieldList'; |
4 | 4 | import { |
5 | 5 | ArrayField, |
6 | 6 | BooleanField, |
7 | 7 | ChipField, |
8 | 8 | DateField, |
9 | 9 | EmailField, |
10 | | - NumberField, |
11 | 10 | ReferenceField, |
12 | 11 | ReferenceArrayField, |
13 | | - TextField, |
14 | 12 | UrlField, |
15 | 13 | ArrayFieldProps, |
16 | 14 | } from '../field'; |
17 | 15 |
|
18 | 16 | export const listFieldTypes = { |
19 | 17 | table: { |
20 | 18 | component: props => { |
21 | | - return <Datagrid {...props} />; |
| 19 | + return <DataTable {...props} />; |
22 | 20 | }, |
23 | | - representation: (_props, children) => ` <Datagrid> |
| 21 | + representation: (_props, children) => ` <DataTable> |
24 | 22 | ${children.map(child => ` ${child.getRepresentation()}`).join('\n')} |
25 | | - </Datagrid>`, |
| 23 | + </DataTable>`, |
26 | 24 | }, |
27 | 25 | array: { |
28 | 26 | component: ({ children, ...props }: ArrayFieldProps) => { |
29 | 27 | const childrenArray = React.Children.toArray(children); |
30 | 28 | 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> |
42 | 42 | ); |
43 | 43 | }, |
44 | 44 | representation: (props, children) => |
45 | | - `<ArrayField source="${ |
| 45 | + `<DataTable.Col source="${props.source}"><ArrayField source="${ |
46 | 46 | props.source |
47 | 47 | }"><SingleFieldList><ChipField source="${ |
48 | 48 | children.length > 0 && children[0].getProps().source |
49 | | - }" /></SingleFieldList></ArrayField>`, |
| 49 | + }" /></SingleFieldList></ArrayField></DataTable.Col>`, |
50 | 50 | }, |
51 | 51 | 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} />`, |
54 | 55 | }, |
55 | 56 | 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} />`, |
58 | 60 | }, |
59 | 61 | 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} />`, |
62 | 65 | }, |
63 | 66 | 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}" />`, |
66 | 69 | }, |
67 | 70 | number: { |
68 | | - component: NumberField, |
69 | | - representation: props => `<NumberField source="${props.source}" />`, |
| 71 | + component: DataTable.NumberCol, |
| 72 | + representation: props => |
| 73 | + `<DataTable.NumberCol source="${props.source}" />`, |
70 | 74 | }, |
71 | 75 | reference: { |
72 | | - component: ReferenceField, |
| 76 | + component: props => ( |
| 77 | + <DataTable.Col {...props}> |
| 78 | + <ReferenceField {...props} /> |
| 79 | + </DataTable.Col> |
| 80 | + ), |
73 | 81 | 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>`, |
75 | 83 | }, |
76 | 84 | referenceChild: { |
77 | | - component: () => <TextField source="id" />, |
78 | | - representation: () => `<TextField source="id" />`, |
| 85 | + component: () => <DataTable.Col source="id" />, |
| 86 | + representation: () => `<DataTable.Col source="id" />`, |
79 | 87 | }, |
80 | 88 | referenceArray: { |
81 | | - component: ReferenceArrayField, |
| 89 | + component: props => ( |
| 90 | + <DataTable.Col {...props}> |
| 91 | + <ReferenceArrayField {...props} /> |
| 92 | + </DataTable.Col> |
| 93 | + ), |
82 | 94 | 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>`, |
84 | 96 | }, |
85 | 97 | referenceArrayChild: { |
86 | 98 | component: () => ( |
87 | | - <SingleFieldList> |
88 | | - <ChipField source="id" /> |
89 | | - </SingleFieldList> |
| 99 | + <DataTable.Col> |
| 100 | + <SingleFieldList> |
| 101 | + <ChipField source="id" /> |
| 102 | + </SingleFieldList> |
| 103 | + </DataTable.Col> |
90 | 104 | ), |
91 | 105 | representation: () => |
92 | | - `<SingleFieldList><ChipField source="id" /></SingleFieldList>`, |
| 106 | + `<DataTable.Col><SingleFieldList><ChipField source="id" /></SingleFieldList></DataTable.Col>`, |
93 | 107 | }, |
94 | 108 | richText: undefined, // never display a rich text field in a datagrid |
95 | 109 | string: { |
96 | | - component: TextField, |
97 | | - representation: props => `<TextField source="${props.source}" />`, |
| 110 | + component: DataTable.Col, |
| 111 | + representation: props => `<DataTable.Col source="${props.source}" />`, |
98 | 112 | }, |
99 | 113 | 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} />`, |
102 | 117 | }, |
103 | 118 | }; |
0 commit comments