Skip to content

Commit 420ab1d

Browse files
committed
update the bulkActionsToolbar implementation
1 parent 002f485 commit 420ab1d

File tree

4 files changed

+46
-53
lines changed

4 files changed

+46
-53
lines changed

docs/Buttons.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ The `<SelectAllButton>` component allows users to select all items from a resour
964964

965965
## Usage
966966

967-
By default, react-admin's `<Datagrid>` displays a `<SelectAllButton>` in their List view action toolbar. You can custom it by specifying your own [`selectAllButton`](./Datagrid.md#selectallbutton):
967+
By default, react-admin's `<Datagrid>` displays a `<SelectAllButton>` in their `bulkActionsToolbar`. You can custom it by specifying your own `selectAllButton`:
968968

969969
{% raw %}
970970

@@ -980,7 +980,13 @@ const PostSelectAllButton = () => (
980980

981981
export const PostList = () => (
982982
<List>
983-
<Datagrid selectAllButton={<PostSelectAllButton />}>
983+
<Datagrid
984+
bulkActionsToolbar={
985+
<BulkActionsToolbar selectAllButton={PostSelectAllButton}>
986+
<BulkDeleteButton />
987+
</BulkActionsToolbar>
988+
}
989+
>
984990
...
985991
</Datagrid>
986992
</List>
@@ -1012,9 +1018,11 @@ const PostSelectAllButton = () => <SelectAllButton limit={100} />;
10121018
`<SelectAllButton>` calls a `get` method of your `dataProvider` via a react-query's `useQuery` hook. You can customize the options you pass to this hook, e.g. to pass [a custom `meta`](./Actions.md#meta-parameter) to the call.
10131019

10141020
{% raw %}
1021+
10151022
```jsx
10161023
const PostSelectAllButton = () => <SelectAllButton queryOptions={{ meta: { foo: 'bar' } }} />;
10171024
```
1025+
10181026
{% endraw %}
10191027

10201028
### `sx`: CSS API

docs/Datagrid.md

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ Both are [Enterprise Edition](https://react-admin-ee.marmelab.com) components.
6161
| `rowClick` | Optional | mixed | | The action to trigger when the user clicks on a row. |
6262
| `rowStyle` | Optional | Function | | A function that returns the style to apply to a row. |
6363
| `rowSx` | Optional | Function | | A function that returns the sx prop to apply to a row. |
64-
| `selectAllButton` | Optional | Element or `false` | | The button used to select all records. |
6564
| `size` | Optional | `'small'` or `'medium'` | `'small'` | The size of the table. |
6665
| `sx` | Optional | Object | | The sx prop passed down to the Material UI `<Table>` element. |
6766

@@ -374,38 +373,6 @@ const CustomResetViewsButton = () => {
374373
};
375374
```
376375

377-
## `selectAllButton`
378-
379-
You can use the `selectAllButton` prop to customize the default [`<SelectAllButton>`](./Buttons.md#selectallbutton) displayed in the bulk action toolbar when at least one row is selected.
380-
381-
```tsx
382-
import { List, Datagrid, SelectAllButton } from 'react-admin';
383-
384-
const PostSelectAllButton = () => <SelectAllButton label="Select all records" />
385-
386-
export const PostList = () => (
387-
<List>
388-
<Datagrid selectAllButton={<PostSelectAllButton />}>
389-
...
390-
</Datagrid>
391-
</List>
392-
);
393-
```
394-
395-
You disable this feature by setting the `selectAllButton` prop to `false`:
396-
397-
```tsx
398-
import { Datagrid, List } from 'react-admin';
399-
400-
export const PostList = () => (
401-
<List>
402-
<Datagrid selectAllButton={false}>
403-
...
404-
</Datagrid>
405-
</List>
406-
);
407-
```
408-
409376
## `children`
410377

411378
`<Datagrid>` accepts a list of Field components as children. It inspects each child's `source` and/or `label` props to determine the name of the column.

packages/ra-ui-materialui/src/list/datagrid/Datagrid.stories.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { List } from '../List';
3232
import { EditGuesser } from '../../detail';
3333
import { DatagridRowProps } from './DatagridRow';
3434
import DatagridBody, { DatagridBodyProps } from './DatagridBody';
35+
import { BulkActionsToolbar } from '../BulkActionsToolbar';
3536

3637
export default { title: 'ra-ui-materialui/list/Datagrid' };
3738

@@ -205,7 +206,13 @@ export const SelectAllButton = ({
205206
{(!onlyDisplay || onlyDisplay === 'disabled') && (
206207
<>
207208
<h1>Disabled</h1>
208-
<Datagrid selectAllButton={false}>
209+
<Datagrid
210+
bulkActionsToolbar={
211+
<BulkActionsToolbar selectAllButton={false}>
212+
<BulkDeleteButton />
213+
</BulkActionsToolbar>
214+
}
215+
>
209216
<TextField source="id" />
210217
<TextField source="title" />
211218
<TextField source="author" />
@@ -217,8 +224,14 @@ export const SelectAllButton = ({
217224
<>
218225
<h1>Custom</h1>
219226
<Datagrid
220-
selectAllButton={
221-
<RaSelectAllButton label="Select all records" />
227+
bulkActionsToolbar={
228+
<BulkActionsToolbar
229+
selectAllButton={
230+
<RaSelectAllButton label="Select all records" />
231+
}
232+
>
233+
<BulkDeleteButton />
234+
</BulkActionsToolbar>
222235
}
223236
>
224237
<TextField source="id" />

packages/ra-ui-materialui/src/list/datagrid/Datagrid.tsx

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import { RowClickFunction } from '../types';
3333
import DatagridContextProvider from './DatagridContextProvider';
3434
import { DatagridClasses, DatagridRoot } from './useDatagridStyles';
3535
import { BulkActionsToolbar } from '../BulkActionsToolbar';
36-
import type { BulkActionsToolbarProps } from '../BulkActionsToolbar';
3736
import { BulkDeleteButton } from '../../button';
3837
import { ListNoResults } from '../ListNoResults';
3938

@@ -45,7 +44,7 @@ const defaultBulkActionButtons = <BulkDeleteButton />;
4544
*
4645
* Props:
4746
* - body
48-
* - selectAllButton
47+
* - bulkActionToolbar
4948
* - bulkActionButtons
5049
* - children
5150
* - empty
@@ -134,7 +133,7 @@ export const Datagrid: React.ForwardRefExoticComponent<
134133
className,
135134
empty = DefaultEmpty,
136135
expand,
137-
selectAllButton,
136+
bulkActionsToolbar,
138137
bulkActionButtons = canDelete ? defaultBulkActionButtons : false,
139138
hover,
140139
isRowSelectable,
@@ -247,13 +246,14 @@ export const Datagrid: React.ForwardRefExoticComponent<
247246
sx={sx}
248247
className={clsx(DatagridClasses.root, className)}
249248
>
250-
{bulkActionButtons !== false ? (
251-
<BulkActionsToolbar selectAllButton={selectAllButton}>
252-
{isValidElement(bulkActionButtons)
253-
? bulkActionButtons
254-
: defaultBulkActionButtons}
255-
</BulkActionsToolbar>
256-
) : null}
249+
{bulkActionsToolbar ??
250+
(bulkActionButtons !== false ? (
251+
<BulkActionsToolbar>
252+
{isValidElement(bulkActionButtons)
253+
? bulkActionButtons
254+
: defaultBulkActionButtons}
255+
</BulkActionsToolbar>
256+
) : null)}
257257
<div className={DatagridClasses.tableWrapper}>
258258
<Table
259259
ref={ref}
@@ -321,21 +321,26 @@ export interface DatagridProps<RecordType extends RaRecord = any>
321321
className?: string;
322322

323323
/**
324-
* The button used to select all records.
324+
* The component used to render the bulk actions toolbar.
325325
*
326-
* @see https://marmelab.com/react-admin/Datagrid.html#selectallbutton
327326
* @example
328-
* import { List, Datagrid, SelectAllButton } from 'react-admin';
327+
* import { List, Datagrid, BulkActionsToolbar, SelectAllButton, BulkDeleteButton } from 'react-admin';
328+
*
329+
* const PostBulkActionsToolbar = () => (
330+
* <BulkActionsToolbar selectAllButton={<SelectAllButton label="Select all records" />}>
331+
* <BulkDeleteButton />
332+
* </BulkActionsToolbar>
333+
* );
329334
*
330335
* export const PostList = () => (
331336
* <List>
332-
* <Datagrid selectAllButton={<SelectAllButton label="Select all records" />}>
337+
* <Datagrid bulkActionsToolbar={<PostBulkActionsToolbar />}>
333338
* ...
334339
* </Datagrid>
335340
* </List>
336341
* );
337342
*/
338-
selectAllButton?: BulkActionsToolbarProps['selectAllButton'];
343+
bulkActionsToolbar?: ReactElement;
339344

340345
/**
341346
* The component used to render the bulk action buttons. Defaults to <BulkDeleteButton>.

0 commit comments

Comments
 (0)