Skip to content

Commit 80052c0

Browse files
committed
Fix missing data
1 parent ebc0f3b commit 80052c0

File tree

3 files changed

+33
-29
lines changed

3 files changed

+33
-29
lines changed

packages/ra-core/src/controller/button/useUpdateController.tsx

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const useUpdateController = <
6363
ErrorType = Error,
6464
>(
6565
props: UseUpdateControllerParams<RecordType, ErrorType>
66-
): UseUpdateControllerReturn => {
66+
): UseUpdateControllerReturn<RecordType> => {
6767
const {
6868
redirect: redirectTo = false,
6969
mutationMode,
@@ -120,32 +120,36 @@ export const useUpdateController = <
120120
}
121121
);
122122

123-
const handleUpdate = useCallback(() => {
124-
if (!record) {
125-
throw new Error(
126-
'The record cannot be updated because no record has been passed'
123+
const handleUpdate = useCallback(
124+
(data: Partial<RecordType>) => {
125+
if (!record) {
126+
throw new Error(
127+
'The record cannot be updated because no record has been passed'
128+
);
129+
}
130+
updateOne(
131+
resource,
132+
{
133+
id: record.id,
134+
data,
135+
previousData: record,
136+
meta: mutationMeta,
137+
},
138+
{
139+
mutationMode,
140+
...otherMutationOptions,
141+
}
127142
);
128-
}
129-
updateOne(
143+
},
144+
[
145+
updateOne,
146+
mutationMeta,
147+
mutationMode,
148+
otherMutationOptions,
149+
record,
130150
resource,
131-
{
132-
id: record.id,
133-
previousData: record,
134-
meta: mutationMeta,
135-
},
136-
{
137-
mutationMode,
138-
...otherMutationOptions,
139-
}
140-
);
141-
}, [
142-
updateOne,
143-
mutationMeta,
144-
mutationMode,
145-
otherMutationOptions,
146-
record,
147-
resource,
148-
]);
151+
]
152+
);
149153

150154
return useMemo(
151155
() => ({
@@ -169,8 +173,8 @@ export interface UseUpdateControllerParams<
169173
successMessage?: string;
170174
}
171175

172-
export interface UseUpdateControllerReturn {
176+
export interface UseUpdateControllerReturn<RecordType extends RaRecord = any> {
173177
isLoading: boolean;
174178
isPending: boolean;
175-
handleUpdate: () => void;
179+
handleUpdate: (data: Partial<RecordType>) => void;
176180
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const UpdateWithConfirmButton = <
6464
};
6565

6666
const handleConfirm = e => {
67-
handleUpdate();
67+
handleUpdate(data);
6868

6969
if (typeof onClick === 'function') {
7070
onClick(e);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export const UpdateWithUndoButton = (inProps: UpdateWithUndoButtonProps) => {
6868
'The UpdateWithUndoButton must be used inside a RecordContext.Provider or must be passed a record prop.'
6969
);
7070
}
71-
handleUpdate();
71+
handleUpdate(data);
7272
if (typeof onClick === 'function') {
7373
onClick(e);
7474
}

0 commit comments

Comments
 (0)