Skip to content

Commit 0155a34

Browse files
authored
Merge pull request #9123 from marmelab/doc-howtos-review
[Doc] Fix HowTos order and syntax in various chapters
2 parents 605f8aa + b90eec3 commit 0155a34

File tree

11 files changed

+305
-344
lines changed

11 files changed

+305
-344
lines changed

docs/Datagrid.md

Lines changed: 176 additions & 194 deletions
Large diffs are not rendered by default.

docs/Fields.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,17 +368,15 @@ const BookEdit = () => (
368368
);
369369
```
370370

371-
## Hiding A Field Label
371+
## Hiding The Field Label
372372

373-
You can opt out of the label decoration by passing `false` to the `label` prop.
373+
React-admin Field layout components like [`<Datagrid>`](./Datagrid.md) and [`<SimpleShowLayout>`](./SimpleShowLayout.md) inspect their children and use their `source` prop to set the table headers or the field labels. To opt out of this behavior, pass `false` to the `label` prop.
374374

375375
```jsx
376-
// No label will be added
376+
// No label will be added in SimpleShowLayout
377377
<TextField source="author.name" label={false} />
378378
```
379379

380-
**Note**: This prop has no effect when rendering a field outside a `<Datagrid>`, a `<SimpleShowLayout>`, a `<TabbedShowLayout>`, a `<SimpleForm>`, or a `<TabbedForm>`.
381-
382380
## Conditional Formatting
383381

384382
If you want to format a field depending on the value, create another component wrapping this field, and set the `sx` prop depending on the field value:

docs/FilterList.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const PostFilterSidebar = () => (
5050
```
5151
{% endraw %}
5252

