Skip to content

Commit 02bbccf

Browse files
authored
Merge pull request #5604 from marmelab/save-context-value-side-effects-access
Make SaveContext provides access to side effects
2 parents 1ef2add + e465de7 commit 02bbccf

File tree

10 files changed

+640
-67
lines changed

10 files changed

+640
-67
lines changed

examples/simple/src/comments/CommentEdit.js

+58-53
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
AutocompleteInput,
77
DateInput,
88
EditActions,
9+
EditContextProvider,
910
useEditController,
1011
Link,
1112
ReferenceInput,
@@ -43,71 +44,75 @@ const inputText = record => `${record.title} - ${record.id}`;
4344

4445
const CommentEdit = props => {
4546
const classes = useEditStyles();
47+
const controllerProps = useEditController(props);
4648
const {
4749
resource,
4850
record,
4951
redirect,
5052
save,
5153
basePath,
5254
version,
53-
} = useEditController(props);
55+
} = controllerProps;
5456
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
6962
basePath={basePath}
70-
redirect={redirect}
7163
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}
8378
>
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>
9397

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>
111116
);
112117
};
113118

0 commit comments

Comments
 (0)