Skip to content

Commit 878c89d

Browse files
[Doc] Add documentation for <LockOnMount> and <WithLocks> headless components
1 parent b125279 commit 878c89d

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

docs_headless/astro.config.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ export default defineConfig({
233233
label: 'Realtime',
234234
items: [
235235
enterpriseEntry('<ListLiveUpdate>'),
236+
enterpriseEntry('<LockOnMount>'),
236237
enterpriseEntry('<LockStatusBase>'),
238+
enterpriseEntry('<WithLocks>'),
237239
enterpriseEntry('usePublish'),
238240
enterpriseEntry('useSubscribe'),
239241
enterpriseEntry('useSubscribeCallback'),
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: '<LockOnMount>'
3+
---
4+
5+
`<LockOnMount />` calls `dataProvider.lock()` on mount and `dataProvider.unlock()` on unmount to lock and unlock the record. It relies on `authProvider.getIdentity()` to get the identity of the current user. It guesses the current `resource` and `recordId` from the context (or the route) if not provided.
6+
7+
This feature requires a valid [Enterprise Edition](https://marmelab.com/ra-enterprise/) subscription.
8+
9+
## Installation
10+
11+
```bash
12+
npm install --save @react-admin/ra-core-ee
13+
# or
14+
yarn add @react-admin/ra-core-ee
15+
```
16+
17+
## Usage
18+
19+
```tsx
20+
import { EditBase, Form } from 'ra-core';
21+
import { LockOnMount, useLockCallbacks } from '@react-admin/ra-core-ee';
22+
23+
const PostEdit = () => (
24+
<EditBase>
25+
<PostEditForm />
26+
<LockOnMount />
27+
</EditBase>
28+
);
29+
30+
const PostEditForm = () => {
31+
const { isPending, isLocked } = useLockCallbacks();
32+
33+
if (isPending) {
34+
return <p>Loading...</p>;
35+
}
36+
37+
return <Form disabled={isLocked}>{/* ... */}</Form>;
38+
};
39+
```
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
title: '<WithLocks>'
3+
---
4+
5+
`<WithLocks>` fetches the locks for a resource on mount, and puts them in a LocksContext. The locks are updated in real time.
6+
7+
This component calls `dataProvider.getLocks()`, then subscribes to the locks topic for the current resource, and refetches the locks when a new event is received.
8+
9+
This feature requires a valid [Enterprise Edition](https://marmelab.com/ra-enterprise/) subscription.
10+
11+
## Installation
12+
13+
```bash
14+
npm install --save @react-admin/ra-core-ee
15+
# or
16+
yarn add @react-admin/ra-core-ee
17+
```
18+
19+
## Usage
20+
21+
```tsx
22+
import { ListBase, useRecordContext } from 'ra-core';
23+
import { WithLocks, useLocksContext } from '@react-admin/ra-core-ee';
24+
import { DataTable } from 'your-ra-ui-library';
25+
26+
const LockField = () => {
27+
const locks = useLocksContext();
28+
const record = useRecordContext();
29+
30+
if (!record) return null;
31+
32+
const lock = locks.find(lock => lock.recordId === record?.id);
33+
if (!lock) return null;
34+
35+
return <span>Locked by {lock.identity}</span>;
36+
};
37+
38+
const PostList = () => (
39+
<WithLocks>
40+
<ListBase>
41+
<DataTable>
42+
{/* ... */}
43+
<DataTable.Col source="lockStatus" field={LockField} />
44+
</DataTable>
45+
</ListBase>
46+
</WithLocks>
47+
);
48+
```
49+
50+
## Props
51+
52+
| Prop | Required | Type | Default | Description |
53+
| ---------- | -------- | ----------- | ------- | ------------------------------------------------- |
54+
| `children` | Required | `ReactNode` | | The component to render inside the `LocksContext` |

0 commit comments

Comments
 (0)