53-
Add this component to the list view using [the `<List aside>` prop](./List.md#aside-side-component):
53+
Add this component to the list view using [the `<List aside>` prop](./List.md#aside):
5454

5555
```jsx
5656
import { PostFilterSidebar } from './PostFilterSidebar';

docs/List.md

Lines changed: 31 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,26 @@ You can find more advanced examples of `<List>` usage in the [demos](./Demos.md)
5252

5353
| Prop | Required | Type | Default | Description |
5454
|---------------------------|----------|----------------|----------------|----------------------------------------------------------------------------------------------|
55-
| `children` | Required | `ReactNode` | - | The component to use to render the list of records. |
55+
| `children` | Required | `ReactNode` | - | The components rendering the list of records. |
5656
| `actions` | Optional | `ReactElement` | - | The actions to display in the toolbar. |
5757
| `aside` | Optional | `ReactElement` | - | The component to display on the side of the list. |
5858
| `component` | Optional | `Component` | `Card` | The component to render as the root element. |
5959
| `debounce` | Optional | `number` | `500` | The debounce delay in milliseconds to apply when users change the sort or filter parameters. |
6060
| `disable Authentication` | Optional | `boolean` | `false` | Set to `true` to disable the authentication check. |
6161
| `disable SyncWithLocation`| Optional | `boolean` | `false` | Set to `true` to disable the synchronization of the list parameters with the URL. |
6262
| `empty` | Optional | `ReactElement` | - | The component to display when the list is empty. |
63-
| `emptyWhileLoading` | Optional | `boolean` | `false` | Set to `true` to return `null` while the list is loading. |
63+
| `empty WhileLoading` | Optional | `boolean` | `false` | Set to `true` to return `null` while the list is loading. |
6464
| `exporter` | Optional | `function` | - | The function to call to export the list. |
6565
| `filters` | Optional | `ReactElement` | - | The filters to display in the toolbar. |
6666
| `filter` | Optional | `object` | - | The permanent filter values. |
67-
| `filterDefaultValues` | Optional | `object` | - | The default filter values. |
67+
| `filter DefaultValues` | Optional | `object` | - | The default filter values. |
6868
| `hasCreate` | Optional | `boolean` | `false` | Set to `true` to show the create button. |
6969
| `pagination` | Optional | `ReactElement` | `<Pagination>` | The pagination component to use. |
7070
| `perPage` | Optional | `number` | `10` | The number of records to fetch per page. |
7171
| `queryOptions` | Optional | `object` | - | The options to pass to the `useQuery` hook. |
7272
| `resource` | Optional | `string` | - | The resource name, e.g. `posts`. |
7373
| `sort` | Optional | `object` | - | The initial sort parameters. |
74-
| `storeKey` | Optional | `string` | `false` | - | The key to use to store the current filter & sort. Pass `false` to disable |
74+
| `storeKey` | Optional | `string | false` | - | The key to use to store the current filter & sort. Pass `false` to disable |
7575
| `title` | Optional | `string` | - | The title to display in the App Bar. |
7676
| `sx` | Optional | `object` | - | The CSS styles to apply to the component. |
7777

@@ -143,7 +143,7 @@ const ListActions = () => {
143143
}
144144
```
145145

146-
## `aside`: Side Component
146+
## `aside`
147147

148148
You may want to display additional information on the side of the list. Use the `aside` prop for that, passing the component of your choice:
149149

@@ -232,7 +232,7 @@ export const PostList = () => (
232232

233233
**Tip**: the `<Card sx>` prop in the `PostFilterSidebar` component above is here to put the sidebar on the left side of the screen, instead of the default right side.
234234

235-
## `children`: List Layout
235+
## `children`
236236

237237
`<List>` itself doesn't render the list of records. It delegates this task to its children components. These children components grab the `data` from the `ListContext` and render them on screen.
238238

@@ -397,7 +397,7 @@ const Dashboard = () => (
397397

398398
Please note that the selection state is not synced in the URL but in a global store using the resource as key. Thus, all lists in the page using the same resource will share the same selection state. This is a design choice because if row selection is not tied to a resource, then when a user deletes a record it may remain selected without any ability to unselect it. If you want the selection state to be local, you will have to implement your own `useListController` hook and pass a custom key to the `useRecordSelection` hook. You will then need to implement your own `DeleteButton` and `BulkDeleteButton` to manually unselect rows when deleting records.
399399

400-
## `empty`: Empty Page Component
400+
## `empty`
401401

402402
When there is no result, and there is no active filter, and the resource has a create page, react-admin displays a special page inviting the user to create the first record.
403403

@@ -694,7 +694,7 @@ export const PostList = () => (
694694
);
695695
```
696696

697-
## `pagination`: Pagination Component
697+
## `pagination`
698698

699699
The `pagination` prop allows to replace the default pagination controls by your own.
700700

@@ -713,7 +713,7 @@ export const PostList = () => (
713713

714714
See [Paginating the List](./ListTutorial.md#building-a-custom-pagination) for details.
715715

716-
## `perPage`: Pagination Size
716+
## `perPage`
717717

718718
By default, the list paginates results by groups of 10. You can override this setting by specifying the `perPage` prop:
719719

@@ -801,7 +801,7 @@ export const UsersList = () => (
801801
);
802802
```
803803

804-
## `sort`: Default Sort Field & Order
804+
## `sort`
805805

806806
Pass an object literal as the `sort` prop to determine the default `field` and `order` used for sorting:
807807

@@ -821,13 +821,11 @@ For more details on list sort, see the [Sorting The List](./ListTutorial.md#sort
821821

822822
## `storeKey`
823823

824-
To display multiple lists of the same resource and keep distinct store states for each of them (filters, sorting and pagination), specify unique keys with the `storeKey` property.
824+
By default, react-admin stores the list parameters (sort, pagination, filters) in localStorage so that users can come back to the list and find it in the same state as when they left it. React-admin uses the current resource as the identifier to store the list parameters (under the key `${resource}.listParams`).
825825

826-
In case no `storeKey` is provided, the states will be stored with the following key: `${resource}.listParams`.
826+
If you want to display multiple lists of the same resource and keep distinct store states for each of them (filters, sorting and pagination), you must give each list a unique `storeKey` property. You can also disable the persistence of list parameters in the store by setting the `storeKey` prop to `false`.
827827

828-
**Note:** Please note that selection state will remain linked to a resource-based key as described [here](./List.md#disablesyncwithlocation).
829-
830-
In the example below, both lists `NewerBooks` and `OlderBooks` use the same resource ('books'), but their controller states are stored separately (under the store keys `'newerBooks'` and `'olderBooks'` respectively). This allows to use both components in the same app, each having its own state (filters, sorting and pagination).
828+
In the example below, both lists `NewerBooks` and `OlderBooks` use the same resource ('books'), but their list parameters are stored separately (under the store keys `'newerBooks'` and `'olderBooks'` respectively). This allows to use both components in the same app, each having its own state (filters, sorting and pagination).
831829

832830
{% raw %}
833831
```jsx
@@ -887,7 +885,7 @@ const Admin = () => {
887885

888886
**Tip:** The `storeKey` is actually passed to the underlying `useListController` hook, which you can use directly for more complex scenarios. See the [`useListController` doc](./useListController.md#storekey) for more info.
889887

890-
You can disable this feature by setting the `storeKey` prop to `false`. When disabled, parameters will not be persisted in the store.
888+
**Note:** *Selection state* will remain linked to a resource-based key regardless of the `storeKey`. This is a design choice because if row selection is not tied to a resource, then when a user deletes a record it may remain selected without any ability to unselect it. If you want the selection state to be local, you will have to implement your own `useListController` hook and pass a custom key to the `useRecordSelection` hook. You will then need to implement your own `DeleteButton` and `BulkDeleteButton` to manually unselect rows when deleting records.
891889

892890
## `title`
893891

@@ -935,22 +933,6 @@ const PostList = () => (
935933

936934
**Tip**: The `List` component `classes` can also be customized for all instances of the component with its global css name `RaList` as [describe here](https://marmelab.com/blog/2019/12/18/react-admin-3-1.html#theme-overrides)
937935

938-
## Adding `meta` To The DataProvider Call
939-
940-
Use [the `queryOptions` prop](#queryoptions) to pass [a custom `meta`](./Actions.md#meta-parameter) to the `dataProvider.getList()` call.
941-
942-
{% raw %}
943-
```jsx
944-
import { List } from 'react-admin';
945-
946-
const PostList = () => (
947-
<List queryOptions={{ meta: { foo: 'bar' } }}>
948-
...
949-
</List>
950-
);
951-
```
952-
{% endraw %}
953-
954936
## Infinite Scroll Pagination
955937

956938
By default, the `<List>` component displays the first page of the list of records. To display the next page, the user must click on the "next" button. This is called "finite pagination". An alternative is to display the next page automatically when the user scrolls to the bottom of the list. This is called "infinite pagination".
@@ -1008,37 +990,43 @@ const PostList = () => (
1008990

1009991
The list will automatically update when a new record is created, or an existing record is updated or deleted.
1010992

1011-
## How to render an empty list
993+
## Adding `meta` To The DataProvider Call
1012994

1013-
You can set the `empty` props value to `false` to bypass the empty page display and render an empty list instead.
995+
Use [the `queryOptions` prop](#queryoptions) to pass [a custom `meta`](./Actions.md#meta-parameter) to the `dataProvider.getList()` call.
1014996

1015-
```tsx
997+
{% raw %}
998+
```jsx
1016999
import { List } from 'react-admin';
10171000

1018-
const ProductList = () => (
1019-
<List empty={false}>
1001+
const PostList = () => (
1002+
<List queryOptions={{ meta: { foo: 'bar' } }}>
10201003
...
10211004
</List>
1022-
)
1005+
);
10231006
```
1007+
{% endraw %}
1008+
1009+
## Rendering An Empty List
10241010

1025-
## How to remove the `<ExportButton>`
1011+
When there is no data, react-admin displays a special page inviting the user to create the first record. This page can be customized using [the `empty` prop](#empty-empty-page-component).
10261012

1027-
You can remove the `<ExportButton>` by passing `false` to the `exporter` prop.
1013+
You can set the `empty` props value to `false` to render an empty list instead.
10281014

10291015
```tsx
10301016
import { List } from 'react-admin';
10311017

10321018
const ProductList = () => (
1033-
<List exporter={false}>
1019+
<List empty={false}>
10341020
...
10351021
</List>
10361022
)
10371023
```
10381024

1039-
## How to disable storing the list parameters in the Store
1025+
## Disabling Parameters Persistence
1026+
1027+
By default, react-admin stores the list parameters (sort, pagination, filters) in localStorage so that users can come back to the list and find it in the same state as when they left it. This also synchronizes the list parameters across tabs.
10401028

1041-
You can disable the `storeKey` feature by setting the `storeKey` prop to `false`. When disabled, the list parameters will not be persisted in [the Store](./Store.md).
1029+
You can disable this feature by setting [the `storeKey` prop](#storekey) to `false`:
10421030

10431031
```tsx
10441032
import { List } from 'react-admin';

docs/ListBase.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ The `<ListBase>` component accepts the same props as [`useListController`](./use
5858
* [`exporter`](./List.md#exporter)
5959
* [`filter`](./List.md#filter-permanent-filter)
6060
* [`filterDefaultValues`](./List.md#filterdefaultvalues)
61-
* [`perPage`](./List.md#perpage-pagination-size)
61+
* [`perPage`](./List.md#perpage)
6262
* [`queryOptions`](./List.md#queryoptions)
6363
* [`resource`](./List.md#resource)
64-
* [`sort`](./List.md#sort-default-sort-field--order)
64+
* [`sort`](./List.md#sort)
6565

6666
These are a subset of the props accepted by `<List>` - only the props that change data fetching, and not the props related to the user interface.
6767

68-
In addition, `<ListBase>` renders its children components inside a `ListContext`. Check [the `<List children>` documentation](./List.md#children-list-layout) for usage examples.
68+
In addition, `<ListBase>` renders its children components inside a `ListContext`. Check [the `<List children>` documentation](./List.md#children) for usage examples.

docs/Reference.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ title: "Index"
6565
* [`<EditDialog>`](./EditDialog)<img class="icon" src="./img/premium.svg" />
6666
* [`<EditInDialogButton>`](./EditInDialogButton.md)<img class="icon" src="./img/premium.svg" />
6767
* [`<EmailField>`](./EmailField.md)
68-
* [`<Empty>`](./List.md#empty-empty-page-component)
68+
* [`<Empty>`](./List.md#empty)
6969

7070
**- F -**
7171
* [`<FileField>`](./FileField.md)
@@ -121,7 +121,7 @@ title: "Index"
121121
* [`<NumberInput>`](./NumberInput.md)
122122

123123
**- P -**
124-
* [`<Pagination>`](./List.md#pagination-pagination-component)
124+
* [`<Pagination>`](./List.md#pagination)
125125
* [`<PasswordInput>`](./PasswordInput.md)
126126
* [`<PreferencesSetter>`](https://marmelab.com/ra-enterprise/modules/ra-preferences#preferencessetter-setting-preferences-declaratively)<img class="icon" src="./img/premium.svg" />
127127

docs/ReferenceField.md

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,53 @@ The `<ReferenceField>` component accepts the usual `className` prop. You can als
190190

191191
To override the style of all instances of `<ReferenceField>` using the [Material UI style overrides](https://mui.com/material-ui/customization/theme-components/#theme-style-overrides), use the `RaReferenceField` key.
192192

193+
## Performance
194+
195+
When used in a `<Datagrid>`, `<ReferenceField>` fetches the referenced record only once for the entire table.
196+
197+
![ReferenceField](./img/reference-field.png)
198+
199+
For instance, with this code:
200+
201+
```jsx
202+
import { List, Datagrid, ReferenceField, TextField, EditButton } from 'react-admin';
203+
204+
export const PostList = () => (
205+
<List>
206+
<Datagrid>
207+
<TextField source="id" />
208+
<ReferenceField label="User" source="user_id" reference="users" />
209+
<TextField source="title" />
210+
<EditButton />
211+
</Datagrid>
212+
</List>
213+
);
214+
```
215+
216+
React-admin accumulates and deduplicates the ids of the referenced records to make *one* `dataProvider.getMany()` call for the entire list, instead of n `dataProvider.getOne()` calls. So for instance, if the API returns the following list of posts:
217+
218+
```js
219+
[
220+
{
221+
id: 123,
222+
title: 'Totally agree',
223+
user_id: 789,
224+
},
225+
{
226+
id: 124,
227+
title: 'You are right my friend',
228+
user_id: 789
229+
},
230+
{
231+
id: 125,
232+
title: 'Not sure about this one',
233+
user_id: 735
234+
}
235+
]
236+
```
237+
238+
Then react-admin renders the `<PostList>` with a loader for the `<ReferenceField>`, fetches the API for the related users in one call (`dataProvider.getMany('users', { ids: [789,735] }`), and re-renders the list once the data arrives. This accelerates the rendering and minimizes network load.
239+
193240
## Rendering More Than One Field
194241

195242
You often need to render more than one field of the reference table (e.g. if the `users` table has a `first_name` and a `last_name` field).
@@ -255,54 +302,7 @@ export const PostShow = () => (
255302
);
256303
```
257304

258-
## Performance
259-
260-
When used in a `<Datagrid>`, `<ReferenceField>` fetches the referenced record only once for the entire table.
261-
262-
![ReferenceField](./img/reference-field.png)
263-
264-
For instance, with this code:
265-
266-
```jsx
267-
import { List, Datagrid, ReferenceField, TextField, EditButton } from 'react-admin';
268-
269-
export const PostList = () => (
270-
<List>
271-
<Datagrid>
272-
<TextField source="id" />
273-
<ReferenceField label="User" source="user_id" reference="users" />
274-
<TextField source="title" />
275-
<EditButton />
276-
</Datagrid>
277-
</List>
278-
);
279-
```
280-
281-
React-admin accumulates and deduplicates the ids of the referenced records to make *one* `dataProvider.getMany()` call for the entire list, instead of n `dataProvider.getOne()` calls. So for instance, if the API returns the following list of posts:
282-
283-
```js
284-
[
285-
{
286-
id: 123,
287-
title: 'Totally agree',
288-
user_id: 789,
289-
},
290-
{
291-
id: 124,
292-
title: 'You are right my friend',
293-
user_id: 789
294-
},
295-
{
296-
id: 125,
297-
title: 'Not sure about this one',
298-
user_id: 735
299-
}
300-
]
301-
```
302-
303-
Then react-admin renders the `<PostList>` with a loader for the `<ReferenceField>`, fetches the API for the related users in one call (`dataProvider.getMany('users', { ids: [789,735] }`), and re-renders the list once the data arrives. This accelerates the rendering and minimizes network load.
304-
305-
## Removing the link
305+
## Removing The Link
306306

307307
You can prevent `<ReferenceField>` from adding a link to its children by setting `link` to `false`.
308308

docs/ReferenceOneField.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ const BookShow = () => (
224224
```
225225
{% endraw %}
226226

227-
## Removing the link
227+
## Removing The Link
228228

229229
By default, `<ReferenceOneField>` links to the edition page of the related record. You can disable this behavior by setting the `link` prop to `false`.
230230

0 commit comments

Comments
 (0)