File tree Expand file tree Collapse file tree 3 files changed +33
-29
lines changed
ra-core/src/controller/button
ra-ui-materialui/src/button Expand file tree Collapse file tree 3 files changed +33
-29
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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 ) ;
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments