Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for mutationOptions in <BulkUpdateButton> #9035

Merged
merged 2 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ import {
useUnselectAll,
useResourceContext,
MutationMode,
RaRecord,
UpdateManyParams,
} from 'ra-core';

import { Confirm } from '../layout';
import { Button, ButtonProps } from './Button';
import { BulkActionProps } from '../types';
import { UseMutationOptions } from 'react-query';

export const BulkUpdateWithConfirmButton = (
props: BulkUpdateWithConfirmButtonProps
Expand Down Expand Up @@ -67,16 +70,19 @@ export const BulkUpdateWithConfirmButton = (
);
setOpen(false);
},
mutationOptions = {},
...rest
} = props;
const { meta: mutationMeta, ...otherMutationOptions } = mutationOptions;

const [updateMany, { isLoading }] = useUpdateMany(
resource,
{ ids: selectedIds, data },
{ ids: selectedIds, data, meta: mutationMeta },
{
onSuccess,
onError,
mutationMode,
...otherMutationOptions,
}
);

Expand Down Expand Up @@ -145,8 +151,10 @@ const sanitizeRestProps = ({
'resource' | 'selectedIds' | 'icon' | 'data'
>) => rest;

export interface BulkUpdateWithConfirmButtonProps
extends BulkActionProps,
export interface BulkUpdateWithConfirmButtonProps<
RecordType extends RaRecord = any,
MutationOptionsError = unknown
> extends BulkActionProps,
ButtonProps {
confirmContent?: React.ReactNode;
confirmTitle?: string;
Expand All @@ -155,6 +163,11 @@ export interface BulkUpdateWithConfirmButtonProps
onSuccess?: () => void;
onError?: (error: any) => void;
mutationMode?: MutationMode;
mutationOptions?: UseMutationOptions<
RecordType,
MutationOptionsError,
UpdateManyParams<RecordType>
> & { meta?: any };
}

BulkUpdateWithConfirmButton.propTypes = {
Expand Down
19 changes: 16 additions & 3 deletions packages/ra-ui-materialui/src/button/BulkUpdateWithUndoButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import {
useUnselectAll,
useResourceContext,
useListContext,
RaRecord,
UpdateManyParams,
} from 'ra-core';
import { UseMutationOptions } from 'react-query';

import { Button, ButtonProps } from './Button';
import { BulkActionProps } from '../types';
Expand Down Expand Up @@ -59,16 +62,19 @@ export const BulkUpdateWithUndoButton = (
);
refresh();
},
mutationOptions = {},
...rest
} = props;
const { meta: mutationMeta, ...otherMutationOptions } = mutationOptions;

const [updateMany, { isLoading }] = useUpdateMany(
resource,
{ ids: selectedIds, data },
{ ids: selectedIds, data, meta: mutationMeta },
{
onSuccess,
onError,
mutationMode: 'undoable',
...otherMutationOptions,
}
);

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

export interface BulkUpdateWithUndoButtonProps
extends BulkActionProps,
export interface BulkUpdateWithUndoButtonProps<
RecordType extends RaRecord = any,
MutationOptionsError = unknown
> extends BulkActionProps,
ButtonProps {
icon?: ReactElement;
data: any;
onSuccess?: () => void;
onError?: (error: any) => void;
mutationOptions?: UseMutationOptions<
RecordType,
MutationOptionsError,
UpdateManyParams<RecordType>
> & { meta?: any };
}

BulkUpdateWithUndoButton.propTypes = {
Expand Down