Skip to content

Commit 0fa640f

Browse files
authored
Merge pull request #9035 from KonkretneKosteczki/next
Mutation options on bulk update buttons
2 parents 5dedc3a + 177f15c commit 0fa640f

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

packages/ra-ui-materialui/src/button/BulkUpdateWithConfirmButton.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ import {
1313
useUnselectAll,
1414
useResourceContext,
1515
MutationMode,
16+
RaRecord,
17+
UpdateManyParams,
1618
} from 'ra-core';
1719

1820
import { Confirm } from '../layout';
1921
import { Button, ButtonProps } from './Button';
2022
import { BulkActionProps } from '../types';
23+
import { UseMutationOptions } from 'react-query';
2124

2225
export const BulkUpdateWithConfirmButton = (
2326
props: BulkUpdateWithConfirmButtonProps
@@ -67,16 +70,19 @@ export const BulkUpdateWithConfirmButton = (
6770
);
6871
setOpen(false);
6972
},
73+
mutationOptions = {},
7074
...rest
7175
} = props;
76+
const { meta: mutationMeta, ...otherMutationOptions } = mutationOptions;
7277

7378
const [updateMany, { isLoading }] = useUpdateMany(
7479
resource,
75-
{ ids: selectedIds, data },
80+
{ ids: selectedIds, data, meta: mutationMeta },
7681
{
7782
onSuccess,
7883
onError,
7984
mutationMode,
85+
...otherMutationOptions,
8086
}
8187
);
8288

@@ -145,8 +151,10 @@ const sanitizeRestProps = ({
145151
'resource' | 'selectedIds' | 'icon' | 'data'
146152
>) => rest;
147153

148-
export interface BulkUpdateWithConfirmButtonProps
149-
extends BulkActionProps,
154+
export interface BulkUpdateWithConfirmButtonProps<
155+
RecordType extends RaRecord = any,
156+
MutationOptionsError = unknown
157+
> extends BulkActionProps,
150158
ButtonProps {
151159
confirmContent?: React.ReactNode;
152160
confirmTitle?: string;
@@ -155,6 +163,11 @@ export interface BulkUpdateWithConfirmButtonProps
155163
onSuccess?: () => void;
156164
onError?: (error: any) => void;
157165
mutationMode?: MutationMode;
166+
mutationOptions?: UseMutationOptions<
167+
RecordType,
168+
MutationOptionsError,
169+
UpdateManyParams<RecordType>
170+
> & { meta?: any };
158171
}
159172

160173
BulkUpdateWithConfirmButton.propTypes = {

packages/ra-ui-materialui/src/button/BulkUpdateWithUndoButton.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import {
1111
useUnselectAll,
1212
useResourceContext,
1313
useListContext,
14+
RaRecord,
15+
UpdateManyParams,
1416
} from 'ra-core';
17+
import { UseMutationOptions } from 'react-query';
1518

1619
import { Button, ButtonProps } from './Button';
1720
import { BulkActionProps } from '../types';
@@ -59,16 +62,19 @@ export const BulkUpdateWithUndoButton = (
5962
);
6063
refresh();
6164
},
65+
mutationOptions = {},
6266
...rest
6367
} = props;
68+
const { meta: mutationMeta, ...otherMutationOptions } = mutationOptions;
6469

6570
const [updateMany, { isLoading }] = useUpdateMany(
6671
resource,
67-
{ ids: selectedIds, data },
72+
{ ids: selectedIds, data, meta: mutationMeta },
6873
{
6974
onSuccess,
7075
onError,
7176
mutationMode: 'undoable',
77+
...otherMutationOptions,
7278
}
7379
);
7480

@@ -102,13 +108,20 @@ const sanitizeRestProps = ({
102108
...rest
103109
}: Omit<BulkUpdateWithUndoButtonProps, 'resource' | 'icon' | 'data'>) => rest;
104110

105-
export interface BulkUpdateWithUndoButtonProps
106-
extends BulkActionProps,
111+
export interface BulkUpdateWithUndoButtonProps<
112+
RecordType extends RaRecord = any,
113+
MutationOptionsError = unknown
114+
> extends BulkActionProps,
107115
ButtonProps {
108116
icon?: ReactElement;
109117
data: any;
110118
onSuccess?: () => void;
111119
onError?: (error: any) => void;
120+
mutationOptions?: UseMutationOptions<
121+
RecordType,
122+
MutationOptionsError,
123+
UpdateManyParams<RecordType>
124+
> & { meta?: any };
112125
}
113126

114127
BulkUpdateWithUndoButton.propTypes = {

0 commit comments

Comments
 (0)