From a03c484d12409eec2efc79231221786c8c830f65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kr=C3=BCger?= Date: Fri, 24 Feb 2023 09:00:00 +0100 Subject: [PATCH 1/2] refactor: move extraInformation to meta The *Params datatypes have a meta field that can be filled with any value as necesarry for the dataprovider, see UpdateParams here https://github.com/marmelab/react-admin/blob/master/packages/ra-core/src/types.ts#L189-L194 It's better to use this value instead of polluting the data object --- src/CreateGuesser.tsx | 3 ++- src/EditGuesser.tsx | 5 +++-- src/hydra/dataProvider.test.ts | 12 ++++++------ src/hydra/dataProvider.ts | 5 ++--- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/CreateGuesser.tsx b/src/CreateGuesser.tsx index 77d87543..69765d9d 100644 --- a/src/CreateGuesser.tsx +++ b/src/CreateGuesser.tsx @@ -97,7 +97,8 @@ export const IntrospectedCreateGuesser = ({ const response = await create( resource, { - data: { ...data, extraInformation: { hasFileField } }, + data, + meta: { hasFileField }, }, { returnPromise: true }, ); diff --git a/src/EditGuesser.tsx b/src/EditGuesser.tsx index acc776fa..e5b811dd 100644 --- a/src/EditGuesser.tsx +++ b/src/EditGuesser.tsx @@ -121,7 +121,8 @@ export const IntrospectedEditGuesser = ({ resource, { id, - data: { ...data, extraInformation: { hasFileField } }, + data, + meta: { hasFileField }, }, { returnPromise: true }, ); @@ -197,7 +198,7 @@ export const IntrospectedEditGuesser = ({ id={id} mutationMode={mutationMode} redirect={redirectTo} - transform={(data) => ({ ...data, extraInformation: { hasFileField } })} + transform={(data) => data} {...props}> { data: { bar: 'baz', foo: 'foo', - extraInformation: { - hasFileField: true, - }, + }, + meta: { + hasFileField: true, }, }); const url = mockFetchHydra.mock.calls?.[0]?.[0] ?? new URL('https://foo'); @@ -330,9 +330,9 @@ describe('Transform a React Admin request to an Hydra request', () => { foo: 'foo', bar: 'baz', qux: null, - extraInformation: { - hasFileField: true, - }, + }, + meta: { + hasFileField: true, }, previousData: { id: '/entrypoint/resource/1', diff --git a/src/hydra/dataProvider.ts b/src/hydra/dataProvider.ts index c24407e8..94658bb1 100644 --- a/src/hydra/dataProvider.ts +++ b/src/hydra/dataProvider.ts @@ -351,9 +351,8 @@ function dataProvider( } }); let extraInformation: { hasFileField?: boolean } = {}; - if ('data' in params && params.data.extraInformation) { - extraInformation = params.data.extraInformation; - delete params.data.extraInformation; + if ('meta' in params) { + extraInformation = params.meta; } const updateHttpMethod = extraInformation.hasFileField ? 'POST' : 'PUT'; From e957ab8f1311683611bb4f2fd06148aea23cf06f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Suwi=C5=84ski?= Date: Wed, 27 Mar 2024 15:21:51 +0100 Subject: [PATCH 2/2] remove passing unnecessary tranport parameter --- src/EditGuesser.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/EditGuesser.tsx b/src/EditGuesser.tsx index abe4dd7b..af018f3f 100644 --- a/src/EditGuesser.tsx +++ b/src/EditGuesser.tsx @@ -199,7 +199,6 @@ export const IntrospectedEditGuesser = ({ id={id} mutationMode={mutationMode} redirect={redirectTo} - transform={(data) => data} component={viewComponent} {...props}>