forked from marmelab/react-admin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Edit.tsx
98 lines (96 loc) · 2.61 KB
/
Edit.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import * as React from 'react';
import { ReactElement } from 'react';
import PropTypes from 'prop-types';
import {
EditContextProvider,
ResourceContextProvider,
useCheckMinimumRequiredProps,
useEditController,
} from 'ra-core';
import { EditProps } from '../types';
import { EditView } from './EditView';
/**
* Page component for the Edit view
*
* The `<Edit>` component renders the page title and actions,
* fetches the record from the data provider.
* It is not responsible for rendering the actual form -
* that's the job of its child component (usually `<SimpleForm>`),
* to which it passes the `record` as prop.
*
* The <Edit> component accepts the following props:
*
* - actions
* - aside
* - component
* - successMessage
* - title
* - mutationMode
* - undoable (deprecated)
*
* @example
*
* // in src/posts.js
* import * as React from "react";
* import { Edit, SimpleForm, TextInput } from 'react-admin';
*
* export const PostEdit = (props) => (
* <Edit {...props}>
* <SimpleForm>
* <TextInput source="title" />
* </SimpleForm>
* </Edit>
* );
*
* // in src/App.js
* import * as React from "react";
* import { Admin, Resource } from 'react-admin';
*
* import { PostEdit } from './posts';
*
* const App = () => (
* <Admin dataProvider={...}>
* <Resource name="posts" edit={PostEdit} />
* </Admin>
* );
* export default App;
*/
export const Edit = (
props: EditProps & { children: ReactElement }
): ReactElement => {
useCheckMinimumRequiredProps('Edit', ['children'], props);
const controllerProps = useEditController(props);
const body = (
<EditContextProvider value={controllerProps}>
<EditView {...props} {...controllerProps} />
</EditContextProvider>
);
return props.resource ? (
// support resource override via props
<ResourceContextProvider value={props.resource}>
{body}
</ResourceContextProvider>
) : (
body
);
};
Edit.propTypes = {
actions: PropTypes.element,
aside: PropTypes.element,
children: PropTypes.node,
classes: PropTypes.object,
className: PropTypes.string,
hasCreate: PropTypes.bool,
hasEdit: PropTypes.bool,
hasShow: PropTypes.bool,
hasList: PropTypes.bool,
id: PropTypes.any.isRequired,
mutationMode: PropTypes.oneOf(['pessimistic', 'optimistic', 'undoable']),
onSuccess: PropTypes.func,
onFailure: PropTypes.func,
resource: PropTypes.string,
successMessage: PropTypes.string,
title: PropTypes.node,
transform: PropTypes.func,
undoable: PropTypes.bool,
};