From b002b3583df5dcb66f62581f902f0f5c259ed473 Mon Sep 17 00:00:00 2001 From: fzaninotto Date: Sun, 29 Sep 2019 22:31:16 +0200 Subject: [PATCH] Various fixes --- .../simple/src/comments/PostQuickCreate.js | 2 +- packages/ra-core/src/dataFetchActions.ts | 12 ++++---- .../ra-core/src/dataProvider/Mutation.tsx | 30 +++++-------------- .../ra-core/src/dataProvider/getFetchType.ts | 24 +++++++-------- .../ra-core/src/dataProvider/useCreate.ts | 15 ++-------- .../ra-core/src/dataProvider/useMutation.ts | 4 +-- .../ra-core/src/dataProvider/useUpdate.ts | 10 +------ 7 files changed, 31 insertions(+), 66 deletions(-) diff --git a/examples/simple/src/comments/PostQuickCreate.js b/examples/simple/src/comments/PostQuickCreate.js index 23af6ad37f5..5cc1b3c9006 100644 --- a/examples/simple/src/comments/PostQuickCreate.js +++ b/examples/simple/src/comments/PostQuickCreate.js @@ -48,7 +48,7 @@ const PostQuickCreate = ({ onCancel, onSave, ...props }) => { onSuccess: { callback: ({ payload: { data } }) => onSave(data), }, - onError: { + onFailure: { callback: ({ error }) => { dispatch(showNotification(error.message, 'error')); }, diff --git a/packages/ra-core/src/dataFetchActions.ts b/packages/ra-core/src/dataFetchActions.ts index 9e7af9c0747..99600d3efe1 100644 --- a/packages/ra-core/src/dataFetchActions.ts +++ b/packages/ra-core/src/dataFetchActions.ts @@ -23,8 +23,6 @@ export const fetchActionsWithTotalResponse = [GET_LIST, GET_MANY_REFERENCE]; export const sanitizeFetchType = (fetchType: string) => { switch (fetchType) { - case CREATE: - return 'create'; case GET_LIST: return 'getList'; case GET_ONE: @@ -33,14 +31,16 @@ export const sanitizeFetchType = (fetchType: string) => { return 'getMany'; case GET_MANY_REFERENCE: return 'getManyReference'; - case DELETE: - return 'delete'; - case DELETE_MANY: - return 'deleteMany'; + case CREATE: + return 'create'; case UPDATE: return 'update'; case UPDATE_MANY: return 'updateMany'; + case DELETE: + return 'delete'; + case DELETE_MANY: + return 'deleteMany'; default: return fetchType; } diff --git a/packages/ra-core/src/dataProvider/Mutation.tsx b/packages/ra-core/src/dataProvider/Mutation.tsx index 7ebeda11a92..ab334cdc422 100644 --- a/packages/ra-core/src/dataProvider/Mutation.tsx +++ b/packages/ra-core/src/dataProvider/Mutation.tsx @@ -1,5 +1,4 @@ -import { FunctionComponent, useCallback } from 'react'; -import merge from 'lodash/merge'; +import { FunctionComponent } from 'react'; import useMutation from './useMutation'; @@ -58,27 +57,12 @@ const Mutation: FunctionComponent = ({ resource, payload, options, -}) => { - const [mutate, state] = useMutation(); - - const finalMutate = useCallback( - (event: any, callTimeData?: any, callTimeOptions?: any) => - mutate( - { - resource, - payload: merge({}, payload, callTimeData), - type, - }, - merge( - { withDeclarativeSideEffectsSupport: true }, - options, - callTimeOptions - ) - ), - [mutate, resource, JSON.stringify({ payload, options })] // eslint-disable-line react-hooks/exhaustive-deps +}) => + children( + ...useMutation( + { type, resource, payload }, + { ...options, withDeclarativeSideEffectsSupport: true } + ) ); - return children(finalMutate, state); -}; - export default Mutation; diff --git a/packages/ra-core/src/dataProvider/getFetchType.ts b/packages/ra-core/src/dataProvider/getFetchType.ts index 2d365c05144..5c6799d2939 100644 --- a/packages/ra-core/src/dataProvider/getFetchType.ts +++ b/packages/ra-core/src/dataProvider/getFetchType.ts @@ -1,13 +1,13 @@ import { - CREATE, - DELETE, - DELETE_MANY, GET_LIST, + GET_ONE, GET_MANY, GET_MANY_REFERENCE, - GET_ONE, + CREATE, UPDATE, UPDATE_MANY, + DELETE, + DELETE_MANY, } from '../dataFetchActions'; /** @@ -19,24 +19,24 @@ import { */ export default actionType => { switch (actionType) { - case 'create': - return CREATE; - case 'delete': - return DELETE; - case 'deleteMany': - return DELETE_MANY; case 'getList': return GET_LIST; + case 'getOne': + return GET_ONE; case 'getMany': return GET_MANY; case 'getManyReference': return GET_MANY_REFERENCE; - case 'getOne': - return GET_ONE; + case 'create': + return CREATE; case 'update': return UPDATE; case 'updateMany': return UPDATE_MANY; + case 'delete': + return DELETE; + case 'deleteMany': + return DELETE_MANY; default: return actionType; diff --git a/packages/ra-core/src/dataProvider/useCreate.ts b/packages/ra-core/src/dataProvider/useCreate.ts index 7b988b23735..dd074a284ca 100644 --- a/packages/ra-core/src/dataProvider/useCreate.ts +++ b/packages/ra-core/src/dataProvider/useCreate.ts @@ -26,18 +26,7 @@ import useMutation from './useMutation'; * return