You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`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' | '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' | '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 |
45
45
|`icon`| Optional |`ReactElement`|`<DeleteIcon>`| iconElement, e.g. `<CommentIcon />`|
46
-
|`mutationMode`| Optional |`string`|`'undoable'`| Mutation mode (`'undoable'`, `'pessimistic'` or `'optimistic'`) |
|`success Message`| Optional |`string`| 'ra-soft-delete.notification.soft_deleted' | Lets you customize the success notification message. |
49
49
50
50
**Tip:** If you choose the `'pessimistic'` or `'optimistic'` mutation mode, a confirm dialog will be displayed to the user before the mutation is executed.
Copy file name to clipboardExpand all lines: docs/SoftDeleteButton.md
+8-7Lines changed: 8 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,30 +5,31 @@ title: "The SoftDeleteButton Component"
5
5
6
6
# `<SoftDeleteButton>`
7
7
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.
9
9
10
10

11
11
12
12
## Usage
13
13
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:
When pressed, it will call `dataProvider.softDelete()` with the current record's `id`.
30
31
31
-
You can also call it with a record and a resource:
32
+
You can also specify a record and a resource:
32
33
33
34
{% raw %}
34
35
```tsx
@@ -186,9 +187,9 @@ Alternately, pass a `successMessage` prop:
186
187
187
188
## Access Control
188
189
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.
190
191
191
-
`<SoftDeleteButton>`will call`authProvider.canAccess()` using the following parameters:
192
+
This means `<SoftDeleteButton>`calls`authProvider.canAccess()` using the following parameters:
Copy file name to clipboardExpand all lines: docs/SoftDeleteDataProvider.md
+74-35Lines changed: 74 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,30 @@ title: "Soft Delete Setup"
5
5
6
6
# Soft Delete Setup
7
7
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
9
32
10
33
`ra-soft-delete` relies on the `dataProvider` to soft-delete, restore or view deleted records.
11
34
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
20
43
-`hardDeleteMany` permanently deletes many records.
21
44
- (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.
22
45
46
+
### Signature
47
+
48
+
Here is the full `SoftDeleteDataProvider` interface:
**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.
74
101
75
102
**Tip**: Deleted records are immutable, so you don't need to implement an `updateDeleted` method.
76
103
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`.
A _deleted record_ is an object with the following properties:
78
117
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
+
79
126
```js
80
127
{
81
128
id:123,
@@ -91,37 +138,13 @@ A _deleted record_ is an object with the following properties:
91
138
}
92
139
```
93
140
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`.
`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:
121
144
122
-
##`addSoftDeleteBasedOnResource`
145
+
-`addSoftDeleteBasedOnResource` stores the deleted records for all resources in a single resource. This resource is named `deleted_records` by default.
123
146
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.
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.
140
161
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.
142
163
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.
**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:
`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