Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make SaveContext provides access to side effects #5604

Merged
merged 5 commits into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 58 additions & 53 deletions examples/simple/src/comments/CommentEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
AutocompleteInput,
DateInput,
EditActions,
EditContextProvider,
useEditController,
Link,
ReferenceInput,
Expand Down Expand Up @@ -43,71 +44,75 @@ const inputText = record => `${record.title} - ${record.id}`;

const CommentEdit = props => {
const classes = useEditStyles();
const controllerProps = useEditController(props);
const {
resource,
record,
redirect,
save,
basePath,
version,
} = useEditController(props);
} = controllerProps;
return (
<div className="edit-page">
<Title defaultTitle={`Comment #${record ? record.id : ''}`} />
<div className={classes.actions}>
<EditActions
basePath={basePath}
resource={resource}
data={record}
hasShow
hasList
/>
</div>
<Card className={classes.card}>
{record && (
<SimpleForm
<EditContextProvider value={controllerProps}>
<div className="edit-page">
<Title defaultTitle={`Comment #${record ? record.id : ''}`} />
<div className={classes.actions}>
<EditActions
basePath={basePath}
redirect={redirect}
resource={resource}
record={record}
save={save}
version={version}
>
<TextInput disabled source="id" fullWidth />
<ReferenceInput
source="post_id"
reference="posts"
perPage={15}
sort={{ field: 'title', order: 'ASC' }}
fullWidth
data={record}
hasShow
hasList
/>
</div>
<Card className={classes.card}>
{record && (
<SimpleForm
basePath={basePath}
redirect={redirect}
resource={resource}
record={record}
save={save}
version={version}
>
<AutocompleteInput
matchSuggestion={(filterValue, suggestion) =>
true
}
optionText={<OptionRenderer />}
inputText={inputText}
options={{ fullWidth: true }}
/>
</ReferenceInput>
<TextInput disabled source="id" fullWidth />
<ReferenceInput
source="post_id"
reference="posts"
perPage={15}
sort={{ field: 'title', order: 'ASC' }}
fullWidth
>
<AutocompleteInput
matchSuggestion={(
filterValue,
suggestion
) => true}
optionText={<OptionRenderer />}
inputText={inputText}
options={{ fullWidth: true }}
/>
</ReferenceInput>

<LinkToRelatedPost />
<TextInput
source="author.name"
validate={minLength(10)}
fullWidth
/>
<DateInput source="created_at" fullWidth />
<TextInput
source="body"
validate={minLength(10)}
fullWidth={true}
multiline={true}
/>
</SimpleForm>
)}
</Card>
</div>
<LinkToRelatedPost />
<TextInput
source="author.name"
validate={minLength(10)}
fullWidth
/>
<DateInput source="created_at" fullWidth />
<TextInput
source="body"
validate={minLength(10)}
fullWidth={true}
multiline={true}
/>
</SimpleForm>
)}
</Card>
</div>
</EditContextProvider>
);
};

Expand Down
Loading