Skip to content

Commit b5bb8b3

Browse files
committed
update docs for 5.6.1
1 parent c74a0a4 commit b5bb8b3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+295
-139
lines changed

CreateDialog.md

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -210,35 +210,31 @@ Unlike the `<Create>` components, with Dialog components the title will be displ
210210
Here is an example:
211211

212212
```tsx
213-
import React from 'react';
214213
import {
215214
List,
215+
ListActions,
216216
Datagrid,
217217
SimpleForm,
218218
TextInput,
219219
DateInput,
220220
required,
221221
} from 'react-admin';
222-
import {
223-
CreateDialog,
224-
} from '@react-admin/ra-form-layout';
222+
import { CreateDialog } from '@react-admin/ra-form-layout';
225223

226224
const CustomerList = () => (
227225
<>
228-
<List hasCreate>
226+
<List actions={<ListActions hasCreate />}>
229227
<Datagrid>
230228
...
231-
<ShowButton />
232229
</Datagrid>
233230
</List>
234-
<ShowDialog title={<CustomerShowTitle />}>
235-
<SimpleShowLayout>
236-
<TextField source="id" />
237-
<TextField source="first_name" />
238-
<TextField source="last_name" />
239-
<DateField source="date_of_birth" label="born" />
240-
</SimpleShowLayout>
241-
</ShowDialog>
231+
<CreateDialog title="Create a new customer">
232+
<SimpleForm>
233+
<TextInput source="first_name" validate={required()} />
234+
<TextInput source="last_name" validate={required()} />
235+
<DateInput source="date_of_birth" />
236+
</SimpleForm>
237+
</CreateDialog>
242238
</>
243239
);
244240
```
@@ -464,9 +460,7 @@ const EmployerEdit = () => (
464460

465461
## Warn When There Are Unsaved Changes
466462

467-
If you'd like to trigger a warning when the user tries to close the dialog with unsaved changes, there are two cases to consider.
468-
469-
In that case, you can leverage the [warnWhenUnsavedChanges](./Form.md#warnwhenunsavedchanges) feature provided by React Admin forms.
463+
If you'd like to trigger a warning when the user tries to close the dialog with unsaved changes, you can leverage the [warnWhenUnsavedChanges](./Form.md#warnwhenunsavedchanges) feature provided by React Admin forms.
470464

471465
Add the `warnWhenUnsavedChanges` prop to your Form like so:
472466

CreateInDialogButton.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,7 @@ You can also hide the title by passing `null`:
293293

294294
## Warn When There Are Unsaved Changes
295295

296-
If you'd like to trigger a warning when the user tries to close the dialog with unsaved changes, there are two cases to consider.
297-
298-
In that case, using the `warnWhenUnsavedChanges` prop directly on the form won't work, because this feature relies on the router's location, but both components do not use routing.
296+
If you'd like to trigger a warning when the user tries to close the dialog with unsaved changes, using the `warnWhenUnsavedChanges` prop directly on the form won't work, because this feature relies on the router's location, but both components do not use routing.
299297

300298
Instead, you can use the `<WarnWhenUnsavedChangesInDialog>` component provided by `ra-form-layout`.
301299

DataFetchingGuide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ Once your data provider has enabled realtime features, you can use these hooks a
414414
- [`useLockOnCall`](./useLockOnCall.md)
415415
- [`useGetListLive`](./useGetListLive.md)
416416
- [`useGetOneLive`](./useGetOneLive.md)
417-
- [`<ListLive>`](./ListLive.md)
417+
- [`<ListLiveUpdate>`](./ListLiveUpdate.md)
418418
- [`<EditLive>`](./EditLive.md)
419419
- [`<ShowLive>`](./ShowLive.md)
420420
- [`<MenuLive>`](./MenuLive.md)

DataProviderLive.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Once your data provider has enabled realtime features, you can use these hooks a
6161
- [`useLockOnCall`](./useLockOnCall.md)
6262
- [`useGetListLive`](./useGetListLive.md)
6363
- [`useGetOneLive`](./useGetOneLive.md)
64-
- [`<ListLive>`](./ListLive.md)
64+
- [`<ListLiveUpdate>`](./ListLiveUpdate.md)
6565
- [`<EditLive>`](./EditLive.md)
6666
- [`<ShowLive>`](./ShowLive.md)
6767
- [`<MenuLive>`](./MenuLive.md)

DatagridAG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2851,7 +2851,7 @@ const CarList = () => {
28512851

28522852
### Access Control
28532853

2854-
`<DatagridAG>` has built-in [access control](./Permissions.me#access-control). If the `authProvider` implements the `canAccess` method, users will only be allowed to edit rows of, say, resource `'cars'` if `canAccess({ action: 'edit', resource: 'cars' })` returns `true`.
2854+
`<DatagridAGClient>` has built-in [access control](./Permissions.me#access-control). If the `authProvider` implements the `canAccess` method, users will only be allowed to edit rows of, say, resource `'cars'` if `canAccess({ action: 'edit', resource: 'cars' })` returns `true`.
28552855

28562856
**Note:** the access control check can only be done at the resource level and not at the record level.
28572857

EditDialog.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,9 @@ const MyEditDialog = () => (
236236

237237
## `title`
238238

239-
Unlike the `<Create>` components, with Dialog components the title will be displayed in the `<Dialog>`, not in the `<AppBar>`.
240-
If you pass a custom title component, it will render in the same `RecordContext` as the dialog's child component. That means you can display non-editable details of the current `record` in the title component.
239+
Unlike the `<Edit>` components, with Dialog components the title will be displayed in the `<Dialog>`, not in the `<AppBar>`.
240+
If you pass a custom title component, it will render in the same `RecordContext` as the dialog's child component.
241+
That means you can display non-editable details of the current `record` in the title component.
241242
Here is an example:
242243

243244
```tsx
@@ -501,9 +502,7 @@ const EmployerEdit = () => (
501502

502503
## Warn When There Are Unsaved Changes
503504

504-
If you'd like to trigger a warning when the user tries to close the dialog with unsaved changes, there are two cases to consider.
505-
506-
In that case, you can leverage the [warnWhenUnsavedChanges](./Form.md#warnwhenunsavedchanges) feature provided by React Admin forms.
505+
If you'd like to trigger a warning when the user tries to close the dialog with unsaved changes, you can leverage the [warnWhenUnsavedChanges](./Form.md#warnwhenunsavedchanges) feature provided by React Admin forms.
507506

508507
Add the `warnWhenUnsavedChanges` prop to your Form like so:
509508

EditInDialogButton.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ const EditButton = () => (
302302
## `title`
303303

304304
Unlike the `<Edit>` components, with Dialog components the title will be displayed in the `<Dialog>`, not in the `<AppBar>`.
305-
Still, for `<EditInDialogButton>`, if you pass a custom title component, it will render in the same `RecordContext` as the dialog's child component. That means you can display non-editable details of the current `record` in the title component.
305+
If you pass a custom title component, it will render in the same `RecordContext` as the dialog's child component.
306+
That means you can display non-editable details of the current `record` in the title component.
306307
Here is an example:
307308

308309
```tsx
@@ -383,9 +384,7 @@ const EmployerEdit = () => (
383384

384385
## Warn When There Are Unsaved Changes
385386

386-
If you'd like to trigger a warning when the user tries to close the dialog with unsaved changes, there are two cases to consider.
387-
388-
In that case, using the `warnWhenUnsavedChanges` prop directly on the form won't work, because this feature relies on the router's location, but both components do not use routing.
387+
If you'd like to trigger a warning when the user tries to close the dialog with unsaved changes, using the `warnWhenUnsavedChanges` prop directly on the form won't work, because this feature relies on the router's location, but both components do not use routing.
389388

390389
Instead, you can use the `<WarnWhenUnsavedChangesInDialog>` component provided by `ra-form-layout`.
391390

Features.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,28 +1164,27 @@ Check the following low-level hooks for more details:
11641164

11651165
React-admin provides **live updates** via specialized hooks and components. This means that when a user edits a resource, the other users working on the same resource see the changes in real time whether they are in a list, a show view, or an edit view.
11661166

1167-
For instance, replace `<List>` with `<ListLive>` to have a list refreshing automatically when an element is added, updated, or deleted:
1167+
For instance, include a `<ListLiveUpdate>` within a `<List>` to have a list refreshing automatically when an element is added, updated, or deleted:
11681168

11691169
```diff
11701170
import {
1171-
- List,
1171+
List,
11721172
Datagrid,
11731173
TextField,
11741174
NumberField,
11751175
Datefield,
11761176
} from 'react-admin';
1177-
+import { ListLive } from '@react-admin/ra-realtime';
1177+
+import { ListLiveUpdate } from '@react-admin/ra-realtime';
11781178

11791179
const PostList = () => (
1180-
- <List>
1181-
+ <ListLive>
1180+
<List>
11821181
<Datagrid>
11831182
<TextField source="title" />
11841183
<NumberField source="views" />
11851184
<DateField source="published_at" />
11861185
</Datagrid>
1187-
- </List>
1188-
+ </ListLive>
1186+
+ <ListLiveUpdate />
1187+
</List>
11891188
);
11901189
```
11911190

@@ -1202,7 +1201,7 @@ This feature leverages the following hooks:
12021201

12031202
And the following components:
12041203

1205-
- [`<ListLive>`](./ListLive.md)
1204+
- [`<ListLiveUpdate>`](./ListLiveUpdate.md)
12061205
- [`<EditLive>`](./EditLive.md)
12071206
- [`<ShowLive>`](./ShowLive.md)
12081207

List.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,21 +1085,19 @@ const BookList = () => (
10851085

10861086
## Live Updates
10871087

1088-
If you want to subscribe to live updates on the list of records (topic: `resource/[resource]`), use [the `<ListLive>` component](./ListLive.md) instead.
1088+
If you want to subscribe to live updates on the list of records (topic: `resource/[resource]`), add [the `<ListLiveUpdate>` component](./ListLiveUpdate.md) in your `<List>` children.
10891089

10901090
```diff
1091-
-import { List, Datagrid, TextField } from 'react-admin';
1092-
+import { Datagrid, TextField } from 'react-admin';
1093-
+import { ListLive } from '@react-admin/ra-realtime';
1091+
import { List, Datagrid, TextField } from 'react-admin';
1092+
+import { ListLiveUpdate } from '@react-admin/ra-realtime';
10941093

10951094
const PostList = () => (
1096-
- <List>
1097-
+ <ListLive>
1095+
<List>
10981096
<Datagrid>
10991097
<TextField source="title" />
11001098
</Datagrid>
1101-
- </List>
1102-
+ </ListLive>
1099+
+ <ListLiveUpdate />
1100+
</List>
11031101
);
11041102
```
11051103

ListLiveUpdate.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
layout: default
3+
title: "ListLiveUpdate"
4+
---
5+
6+
# `<ListLiveUpdate>`
7+
8+
`<ListLiveUpdate>` is an [Enterprise Edition](https://react-admin-ee.marmelab.com)<img class="icon" src="./img/premium.svg" /> component that refreshes its parent `ListContext` (e.g in a [`<List>`](./List.md)) when a record is created, updated, or deleted.
9+
10+
![ListLive](./img/ListLive.png)
11+
12+
## Usage
13+
14+
Add the `<ListLiveUpdate>` in your `<List>` children:
15+
16+
```jsx
17+
import { Datagrid, List TextField } from 'react-admin';
18+
import { ListLiveUpdate } from '@react-admin/ra-realtime';
19+
20+
const PostList = () => (
21+
<List>
22+
<Datagrid>
23+
<TextField source="title" />
24+
</Datagrid>
25+
<ListLiveUpdate />
26+
</List>
27+
);
28+
```
29+
30+
To trigger refreshes of `<ListLiveUpdate>`, the API has to publish events containing at least the followings:
31+
32+
```js
33+
{
34+
topic : '/resource/{resource}',
35+
event: {
36+
type: '{deleted || created || updated}',
37+
payload: { ids: [{listOfRecordIdentifiers}]},
38+
}
39+
}
40+
```
41+
42+
43+
This also works with [`<ReferenceManyField>`](https://marmelab.com/react-admin/ReferenceManyField.html) or [`<ReferenceArrayField>`](https://marmelab.com/react-admin/ReferenceArrayField.html):
44+
```tsx
45+
import { Show, SimpleShowLayout, ReferenceManyField, Datagrid, TextField, DateField } from 'react-admin';
46+
import { ListLiveUpdate } from '@react-admin/ra-realtime';
47+
const AuthorShow = () => (
48+
<Show>
49+
<SimpleShowLayout>
50+
<TextField source="first_name" />
51+
<TextField source="last_name" />
52+
<ReferenceManyField reference="books" target="author_id" label="Books">
53+
<Datagrid>
54+
<TextField source="title" />
55+
<DateField source="published_at" />
56+
</Datagrid>
57+
<ListLiveUpdate />
58+
</ReferenceManyField>
59+
</SimpleShowLayout>
60+
</Show>
61+
);
62+
```
63+
64+
## `onEventReceived`
65+
66+
The `<ListLiveUpdate>` allows you to customize the side effects triggered when it receives a new event, by passing a function to the `onEventReceived` prop:
67+
68+
```jsx
69+
import { Datagrid, List, TextField, useNotify, useRefresh } from 'react-admin';
70+
import { ListLiveUpdate } from '@react-admin/ra-realtime';
71+
72+
const PostList = () => {
73+
const notify = useNotify();
74+
const refresh = useRefresh();
75+
76+
const handleEventReceived = event => {
77+
const count = get(event, 'payload.ids.length', 1);
78+
notify(`${count} items updated by another user`);
79+
refresh();
80+
};
81+
82+
return (
83+
<List>
84+
<Datagrid>
85+
<TextField source="title" />
86+
</Datagrid>
87+
<ListLiveUpdate onEventReceived={handleEventReceived} />
88+
</List>
89+
);
90+
};
91+
```

0 commit comments

Comments
 (0)