You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: admin/components.md
+48-46Lines changed: 48 additions & 46 deletions
Original file line number
Diff line number
Diff line change
@@ -4,29 +4,30 @@
4
4
5
5
### AdminGuesser
6
6
7
-
`<AdminGuesser>` creates a complete Admin Context and Interface, rendering automatically an [`<AdminUI>` component](https://marmelab.com/react-admin/Admin.html#unplugging-the-admin-using-admincontext-and-adminui) for resources exposed by a web API documented with any format supported by `@api-platform/api-doc-parser` (for Hydra documented APIs,
8
-
use the [`<HydraAdmin>`component](admin/components.md#hydraadmin) instead). It also creates a [`schemaAnalyzer`](admin/components.md#schemaAnalyzer) context, where the schemaAnalyzer service (for getting information about the provided API documentation) is stored.
7
+
`<AdminGuesser>` renders automatically an [<Admin> component](https://marmelab.com/react-admin/Admin.html) for resources exposed by a web API documented with any format supported by `@api-platform/api-doc-parser` (for Hydra documented APIs,
8
+
use the [<HydraAdmin> component](components.md#hydraadmin) instead).
9
+
It also creates a [schema analyzer](components.md#schemaanalyzer) context, where the `schemaAnalyzer` service (for getting information about the provided API documentation) is stored.
9
10
10
-
The `<AdminGuesser>` renders all exposed resources by default, but you can choose what resource you want to render by passing [`<ResourceGuesser>` components](admin/components/#resourceguesser) as children.
11
+
`<AdminGuesser>` renders all exposed resources by default, but you can choose what resource you want to render by passing [<ResourceGuesser> components](components.md#resourceguesser) as children.
11
12
Deprecated resources are hidden by default, but you can add them back using an explicit `<ResourceGuesser>` component.
Based on React-Admin's [`<Resource>` component](https://marmelab.com/react-admin/Resource.html), the ResourceGuesser provides default props [`<CreateGuesser>`](admin/components.md#createguesser), [`<ListGuesser>`](admin/components.md#listguesser), [`<EditGuesser>`](admin/components.md#editguesser) and [`<ShowGuesser>`](admin/components.md#showguesser).
48
-
Otherwise you can pass it your own CRUD components using `create`, `list`, `edit`, `show` props.
48
+
Based on ReactAdmin[<Resource> component](https://marmelab.com/react-admin/Resource.html), `ResourceGuesser` provides default props [<CreateGuesser>](components.md#createguesser), [<ListGuesser>](components.md#listguesser), [<EditGuesser>](components.md#editguesser) and [<ShowGuesser>](components.md#showguesser).
49
+
Otherwise, you can pass it your own CRUD components using `create`, `list`, `edit`, `show` props.
| name | string | - | yes | endpoint of the resource |
78
79
79
-
You can also use props accepted by React-Admin's [`<Resource>` component](https://marmelab.com/react-admin/Resource.html). For example, the props `list`, `show`, `create`&`edit`.
80
+
You can also use props accepted by ReactAdmin[<Resource> component](https://marmelab.com/react-admin/Resource.html). For example, the props `list`, `show`, `create`or`edit`.
80
81
81
82
## Page Components
82
83
83
84
### ListGuesser
84
85
85
-
Based on React-Admin's [`<List>`](https://marmelab.com/react-admin/List.html), ListGuesser displays a list of resources in a [`<Datagrid>`](https://marmelab.com/react-admin/List.html#the-datagrid-component), according to children passed to it (usually [`<FieldGuesser>`](admin/components/#fieldguesser) or any [`field` component](https://marmelab.com/react-admin/Fields.html#basic-fields)
86
-
available in React-Admin).
86
+
Based on ReactAdmin[<List>](https://marmelab.com/react-admin/List.html), ListGuesser displays a list of resources in a [<Datagrid>](https://marmelab.com/react-admin/List.html#the-datagrid-component), according to children passed to it (usually [<FieldGuesser>](components.md#fieldguesser) or any [field component](https://marmelab.com/react-admin/Fields.html#basic-fields)
87
+
available in ReactAdmin).
87
88
88
89
Use `hasShow` and `hasEdit` props if you want to display `show` and `edit` buttons (both set to `true` by default).
89
90
90
-
By default, `<ListGuesser>` comes with [`<Pagination>`](admin/components.md#pagination).
91
+
By default, `<ListGuesser>` comes with [<Pagination>](components.md#pagination).
| resource | string | - | yes | endpoint of the resource |
114
115
| filters | element | - | no | filters that can be applied to the list |
115
116
116
-
You can also use props accepted by React-Admin's [`<List>`](https://marmelab.com/react-admin/List.html).
117
+
You can also use props accepted by ReactAdmin[<List>](https://marmelab.com/react-admin/List.html).
117
118
118
119
### CreateGuesser
119
120
120
-
Displays a creation page for a single item. Uses React-Admin's [`<Create>`](https://marmelab.com/react-admin/Edit.html) and [`<SimpleForm>`](https://marmelab.com/react-admin/CreateEdit.html#the-simpleform-component).
121
-
For simple inputs, you can pass as children API Platform Admin's [`<InputGuesser>`](admin/components.md#inputguesser), or any React-Admin's [`Input components`](https://marmelab.com/react-admin/Inputs.html#input-components) for more complex inputs.
121
+
Displays a creation page for a single item. Uses ReactAdmin[<Create>](https://marmelab.com/react-admin/CreateEdit.html) and [<SimpleForm>](https://marmelab.com/react-admin/CreateEdit.html#the-simpleform-component) components.
122
+
For simple inputs, you can pass as children API Platform Admin[<InputGuesser>](components.md#inputguesser), or any ReactAdmin[Input components](https://marmelab.com/react-admin/Inputs.html#input-components) for more complex inputs.
| resource | string | - | yes | endpoint of the resource |
145
145
146
-
You can also use props accepted by React-Admin's [`<Create>`](https://marmelab.com/react-admin/Edit.html).
146
+
You can also use props accepted by ReactAdmin[<Create>](https://marmelab.com/react-admin/CreateEdit.html).
147
147
148
148
### EditGuesser
149
149
150
-
Displays an edition page for a single item. Uses React-Admin's [`<Edit>`](https://marmelab.com/react-admin/Edit.html) and [`<SimpleForm>`](https://marmelab.com/react-admin/CreateEdit.html#the-simpleform-component) components.
151
-
For simple inputs, you can use API Platform Admin's [`<InputGuesser>`](admin/components.md#inputguesser), or any React-Admin's [`Input components`](https://marmelab.com/react-admin/Inputs.html#input-components) for more complex inputs.
150
+
Displays an edition page for a single item. Uses ReactAdmin[<Edit>](https://marmelab.com/react-admin/CreateEdit.html) and [<SimpleForm>](https://marmelab.com/react-admin/CreateEdit.html#the-simpleform-component) components.
151
+
For simple inputs, you can use API Platform Admin[<InputGuesser>](components.md#inputguesser), or any ReactAdmin[Input components](https://marmelab.com/react-admin/Inputs.html#input-components) for more complex inputs.
| resource | string | - | yes | endpoint of the resource |
174
174
175
-
You can also use props accepted by React-Admin's [`<Edit>`](https://marmelab.com/react-admin/Edit.html).
175
+
You can also use props accepted by ReactAdmin[<Edit>](https://marmelab.com/react-admin/CreateEdit.html).
176
176
177
177
### ShowGuesser
178
178
179
-
Displays a detailed page for one item. Based on React-Admin's [`<Show>` component](https://marmelab.com/react-admin/Show.html). You can pass [`<FieldGuesser>`](admin/components.md#fieldguesser) as children for simple fields, or use any of React-Admin's [`Basic Fields`](https://marmelab.com/react-admin/Fields.html#basic-fields) for more complex fields.
179
+
Displays a detailed page for one item. Based on ReactAdmin[<Show> component](https://marmelab.com/react-admin/Show.html). You can pass [<FieldGuesser>](components.md#fieldguesser) as children for simple fields, or use any of ReactAdmin[basic fields](https://marmelab.com/react-admin/Fields.html#basic-fields) for more complex fields.
| resource | string | - | yes | endpoint of the resource |
202
202
203
-
You can also use props accepted by React-Admin's [`<Show>` component](https://marmelab.com/react-admin/Show.html).
203
+
You can also use props accepted by ReactAdmin[<Show> component](https://marmelab.com/react-admin/Show.html).
204
204
205
205
## Hydra
206
206
207
207
### HydraAdmin
208
208
209
-
Creates a complete Admin Context and Interface, as [`<AdminGuesser>`](/admin/components.md#adminguesser), but configured specially for [Hydra](https://www.hydra-cg.com/). If you want to use other formats (see supported formats: `@api-platform/api-doc-parser`) use the [`<AdminGuesser>`](admin/components.md#adminguesser) instead.
209
+
Creates a complete Admin, as [`<AdminGuesser>`](components.md#adminguesser), but configured specially for [Hydra](https://www.hydra-cg.com/). If you want to use other formats (see supported formats: `@api-platform/api-doc-parser`) use [<AdminGuesser>](components.md#adminguesser) instead.
| entrypoint | string | - | yes | entrypoint of the API |
234
234
235
-
### dataProvider
235
+
### Data Provider
236
236
237
-
Based on React-Admin's `Create`, `Delete`, `getList`, `getManyReference`, `GetOne`, `Update` methods, the `dataProvider` is used by API Platform Admin to communicate with the API. In addition, the specific `introspect` method parses your API documentation.
238
-
Note that the `dataProvider` can be overrided to fit your API needs.
237
+
Based on ReactAdmin`create`, `delete`, `getList`, `getManyReference`, `getOne`, `update` methods, the `dataProvider` is used by API Platform Admin to communicate with the API. In addition, the specific `introspect` method parses your API documentation.
238
+
Note that the `dataProvider` can be overridden to fit your API needs.
239
239
240
-
### schemaAnalyzer
240
+
### Schema Analyzer
241
241
242
242
Analyses your resources and retrieves their types according to the [Schema.org](https://schema.org) vocabulary.
243
243
244
244
## Other Components
245
245
246
246
### Pagination
247
247
248
-
Set by default in the [`<ListGuesser/>` component](/admin/components.md#listguesser), the `<Pagination/> component` uses React-Admin's [`<Pagination>` component](https://marmelab.com/react-admin/List.html#pagination). By default, it renders 30 items per page and displays a navigation UI. If you want to change the number of items per page or disable the pagination, see the [`Pagination` documentation](https://api-platform.com/docs/core/pagination/#pagination).
248
+
Set by default in the [<ListGuesser> component](components.md#listguesser), the `Pagination` component uses React Admin [<Pagination> component](https://marmelab.com/react-admin/List.html#pagination).
249
+
By default, it renders 30 items per page and displays a navigation UI. If you want to change the number of items per page or disable the pagination, see the [Pagination documentation](../core/pagination.md).
250
+
It is also capable to handle partial pagination.
249
251
250
252
### FieldGuesser
251
253
252
-
Renders fields according to their types, using [`schemaAnalyzer`](/admin/components.md#schemaanalyzer). Based on React-Admin's [`<ReferenceField>` component](https://marmelab.com/react-admin/Fields.html#referencefield).
254
+
Renders fields according to their types, using the [schema analyzer](components.md#schemaanalyzer). Based on ReactAdmin[field components](https://marmelab.com/react-admin/Fields.html).
| source | string | - | yes | endpoint of the resource |
274
276
275
-
You can also use props accepted by React-Admin's [`Basic Fields`](https://marmelab.com/react-admin/Fields.html#basic-fields).
277
+
You can also use props accepted by ReactAdmin[basic fields](https://marmelab.com/react-admin/Fields.html#basic-fields).
276
278
277
279
### InputGuesser
278
280
279
-
Uses React-Admin's [`<ReferenceInput>`](https://marmelab.com/react-admin/Inputs.html#referenceinput) to generate inputs according to your API documentation (e.g. number HTML input for numbers, checkbox for booleans, selectbox for relationships...)
281
+
Uses ReactAdmin[input components](https://marmelab.com/react-admin/Inputs.html) to generate inputs according to your API documentation (e.g. number HTML input for numbers, checkbox for booleans, selectbox for relationships...).
Copy file name to clipboardExpand all lines: admin/index.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ according to the API-first paradigm.
14
14
API Platform Admin parses the API documentation then uses the awesome [React Admin](https://marmelab.com/react-admin/)
15
15
library to expose a nice, responsive, management interface (Create-Retrieve-Update-Delete) for all documented resource types.
16
16
17
-
You can **customize everything** by using provided React Admin and [Material UI](https://material-ui.com/) components, or by writing your custom [React](https://reactjs.org/) components.
17
+
You can **customize everything** by using provided React Admin and [Material UI](https://material-ui.com/) components, or by writing your custom [React](https://reactjs.org/) components.
API Platform Admin manages automatically two types of validation: client-side validation and server-side (or submission) validation.
4
+
5
+
## Client-side Validation
6
+
7
+
If the API documentation indicates that a field is mandatory,
8
+
API Platform Admin will automatically add a [required client-side validation](https://marmelab.com/react-admin/CreateEdit.html#per-input-validation-built-in-field-validators).
9
+
10
+
For instance, with API Platform Core as backend, if you write the following:
11
+
12
+
```php
13
+
<?php
14
+
// api/src/Entity/Book.php
15
+
16
+
use ApiPlatform\Core\Annotation\ApiResource;
17
+
use Symfony\Component\Validator\Constraints as Assert;
18
+
19
+
/**
20
+
* @ApiResource
21
+
*/
22
+
class Book
23
+
{
24
+
/**
25
+
* @Assert\NotBlank
26
+
*/
27
+
public ?string $title = null;
28
+
}
29
+
```
30
+
31
+
If you create a new book and touch the "Title" field without typing, you will see:
32
+
33
+

34
+
35
+
## Server-side Validation
36
+
37
+
When the form is submitted and if submission errors are received,
38
+
API Platform Admin will automatically show the errors for the corresponding fields.
39
+
40
+
To do so, it uses the [submission validation](https://marmelab.com/react-admin/CreateEdit.html#submission-validation) feature of React Admin,
41
+
and the mapping between the response and the fields is done by the [schema analyzer](components.md#schemaanalyzer) with its method `getSubmissionErrors`.
42
+
43
+
API Platform Core is supported by default, but if you use another backend, you will need to override the `getSubmissionErrors` method.
44
+
45
+
For example if you have this code:
46
+
47
+
```php
48
+
<?php
49
+
// api/src/Entity/Book.php
50
+
51
+
use ApiPlatform\Core\Annotation\ApiResource;
52
+
use Symfony\Component\Validator\Constraints as Assert;
53
+
54
+
/**
55
+
* @ApiResource
56
+
*/
57
+
class Book
58
+
{
59
+
/**
60
+
* @Assert\Isbn
61
+
*/
62
+
public ?string $isbn = null;
63
+
}
64
+
```
65
+
66
+
If you submit the form with an invalid ISBN, you will see:
0 commit comments