Skip to content

Commit 5265fb7

Browse files
committed
Misc doc fixes
1 parent f6ccb1c commit 5265fb7

File tree

6 files changed

+104
-64
lines changed

6 files changed

+104
-64
lines changed

docs/BulkSoftDeleteButton.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ export const PostList = () => (
3838

3939
| Prop | Required | Type | Default | Description |
4040
|-------------------|----------|-----------------------------------------|--------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------|
41-
| `confirmContent` | Optional | React node | - | Lets you customize the content of the confirm dialog. Only used in `'pessimistic'` or `'optimistic'` mutation modes |
42-
| `confirmTitle` | Optional | `string` | - | Lets you customize the title of the confirm dialog. Only used in `'pessimistic'` or `'optimistic'` mutation modes |
43-
| `confirmColor` | Optional | <code>'primary' &#124; 'warning'</code> | 'primary' | Lets you customize the color of the confirm dialog's "Confirm" button. Only used in `'pessimistic'` or `'optimistic'` mutation modes |
44-
| `label` | Optional | `string` | 'ra-soft-delete.action.soft_delete' | label or translation message to use |
41+
| `confirm Content` | Optional | React node | - | Lets you customize the content of the confirm dialog. Only used in `'pessimistic'` or `'optimistic'` mutation modes |
42+
| `confirm Title` | Optional | `string` | - | Lets you customize the title of the confirm dialog. Only used in `'pessimistic'` or `'optimistic'` mutation modes |
43+
| `confirm Color` | Optional | <code>'primary' &#124; 'warning'</code> | 'primary' | Lets you customize the color of the confirm dialog's "Confirm" button. Only used in `'pessimistic'` or `'optimistic'` mutation modes |
44+
| `label` | Optional | `string` | 'ra-soft-delete. action. soft_delete' | label or translation message to use |
4545
| `icon` | Optional | `ReactElement` | `<DeleteIcon>` | iconElement, e.g. `<CommentIcon />` |
46-
| `mutationMode` | Optional | `string` | `'undoable'` | Mutation mode (`'undoable'`, `'pessimistic'` or `'optimistic'`) |
47-
| `mutationOptions` | Optional | `object` | null | options for react-query `useMutation` hook |
48-
| `successMessage` | Optional | `string` | 'ra-soft-delete.notification.soft_deleted' | Lets you customize the success notification message. |
46+
| `mutation Mode` | Optional | `string` | `'undoable'` | Mutation mode (`'undoable'`, `'pessimistic'` or `'optimistic'`) |
47+
| `mutation Options` | Optional | `object` | null | options for react-query `useMutation` hook |
48+
| `success Message` | Optional | `string` | 'ra-soft-delete. notification. soft_deleted' | Lets you customize the success notification message. |
4949

5050
**Tip:** If you choose the `'pessimistic'` or `'optimistic'` mutation mode, a confirm dialog will be displayed to the user before the mutation is executed.
5151

docs/DeletedRecordsList.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ That's enough to display the deleted records list, with functional simple filter
3939
| Prop | Required | Type | Default | Description |
4040
|----------------------------|----------|---------------------------------|------------------------------------------|--------------------------------------------------------------------------------------------------|
4141
| `debounce` | Optional | `number` | `500` | The debounce delay in milliseconds to apply when users change the sort or filter parameters. |
42-
| `children` | Optional | `Element` | `<DeletedRecordsTable>` | The component used to render the list of deleted records. |
43-
| `detailComponents` | Optional | `Record<string, ComponentType>` | - | The custom show components for each resource in the deleted records list. |
42+
| `children` | Optional | `Element` | `<Deleted Records Table>` | The component used to render the list of deleted records. |
43+
| `detail Components` | Optional | `Record<string, ComponentType>` | - | The custom show components for each resource in the deleted records list. |
4444
| `disable Authentication` | Optional | `boolean` | `false` | Set to `true` to disable the authentication check. |
4545
| `disable SyncWithLocation` | Optional | `boolean` | `false` | Set to `true` to disable the synchronization of the list parameters with the URL. |
4646
| `filter` | Optional | `object` | - | The permanent filter values. |

docs/SoftDeleteButton.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,31 @@ title: "The SoftDeleteButton Component"
55

66
# `<SoftDeleteButton>`
77

8-
Soft-deletes the current record.
8+
A button that soft-deletes the current record. By default, its label is "Archive" instead of "Delete", to reflect the fact that the record is not permanently deleted.
99

1010
![A soft delete button in a `<DataTable>`](https://react-admin-ee.marmelab.com/assets/SoftDeleteButton.png)
1111

1212
## Usage
1313

14-
`<SoftDeleteButton>` reads the current record from `RecordContext`, and the current resource from `ResourceContext`, so in general it doesn't need any property:
14+
`<SoftDeleteButton>` reads the current record from `RecordContext`, and the current resource from `ResourceContext`, so in general it doesn't need any property. You can use it anywhere you would use a regular `<DeleteButton>`, for example in a `<Show>` view:
1515

1616
{% raw %}
1717
```tsx
18+
import { Show } from 'react-admin';
1819
import { SoftDeleteButton } from '@react-admin/ra-soft-delete';
1920

2021
const CommentShow = () => (
21-
<>
22+
<Show>
2223
{/* ... */}
2324
<SoftDeleteButton />
24-
</>
25+
</Show>
2526
);
2627
```
2728
{% endraw %}
2829

2930
When pressed, it will call `dataProvider.softDelete()` with the current record's `id`.
3031

31-
You can also call it with a record and a resource:
32+
You can also specify a record and a resource:
3233

3334
{% raw %}
3435
```tsx
@@ -186,9 +187,9 @@ Alternately, pass a `successMessage` prop:
186187

187188
## Access Control
188189

189-
If your `authProvider` implements [Access Control](https://marmelab.com/react-admin/Permissions.html#access-control), `<SoftDeleteButton>` will only render if the user has the "soft_delete" access to the related resource.
190+
If your `authProvider` implements [Access Control](https://marmelab.com/react-admin/Permissions.html#access-control), `<SoftDeleteButton>` will only render if the user has the `soft_delete` access to the related resource.
190191

191-
`<SoftDeleteButton>` will call `authProvider.canAccess()` using the following parameters:
192+
This means `<SoftDeleteButton>` calls `authProvider.canAccess()` using the following parameters:
192193

193194
```txt
194195
{ action: "soft_delete", resource: [current resource], record: [current record] }

docs/SoftDeleteDataProvider.md

Lines changed: 74 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,30 @@ title: "Soft Delete Setup"
55

66
# Soft Delete Setup
77

8-
## Soft Delete Methods & Signature
8+
The soft delete feature is an Enterprise Edition add-on that allows you to "delete" records without actually removing them from your database.
9+
10+
Use it to:
11+
12+
- Archive records safely instead of permanent deletion
13+
- Browse and filter all deleted records in a dedicated interface
14+
- Restore archived items individually or in bulk
15+
- Track who deleted what and when
16+
17+
It provides drop-in replacements for DeleteButton and BulkDeleteButton.
18+
19+
## Installation
20+
21+
```bash
22+
npm install --save @react-admin/ra-soft-delete
23+
# or
24+
yarn add @react-admin/ra-soft-delete
25+
```
26+
27+
You will need an active Enterprise Edition license to use this package. Please refer to the [Enterprise Edition documentation](https://marmelab.com/react-admin/enterprise-edition.html) for more details.
28+
29+
## Data Provider
30+
31+
### Methods
932

1033
`ra-soft-delete` relies on the `dataProvider` to soft-delete, restore or view deleted records.
1134
In order to use the `ra-soft-delete`, you must add a few new methods to your data provider:
@@ -20,6 +43,10 @@ In order to use the `ra-soft-delete`, you must add a few new methods to your dat
2043
- `hardDeleteMany` permanently deletes many records.
2144
- (OPTIONAL) [`createMany`](#createmany) creates multiple records at once. This method is used internally by some data provider implementations to delete or restore multiple records at once. As it is optional, a default implementation is provided that simply calls `create` multiple times.
2245

46+
### Signature
47+
48+
Here is the full `SoftDeleteDataProvider` interface:
49+
2350
```tsx
2451
const dataProviderWithSoftDelete: SoftDeleteDataProvider = {
2552
...dataProvider,
@@ -70,12 +97,32 @@ const dataProviderWithSoftDelete: SoftDeleteDataProvider = {
7097
};
7198
```
7299

73-
**Tip**: `ra-soft-delete` will automatically populate the `authorId` using your `authProvider`'s `getIdentity` method if there is one. It will use the `id` field of the returned identity object. Otherwise this field will be left blank.
100+
**Tip**: `ra-soft-delete` automatically populates the `authorId` parameter using `authProvider.getIdentity()` if it is implemented. It will use the `id` field of the returned identity object. Otherwise this field will be left blank.
74101

75102
**Tip**: Deleted records are immutable, so you don't need to implement an `updateDeleted` method.
76103

104+
Once your provider has all soft-delete methods, pass it to the `<Admin>` component and you're ready to start using `ra-soft-delete`.
105+
106+
```tsx
107+
// in src/App.tsx
108+
import { Admin } from 'react-admin';
109+
import { dataProvider } from './dataProvider';
110+
111+
const App = () => <Admin dataProvider={dataProvider}>{/* ... */}</Admin>;
112+
```
113+
114+
### Deleted Record Structure
115+
77116
A _deleted record_ is an object with the following properties:
78117

118+
- `id`: The identifier of the deleted record.
119+
- `resource`: The resource name of the deleted record.
120+
- `deleted_at`: The date and time when the record was deleted, in ISO 8601 format.
121+
- `deleted_by`: (optional) The identifier of the user who deleted the record.
122+
- `data`: The original record data before deletion.
123+
124+
Here is an example of a deleted record:
125+
79126
```js
80127
{
81128
id: 123,
@@ -91,37 +138,13 @@ A _deleted record_ is an object with the following properties:
91138
}
92139
```
93140

94-
`ra-soft-delete` comes with two built-in implementations that will add soft delete capabilities to your data provider:
95-
96-
- [`addSoftDeleteBasedOnResource`](#addsoftdeletebasedonresource) stores the deleted records for all resources in a single `deleted_records` (configurable) resource.
97-
- [`addSoftDeleteInPlace`](#addsoftdeleteinplace) keeps the deleted records in the same resource, but fills `deleted_at` (configurable) and `deleted_by` (configurable) fields.
98-
99-
You can also write your own implementation. Feel free to look at these builders source code for inspiration. You can find it under your `node_modules` folder, e.g. at `node_modules/@react-admin/ra-soft-delete/src/dataProvider/addSoftDeleteBasedOnResource.ts`.
100-
101-
Once your provider has all soft-delete methods, pass it to the `<Admin>` component and you're ready to start using `ra-soft-delete`.
102-
103-
```tsx
104-
// in src/App.tsx
105-
import { Admin } from 'react-admin';
106-
import { dataProvider } from './dataProvider';
107-
108-
const App = () => <Admin dataProvider={dataProvider}>{/* ... */}</Admin>;
109-
```
110-
111-
Each data provider verb has its own hook so you can use them in custom components:
141+
### Builders
112142

113-
- `softDelete`: [`useSoftDelete`](./useSoftDelete.md)
114-
- `softDeleteMany`: [`useSoftDeleteMany`](./useSoftDeleteMany.md)
115-
- `getListDeleted`: [`useGetListDeleted`](./useGetListDeleted.md)
116-
- `getOneDeleted`: [`useGetOneDeleted`](./useGetOneDeleted.md)
117-
- `restoreOne`: [`useRestoreOne`](./useRestoreOne.md)
118-
- `restoreMany`: [`useRestoreMany`](./useRestoreMany.md)
119-
- `hardDelete`: [`useHardDelete`](./useHardDelete.md)
120-
- `hardDeleteMany`: [`useHardDeleteMany`](./useHardDeleteMany.md)
143+
`ra-soft-delete` comes with two built-in implementations that will add soft delete capabilities to your data provider without any specific backend requirements. You can choose the one that best fits your needs:
121144

122-
## `addSoftDeleteBasedOnResource`
145+
- `addSoftDeleteBasedOnResource` stores the deleted records for all resources in a single resource. This resource is named `deleted_records` by default.
123146

124-
Use `addSoftDeleteBasedOnResource` to add the soft delete capabilities to your data provider, storing all deleted records in a single `deleted_records` (configurable) resource.
147+
With this builder, all deleted records disappear from their original resource when soft-deleted, and are recreated in the `deleted_records` resource.
125148

126149
```tsx
127150
// in src/dataProvider.ts
@@ -134,13 +157,11 @@ export const dataProvider = addSoftDeleteBasedOnResource(
134157
);
135158
```
136159

137-
## `addSoftDeleteInPlace`
138-
139-
Use `addSoftDeleteInPlace` to add the soft delete capabilities to your data provider, keeping the deleted records in the same resource. This implementation will simply fill the `deleted_at` (configurable) and `deleted_by` (configurable) fields.
160+
- `addSoftDeleteInPlace` keeps the deleted records in the same resource, but marks them as deleted.
140161

141-
You'll need to pass an object with all your resources as key so that `getListDeleted` knows where to look for deleted records.
162+
With this builder, all deleted records remain in their original resource when soft-deleted, but are marked with the `deleted_at` and `deleted_by` fields. The query methods (`getList`, `getOne`, etc.) automatically filter out deleted records.
142163

143-
> **Note on performances:** Avoid calling `getListDeleted` without a `resource` filter, as it uses a naive implementation combining multiple `getList` calls, which can lead to bad performances. It is recommended to use one list per resource in this case (see [`<DeletedRecordsList resource>` property](./DeletedRecordsList.md#resource)).
164+
You'll need to pass a configuration object with all soft deletable resources as key so that `getListDeleted` knows where to look for deleted records.
144165

145166
```tsx
146167
// in src/dataProvider.ts
@@ -162,6 +183,24 @@ export const dataProvider = addSoftDeleteInPlace(
162183
);
163184
```
164185

186+
**Note:** When using `addSoftDeleteInPlace`, avoid calling `getListDeleted` without a `resource` filter, as it uses a naive implementation combining multiple `getList` calls, which can lead to bad performance. It is recommended to use one list per resource in this case (see [`<DeletedRecordsList resource>` property](./DeletedRecordsList.md#resource)).
187+
188+
You can also write your own implementation. Feel free to look at these builders source code for inspiration. You can find it under your `node_modules` folder, e.g. at `node_modules/@react-admin/ra-soft-delete/src/dataProvider/addSoftDeleteBasedOnResource.ts`.
189+
190+
### Query and Mutation Hooks
191+
192+
Each data provider verb has its own hook so you can use them in custom components:
193+
194+
- `softDelete`: [`useSoftDelete`](./useSoftDelete.md)
195+
- `softDeleteMany`: [`useSoftDeleteMany`](./useSoftDeleteMany.md)
196+
- `getListDeleted`: [`useGetListDeleted`](./useGetListDeleted.md)
197+
- `getOneDeleted`: [`useGetOneDeleted`](./useGetOneDeleted.md)
198+
- `restoreOne`: [`useRestoreOne`](./useRestoreOne.md)
199+
- `restoreMany`: [`useRestoreMany`](./useRestoreMany.md)
200+
- `hardDelete`: [`useHardDelete`](./useHardDelete.md)
201+
- `hardDeleteMany`: [`useHardDeleteMany`](./useHardDeleteMany.md)
202+
203+
165204
## `createMany`
166205

167206
`ra-soft-delete` provides a default implementation of the `createMany` method that simply calls `create` multiple times. However, some data providers may be able to create multiple records at once, which can greatly improve performances.

0 commit comments

Comments
 (0)