Skip to content

Commit 6f8d02e

Browse files
committed
Review
1 parent 2dbd753 commit 6f8d02e

9 files changed

Lines changed: 74 additions & 54 deletions

File tree

docs/ArrayField.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ storybook_path: ra-ui-materialui-fields-arrayfield--basic
66

77
# `<ArrayField>`
88

9-
`<ArrayField>` renders an embedded array of objects.
9+
`<ArrayField>` renders an embedded array of objects.
1010

1111
![ArrayField](./img/array-field.webp)
1212

@@ -76,7 +76,7 @@ const PostShow = () => (
7676
|------------|----------|-------------------|---------|------------------------------------------|
7777
| `children` | Required | `ReactNode` | | The component to render the list. |
7878
| `filter` | Optional | `object` | | The filter to apply to the list. |
79-
| `exporter` | Optional | `function` | `defaultExporter` | The function called by export buttons in the list context. |
79+
| `exporter` | Optional | `function` | `default Exporter` | The function called by export buttons in the list context. |
8080
| `perPage` | Optional | `number` | 1000 | The number of items to display per page. |
8181
| `sort` | Optional | `{ field, order}` | | The sort to apply to the list. |
8282

@@ -159,6 +159,7 @@ const PostShow = () => (
159159
You can use the `filter` prop to display only a subset of the items in the array. For instance, to display only the backlinks for a particular day:
160160

161161
{% raw %}
162+
162163
```jsx
163164
<ArrayField source="backlinks" filter={{ date: '2012-08-10T00:00:00.000Z' }}>
164165
<DataTable>
@@ -168,13 +169,14 @@ You can use the `filter` prop to display only a subset of the items in the array
168169
</DataTable>
169170
</ArrayField>
170171
```
172+
171173
{% endraw %}
172174

173175
The filtering capabilities are very limited. For instance, there is no "greater than" or "less than" operator. You can only filter on the equality of a field.
174176

175177
## `perPage`
176178

177-
If the value is a large array, and you don't need to display all the items, you can use the `perPage` prop to limit the number of items displayed.
179+
If the value is a large array, and you don't need to display all the items, you can use the `perPage` prop to limit the number of items displayed.
178180

179181
As `<ArrayField>` creates a [`ListContext`](./useListContext.md), you can use the `<Pagination>` component to navigate through the items.
180182

@@ -210,13 +212,15 @@ const PostShow = () => (
210212
By default, `<ArrayField>` displays the items in the order they are stored in the field. You can use the `sort` prop to change the sort order.
211213

212214
{% raw %}
215+
213216
```jsx
214217
<ArrayField source="tags" sort={{ field: 'name', order: 'ASC' }}>
215218
<SingleFieldList linkType={false}>
216219
<ChipField source="name" />
217220
</SingleFieldList>
218221
</ArrayField>
219222
```
223+
220224
{% endraw %}
221225

222226
## Using The List Context

docs/ReferenceManyField.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ storybook_path: ra-ui-materialui-fields-referencemanyfield--basic
66

77
# `<ReferenceManyField>`
88

9-
`<ReferenceManyField>` is useful for displaying a list of related records via a one-to-many relationship, when the foreign key is carried by the referenced resource.
9+
`<ReferenceManyField>` is useful for displaying a list of related records via a one-to-many relationship, when the foreign key is carried by the referenced resource.
1010

1111
<iframe src="https://www.youtube-nocookie.com/embed/UeM31-65Wc4" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen style="aspect-ratio: 16 / 9;width:100%;margin-bottom:1em;" referrerpolicy="strict-origin-when-cross-origin"></iframe>
1212

@@ -97,7 +97,7 @@ This example leverages [`<SingleFieldList>`](./SingleFieldList.md) to display an
9797
| `empty` | Optional | `ReactNode` | - | Element to display when there are no related records. |
9898
| `error` | Optional | `ReactNode` | - | The component to render when an error occurs while fetching the related records |
9999
| `filter` | Optional | `Object` | - | Filters to use when fetching the related records, passed to `getManyReference()` |
100-
| `exporter` | Optional | `function` | `defaultExporter` | The function called by export buttons in the list context |
100+
| `exporter` | Optional | `function` | `default Exporter` | The function called by export buttons in the list context |
101101
| `loading` | Optional | `ReactNode` | - | The component to render while fetching the related records |
102102
| `offline` | Optional | `ReactNode` | - | Element to display when there are no related records because of lack of network connectivity. |
103103
| `pagination` | Optional | `Element` | - | Pagination element to display pagination controls. empty by default (no pagination) |
@@ -121,7 +121,7 @@ This example leverages [`<SingleFieldList>`](./SingleFieldList.md) to display an
121121
- [`<SimpleList>`](./SimpleList.md)
122122
- [`<EditableDatagrid>`](./EditableDatagrid.md)
123123
- [`<Calendar>`](./Calendar.md)
124-
- Or a component of your own (check the [`<WithListContext>`](./WithListContext.md) and the [`useListContext`](./useListContext.md) chapters to learn how).
124+
- Or a component of your own (check the [`<WithListContext>`](./WithListContext.md) and the [`useListContext`](./useListContext.md) chapters to learn how).
125125

126126
For instance, use a `<DataTable>` to render the related records in a table:
127127

@@ -452,9 +452,11 @@ Use the `queryOptions` prop to pass options to [the `dataProvider.getMany()` que
452452
For instance, to pass [a custom `meta`](./Actions.md#meta-parameter):
453453

454454
{% raw %}
455+
455456
```jsx
456457
<ReferenceManyField queryOptions={{ meta: { foo: 'bar' } }} />
457458
```
459+
458460
{% endraw %}
459461

460462
## `reference`
@@ -506,6 +508,7 @@ This allows to inline the render logic for the list of related records.
506508
By default, it orders the possible values by id desc. You can change this order by setting the `sort` prop (an object with `field` and `order` properties).
507509

508510
{% raw %}
511+
509512
```jsx
510513
<ReferenceManyField
511514
target="post_id"
@@ -515,6 +518,7 @@ By default, it orders the possible values by id desc. You can change this order
515518
...
516519
</ReferenceManyField>
517520
```
521+
518522
{% endraw %}
519523

520524
## `source`
@@ -540,6 +544,7 @@ If you want to display multiple lists of the same reference and keep distinct se
540544
In the example below, both lists use the same reference ('books'), but their selection states are stored separately (under the store keys `'authors.1.books.selectedIds'` and `'custom.selectedIds'` respectively). This allows to use both components in the same page, each having its own state.
541545

542546
{% raw %}
547+
543548
```jsx
544549
<Stack direction="row" spacing={2}>
545550
<ReferenceManyField
@@ -567,6 +572,7 @@ In the example below, both lists use the same reference ('books'), but their sel
567572
</ReferenceManyField>
568573
</Stack>
569574
```
575+
570576
{% endraw %}
571577

572578
## `target`
@@ -584,11 +590,12 @@ Name of the field carrying the relationship on the referenced resource. For inst
584590

585591
## Rendering Only One Record
586592

587-
Although you are in a one-to-many relationship, you may want to render only one record. For instance, in a book with several reviews, you may want to display only the last. Or, for a product with many prices, you may want to display only the one in euros.
593+
Although you are in a one-to-many relationship, you may want to render only one record. For instance, in a book with several reviews, you may want to display only the last. Or, for a product with many prices, you may want to display only the one in euros.
588594

589595
In these cases, use [the `<ReferenceOneField>` component](./ReferenceOneField.md) instead of `<ReferenceManyField>`.
590596

591597
{% raw %}
598+
592599
```jsx
593600
<ReferenceOneField
594601
label="Latest review"
@@ -600,9 +607,11 @@ In these cases, use [the `<ReferenceOneField>` component](./ReferenceOneField.md
600607
<TextField source="body" />
601608
</ReferenceOneField>
602609
```
610+
603611
{% endraw %}
604612

605613
{% raw %}
614+
606615
```jsx
607616
<ReferenceOneField
608617
label="Price (€)"
@@ -613,6 +622,7 @@ In these cases, use [the `<ReferenceOneField>` component](./ReferenceOneField.md
613622
<NumberField source="price" />
614623
</ReferenceOneField>
615624
```
625+
616626
{% endraw %}
617627

618628
## Adding or editing a related record
@@ -625,6 +635,7 @@ To allow users to create or edit a record without leaving the current view, use
625635
</video>
626636

627637
{% raw %}
638+
628639
```jsx
629640
import { Edit, SimpleForm, TextInput, ReferenceManyField, WithRecord, DataTable } from 'react-admin';
630641
import { CreateInDialogButton, EditInDialogButton } from "@react-admin/ra-form-layout";
@@ -668,4 +679,5 @@ const EmployerEdit = () => (
668679
</Edit>
669680
)
670681
```
682+
671683
{% endraw %}

docs/useListContext.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ const {
6464
data, // Array of the list records, e.g. [{ id: 123, title: 'hello world' }, { ... }
6565
total, // Total number of results for the current filters, excluding pagination. Useful to build the pagination controls, e.g. 23
6666
meta, // Additional information about the list, like facets & statistics
67-
getData, // Async callback that returns the full list data (ignores pagination)
6867
isPending, // Boolean, true until the data is available
6968
isFetching, // Boolean, true while the data is being fetched, false once the data is fetched
7069
isLoading, // Boolean, true until the data is fetched for the first time
@@ -93,6 +92,7 @@ const {
9392
defaultTitle, // Translated title based on the resource, e.g. 'Posts'
9493
resource, // Resource name, deduced from the location. e.g. 'posts'
9594
refetch, // Callback for fetching the list data again
95+
getData, // Callback that returns the full list data (ignores pagination)
9696
} = useListContext();
9797
```
9898

docs/useListController.md

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ storybook_path: ra-core-controller-list-uselistcontroller--authenticated
66

77
# `useListController`
88

9-
`useListController` contains the headless logic of the [`<List>`](./List.md) component. It's useful to create a custom List view. It's also the base hook when building a custom view with another UI kit than Material UI.
9+
`useListController` contains the headless logic of the [`<List>`](./List.md) component. It's useful to create a custom List view. It's also the base hook when building a custom view with another UI kit than Material UI.
1010

1111
![List view built with Ant Design](./img/list_ant_design.png)
1212

13-
`useListController` reads the list parameters from the URL, calls `dataProvider.getList()`, prepares callbacks for modifying the pagination, filters, sort and selection, and returns them together with the data. Its return value matches the [`ListContext`](./useListContext.md) shape.
13+
`useListController` reads the list parameters from the URL, calls `dataProvider.getList()`, prepares callbacks for modifying the pagination, filters, sort and selection, and returns them together with the data. Its return value matches the [`ListContext`](./useListContext.md) shape.
1414

1515
`useListController` is used internally by [`<List>`](./List.md) and [`<ListBase>`](./ListBase.md). If your list view uses react-admin components like [`<DataTable>`](./DataTable.md), prefer [`<ListBase>`](./ListBase.md) to `useListController` as it takes care of creating a `<ListContext>`.
1616

@@ -21,6 +21,7 @@ storybook_path: ra-core-controller-list-uselistcontroller--authenticated
2121
Here the code for the post list view above, built with [Ant Design](https://ant.design/):
2222

2323
{% raw %}
24+
2425
```jsx
2526
import { useListController } from 'react-admin';
2627
import { Card, Table, Button } from 'antd';
@@ -86,6 +87,7 @@ const columns = [
8687

8788
export default PostList;
8889
```
90+
8991
{% endraw %}
9092

9193
When using react-admin components, it's common to call `useListController()` without parameters, and to put the result in a `ListContext` to make it available to the rest of the component tree.
@@ -110,17 +112,21 @@ const MyList = () => {
110112

111113
`useListController` expects an object as parameter. All keys are optional.
112114

113-
* [`debounce`](./List.md#debounce): Debounce time in ms for the setFilters callbacks
114-
* [`disableAuthentication`](./List.md#disableauthentication): Set to true to allow anonymous access to the list
115-
* [`disableSyncWithLocation`](./List.md#disablesyncwithlocation): Set to true to have more than one list per page
116-
* [`exporter`](./List.md#exporter): Exporter function
117-
* [`filter`](./List.md#filter-permanent-filter): Permanent filter, forced over the user filter
118-
* [`filterDefaultValues`](./List.md#filterdefaultvalues): Default values for the filter form
119-
* [`perPage`](./List.md#perpage): Number of results per page
120-
* [`queryOptions`](./List.md#queryoptions): React-query options for the useQuery call
121-
* [`resource`](./List.md#resource): Resource name, e.g. 'posts' ; defaults to the current resource context
122-
* [`sort`](./List.md#sort): Current sort value, e.g. `{ field: 'published_at', order: 'DESC' }`
123-
* [`storeKey`](#storekey): Key used to differentiate the list from another sharing the same resource, in store managed states
115+
| Prop | Type | Default | Description |
116+
|---------------------------|-------------------------|---------|--------------------------------------------------------------------------------------------------|
117+
| `debounce` | `number` | `500` | The debounce delay in milliseconds to apply when users change the sort or filter parameters. |
118+
| `disableAuthentication` | `boolean` | `false` | Set to `true` to disable the authentication check. |
119+
| `disableSyncWithLocation` | `boolean` | `false` | Set to `true` to disable the synchronization of the list parameters with the URL. |
120+
| `exporter` | `function` | - | The function to call to export the list. |
121+
| `filter` | `object` | - | The permanent filter values, forced over the user filter |
122+
| `filterDefaultValues` | `object` | - | The default filter values. |
123+
| `perPage` | `number` | `10` | The number of records to fetch per page. |
124+
| `queryOptions` | `object` | - | The options to pass to the `useQuery` hook. |
125+
| `resource` | `string` | - | The resource name, e.g. `posts`. |
126+
| `sort` | `object` | - | The initial sort parameters, e.g. `{ field: 'published_at', order: 'DESC' }`. |
127+
| `storeKey` | `string` &#124; `false` | - | The key to use to store the current filter & sort. Pass `false` to disable store synchronization |
128+
129+
Check [the `<List>` component documentation](./List.md) for more details about these parameters.
124130

125131
Here are their default values:
126132

@@ -178,6 +184,7 @@ If you want to disable the storage of list parameters altogether for a given lis
178184
In the example below, both lists `TopPosts` and `FlopPosts` use the same resource ('posts'), but their controller states are stored separately (under the store keys `'top'` and `'flop'` respectively).
179185

180186
{% raw %}
187+
181188
```jsx
182189
import { useListController } from 'react-admin';
183190

@@ -211,21 +218,20 @@ const FlopPosts = (
211218
<OrderedPostList storeKey="flop" sort={{ field: 'votes', order: 'ASC' }} />
212219
);
213220
```
221+
214222
{% endraw %}
215223

216224
You can disable this feature by setting the `storeKey` prop to `false`. When disabled, parameters will not be persisted in the store.
217225

218-
219226
## Return Value
220227

221-
`useListController` returns an object with the following keys:
228+
`useListController` returns an object with the following keys:
222229

223230
```jsx
224231
const {
225232
// Data
226233
data, // Array of the list records, e.g. [{ id: 123, title: 'hello world' }, { ... }
227234
total, // Total number of results for the current filters, excluding pagination. Useful to build the pagination controls, e.g. 23
228-
getData, // Async callback that returns the full list data (ignores pagination)
229235
isPending, // Boolean, true until the data is available
230236
isFetching, // Boolean, true while the data is being fetched, false once the data is fetched
231237
isLoading, // Boolean, true until the data is fetched for the first time
@@ -254,16 +260,17 @@ const {
254260
defaultTitle, // Translated title based on the resource, e.g. 'Posts'
255261
resource, // Resource name, deduced from the location. e.g. 'posts'
256262
refetch, // Callback for fetching the list data again
263+
getData, // Callback that returns the full list data (ignores pagination)
257264
} = useListController();
258265
```
259266

260267
## Using `setFilters` to Update Filters
261268

262269
The `setFilters` method is used to update the filters. It takes three arguments:
263270

264-
- `filters`: an object containing the new filter values
265-
- `displayedFilters`: an object containing the new displayed filters
266-
- `debounced`: set to true to debounce the call to setFilters (false by default)
271+
* `filters`: an object containing the new filter values
272+
* `displayedFilters`: an object containing the new displayed filters
273+
* `debounced`: set to true to debounce the call to setFilters (false by default)
267274

268275
You can use it to update the list filters:
269276

docs_headless/src/content/docs/useListContext.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ const {
5555
data, // Array of the list records, e.g. [{ id: 123, title: 'hello world' }, { ... }
5656
total, // Total number of results for the current filters, excluding pagination. Useful to build the pagination controls, e.g. 23
5757
meta, // Additional information about the list, like facets & statistics
58-
getData, // Async callback that returns the full list data (ignores pagination)
5958
isPending, // Boolean, true until the data is available
6059
isFetching, // Boolean, true while the data is being fetched, false once the data is fetched
6160
isLoading, // Boolean, true until the data is fetched for the first time
@@ -84,6 +83,7 @@ const {
8483
defaultTitle, // Translated title based on the resource, e.g. 'Posts'
8584
resource, // Resource name, deduced from the location. e.g. 'posts'
8685
refetch, // Callback for fetching the list data again
86+
getData, // Callback that returns the full list data (ignores pagination)
8787
} = useListContext();
8888
```
8989

0 commit comments

Comments
 (0)