|
6 | 6 | AutocompleteInput,
|
7 | 7 | DateInput,
|
8 | 8 | EditActions,
|
| 9 | + EditContextProvider, |
9 | 10 | useEditController,
|
10 | 11 | Link,
|
11 | 12 | ReferenceInput,
|
@@ -43,71 +44,75 @@ const inputText = record => `${record.title} - ${record.id}`;
|
43 | 44 |
|
44 | 45 | const CommentEdit = props => {
|
45 | 46 | const classes = useEditStyles();
|
| 47 | + const controllerProps = useEditController(props); |
46 | 48 | const {
|
47 | 49 | resource,
|
48 | 50 | record,
|
49 | 51 | redirect,
|
50 | 52 | save,
|
51 | 53 | basePath,
|
52 | 54 | version,
|
53 |
| - } = useEditController(props); |
| 55 | + } = controllerProps; |
54 | 56 | return (
|
55 |
| - <div className="edit-page"> |
56 |
| - <Title defaultTitle={`Comment #${record ? record.id : ''}`} /> |
57 |
| - <div className={classes.actions}> |
58 |
| - <EditActions |
59 |
| - basePath={basePath} |
60 |
| - resource={resource} |
61 |
| - data={record} |
62 |
| - hasShow |
63 |
| - hasList |
64 |
| - /> |
65 |
| - </div> |
66 |
| - <Card className={classes.card}> |
67 |
| - {record && ( |
68 |
| - <SimpleForm |
| 57 | + <EditContextProvider value={controllerProps}> |
| 58 | + <div className="edit-page"> |
| 59 | + <Title defaultTitle={`Comment #${record ? record.id : ''}`} /> |
| 60 | + <div className={classes.actions}> |
| 61 | + <EditActions |
69 | 62 | basePath={basePath}
|
70 |
| - redirect={redirect} |
71 | 63 | resource={resource}
|
72 |
| - record={record} |
73 |
| - save={save} |
74 |
| - version={version} |
75 |
| - > |
76 |
| - <TextInput disabled source="id" fullWidth /> |
77 |
| - <ReferenceInput |
78 |
| - source="post_id" |
79 |
| - reference="posts" |
80 |
| - perPage={15} |
81 |
| - sort={{ field: 'title', order: 'ASC' }} |
82 |
| - fullWidth |
| 64 | + data={record} |
| 65 | + hasShow |
| 66 | + hasList |
| 67 | + /> |
| 68 | + </div> |
| 69 | + <Card className={classes.card}> |
| 70 | + {record && ( |
| 71 | + <SimpleForm |
| 72 | + basePath={basePath} |
| 73 | + redirect={redirect} |
| 74 | + resource={resource} |
| 75 | + record={record} |
| 76 | + save={save} |
| 77 | + version={version} |
83 | 78 | >
|
84 |
| - <AutocompleteInput |
85 |
| - matchSuggestion={(filterValue, suggestion) => |
86 |
| - true |
87 |
| - } |
88 |
| - optionText={<OptionRenderer />} |
89 |
| - inputText={inputText} |
90 |
| - options={{ fullWidth: true }} |
91 |
| - /> |
92 |
| - </ReferenceInput> |
| 79 | + <TextInput disabled source="id" fullWidth /> |
| 80 | + <ReferenceInput |
| 81 | + source="post_id" |
| 82 | + reference="posts" |
| 83 | + perPage={15} |
| 84 | + sort={{ field: 'title', order: 'ASC' }} |
| 85 | + fullWidth |
| 86 | + > |
| 87 | + <AutocompleteInput |
| 88 | + matchSuggestion={( |
| 89 | + filterValue, |
| 90 | + suggestion |
| 91 | + ) => true} |
| 92 | + optionText={<OptionRenderer />} |
| 93 | + inputText={inputText} |
| 94 | + options={{ fullWidth: true }} |
| 95 | + /> |
| 96 | + </ReferenceInput> |
93 | 97 |
|
94 |
| - <LinkToRelatedPost /> |
95 |
| - <TextInput |
96 |
| - source="author.name" |
97 |
| - validate={minLength(10)} |
98 |
| - fullWidth |
99 |
| - /> |
100 |
| - <DateInput source="created_at" fullWidth /> |
101 |
| - <TextInput |
102 |
| - source="body" |
103 |
| - validate={minLength(10)} |
104 |
| - fullWidth={true} |
105 |
| - multiline={true} |
106 |
| - /> |
107 |
| - </SimpleForm> |
108 |
| - )} |
109 |
| - </Card> |
110 |
| - </div> |
| 98 | + <LinkToRelatedPost /> |
| 99 | + <TextInput |
| 100 | + source="author.name" |
| 101 | + validate={minLength(10)} |
| 102 | + fullWidth |
| 103 | + /> |
| 104 | + <DateInput source="created_at" fullWidth /> |
| 105 | + <TextInput |
| 106 | + source="body" |
| 107 | + validate={minLength(10)} |
| 108 | + fullWidth={true} |
| 109 | + multiline={true} |
| 110 | + /> |
| 111 | + </SimpleForm> |
| 112 | + )} |
| 113 | + </Card> |
| 114 | + </div> |
| 115 | + </EditContextProvider> |
111 | 116 | );
|
112 | 117 | };
|
113 | 118 |
|
|
0 commit comments