Skip to content

Commit b931b95

Browse files
authored
Merge pull request #9077 from marmelab/BulkUpdateButton-doc
[Doc] Add doc for `<BulkUpdateButton>`
2 parents e84cfd5 + 99a12b0 commit b931b95

3 files changed

Lines changed: 54 additions & 7 deletions

File tree

docs/Buttons.md

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,58 @@ export const PostList = () => (
246246

247247
![Bulk Delete button](./img/bulk-delete-button.png)
248248

249-
| Prop | Required | Type | Default | Description |
250-
| --------------------| -------- | --------------- | ------------------ | ---------------------------------------------------|
251-
| `label` | Optional | `string` | 'ra.action.delete' | label or translation message to use |
252-
| `icon` | Optional | `ReactElement` | `<DeleteIcon>` | iconElement, e.g. `<CommentIcon />` |
253-
| `mutationOptions` | Optional | `object` | null | options for react-query `useMutation` hook |
249+
| Prop | Required | Type | Default | Description |
250+
|-------------------|----------|----------------|--------------------|---------------------------------------------------------------------------------------------------------------------|
251+
| `confirmContent` | Optional | React node | - | Lets you customize the content of the confirm dialog. Only used in `'pessimistic'` or `'optimistic'` mutation modes |
252+
| `confirmTitle` | Optional | `string` | - | Lets you customize the title of the confirm dialog. Only used in `'pessimistic'` or `'optimistic'` mutation modes |
253+
| `label` | Optional | `string` | 'ra.action.delete' | label or translation message to use |
254+
| `icon` | Optional | `ReactElement` | `<DeleteIcon>` | iconElement, e.g. `<CommentIcon />` |
255+
| `mutationMode` | Optional | `string` | `'undoable'` | Mutation mode (`'undoable'`, `'pessimistic'` or `'optimistic'`) |
256+
| `mutationOptions` | Optional | `object` | null | options for react-query `useMutation` hook |
257+
258+
**Tip:** If you choose the `'pessimistic'` or `'optimistic'` mutation mode, a confirm dialog will be displayed to the user before the mutation is executed.
259+
260+
### `<BulkUpdateButton>`
261+
262+
Partially updates the selected rows. To be used inside [the `<Datagrid bulkActionButtons>` prop](./Datagrid.md#bulkactionbuttons).
263+
264+
{% raw %}
265+
```jsx
266+
import * as React from 'react';
267+
import { Fragment } from 'react';
268+
import { BulkDeleteButton, BulkExportButton, BulkUpdateButton } from 'react-admin';
269+
270+
const PostBulkActionButtons = () => (
271+
<Fragment>
272+
<BulkExportButton />
273+
<BulkUpdateButton data={{ published_at: new Date() }} />
274+
<BulkDeleteButton />
275+
</Fragment>
276+
);
277+
278+
export const PostList = () => (
279+
<List>
280+
<Datagrid bulkActionButtons={<PostBulkActionButtons />}>
281+
...
282+
</Datagrid>
283+
</List>
284+
);
285+
```
286+
{% endraw %}
287+
288+
![Bulk Update button](./img/bulk-update-button.png)
289+
290+
| Prop | Required | Type | Default | Description |
291+
|-------------------|----------|----------------|--------------------|---------------------------------------------------------------------------------------------------------------------|
292+
| `data` | Required | `object` | - | An object with the fields that need to be updated on the selected records |
293+
| `confirmContent` | Optional | React node | - | Lets you customize the content of the confirm dialog. Only used in `'pessimistic'` or `'optimistic'` mutation modes |
294+
| `confirmTitle` | Optional | `string` | - | Lets you customize the title of the confirm dialog. Only used in `'pessimistic'` or `'optimistic'` mutation modes |
295+
| `icon` | Optional | `ReactElement` | `<ActionUpdate>` | An icon element |
296+
| `label` | Optional | `string` | 'ra.action.update' | Label or translation message to use |
297+
| `mutationMode` | Optional | `string` | `'undoable'` | Mutation mode (`'undoable'`, `'pessimistic'` or `'optimistic'`) |
298+
| `mutationOptions` | Optional | `object` | null | Options for react-query `useMutation` hook |
299+
300+
**Tip:** If you choose the `'pessimistic'` or `'optimistic'` mutation mode, a confirm dialog will be displayed to the user before the mutation is executed.
254301

255302
### `<FilterButton>`
256303

docs/Datagrid.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export const PostList = () => (
173173
);
174174
```
175175

176-
**Tip**: React-admin provides three components that you can use in `bulkActionButtons`: `<BulkDeleteButton>`, `<BulkUpdateButton>`, and `<BulkExportButton>`.
176+
**Tip**: React-admin provides three components that you can use in `bulkActionButtons`: [`<BulkDeleteButton>`](./Buttons.md#bulkdeletebutton), [`<BulkUpdateButton>`](./Buttons.md#bulkupdatebutton), and [`<BulkExportButton>`](./Buttons.md#bulkexportbutton).
177177

178178
**Tip**: You can also disable bulk actions altogether by passing `false` to the `bulkActionButtons` prop. In this case, the checkboxes column doesn't show up.
179179

@@ -183,7 +183,7 @@ Bulk action button components can use the [`useListContext`](./useListContext.md
183183
* `resource`: the currently displayed resource (eg `posts`, `comments`, etc.)
184184
* `filterValues`: the filter values. This can be useful if you want to apply your action on all items matching the filter.
185185

186-
Here is an example of custom bulk action button, which sets the `views` property of all posts to `0` optimistically:
186+
Here is an example of custom bulk action button, which sets the `views` property of all posts to `0`:
187187

188188
```jsx
189189
// in ./ResetViewsButton.js

docs/img/bulk-update-button.png

101 KB
Loading

0 commit comments

Comments
 (0)