|
| 1 | +--- |
| 2 | +layout: default |
| 3 | +title: "LockStatus" |
| 4 | +--- |
| 5 | + |
| 6 | +# `<LockStatus>` |
| 7 | + |
| 8 | +`<LockStatus>` is an [Enterprise Edition](https://react-admin-ee.marmelab.com)<img class="icon" src="./img/premium.svg" alt="React Admin Enterprise Edition icon" /> component that displays the lock status of the current record. It allows to visually indicate whether the record is locked or not, by the current user or not, and provides an easy way to lock or unlock the record. |
| 9 | + |
| 10 | +<video controls autoplay playsinline muted loop> |
| 11 | + <source src="https://registry.marmelab.com/assets/LockStatus.mp4" type="video/mp4"/> |
| 12 | + Your browser does not support the video tag. |
| 13 | +</video> |
| 14 | + |
| 15 | +## Usage |
| 16 | + |
| 17 | +Use `<LockStatus>` e.g. in a toolbar, to let the user know the lock status of the current record: |
| 18 | + |
| 19 | +{% raw %} |
| 20 | +```tsx |
| 21 | +import { Toolbar, SaveButton } from 'react-admin'; |
| 22 | +import { LockStatus } from '@react-admin/ra-realtime'; |
| 23 | + |
| 24 | +const CustomToolbar = () => { |
| 25 | + return ( |
| 26 | + <Toolbar> |
| 27 | + <SaveButton sx={{ mr: 1 }} /> |
| 28 | + <LockStatus /> |
| 29 | + </Toolbar> |
| 30 | + ); |
| 31 | +}; |
| 32 | +``` |
| 33 | +{% endraw %} |
| 34 | + |
| 35 | +You can also use it in a DataTable to show the lock status of each record: |
| 36 | + |
| 37 | +```tsx |
| 38 | +import { List, DataTable } from 'react-admin'; |
| 39 | +import { LockStatus } from '@react-admin/ra-realtime'; |
| 40 | + |
| 41 | +const PostList = () => { |
| 42 | + return ( |
| 43 | + <List> |
| 44 | + <DataTable> |
| 45 | + <DataTable.Col source="id" /> |
| 46 | + <DataTable.Col source="title" /> |
| 47 | + <DataTable.Col source="headline" /> |
| 48 | + <DataTable.Col source="author" /> |
| 49 | + <DataTable.Col label="Lock"> |
| 50 | + <LockStatus hideWhenUnlocked /> |
| 51 | + </DataTable.Col> |
| 52 | + </DataTable> |
| 53 | + </List> |
| 54 | + ); |
| 55 | +}; |
| 56 | +``` |
| 57 | + |
| 58 | +**Tip:** You can use the `hideWhenUnlocked` prop to hide the lock status when the record is not locked. This is useful to avoid showing too many lock icons in the DataTable when most records are not locked. |
| 59 | + |
| 60 | +## Props |
| 61 | + |
| 62 | +| Name | Required | Type | Default Value | Description | |
| 63 | +| ----------------------- | -------- | ------------ | --------------------------------- | --------------------------------------------------------------------------------------------- | |
| 64 | +| `hideWhenUnlocked` | No | `boolean` | - | Set to true to hide the lock status when the record is not locked. | |
| 65 | +| `identity` | No | `Identifier` | From `AuthProvider.getIdentity()` | An identifier for the user who owns the lock. | |
| 66 | +| `resource` | No | `string` | From `ResourceContext` | The resource name (e.g. `'posts'`). | |
| 67 | +| `id` | No | `Identifier` | From `RecordContext` | The record id (e.g. `123`). | |
| 68 | +| `meta` | No | `object` | - | Additional metadata forwarded to the dataProvider `lock()`, `unlock()` and `getLock()` calls. | |
| 69 | +| `lockMutationOptions` | No | `object` | - | `react-query` mutation options, used to customize the lock side-effects. | |
| 70 | +| `unlockMutationOptions` | No | `object` | - | `react-query` mutation options, used to customize the unlock side-effects. | |
| 71 | +| `queryOptions` | No | `object` | - | `react-query` query options, used to customize the lock query side-effects. | |
| 72 | + |
| 73 | +## Customizing the Tooltip Messages |
| 74 | + |
| 75 | +You can customize the tooltip messages displayed by `<LockStatus>` by overriding the following i18n keys in your translations: |
| 76 | +- `ra-realtime.locks.status.locked_by_you`: The tooltip message when the record is locked by the current user. |
| 77 | +- `ra-realtime.locks.status.locked_by_another_user`: The tooltip message when the record is locked by another user. |
| 78 | +- `ra-realtime.locks.status.unlocked`: The tooltip message when the record is unlocked. |
0 commit comments