From 4645fb57ad8a9b443321677ba3cd3fe9c2e8cb33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kr=C3=BCger?= Date: Wed, 27 Mar 2024 15:27:12 +0100 Subject: [PATCH] refactor: move extraInformation to meta (#498) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 * remove passing unnecessary tranport parameter --------- Co-authored-by: Paweł Suwiński --- src/CreateGuesser.tsx | 3 ++- src/EditGuesser.tsx | 7 ++----- src/hydra/dataProvider.test.ts | 12 ++++++------ src/hydra/dataProvider.ts | 5 ++--- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/CreateGuesser.tsx b/src/CreateGuesser.tsx index 4faacded..4ecff21d 100644 --- a/src/CreateGuesser.tsx +++ b/src/CreateGuesser.tsx @@ -98,7 +98,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 7c21cb47..af018f3f 100644 --- a/src/EditGuesser.tsx +++ b/src/EditGuesser.tsx @@ -122,7 +122,8 @@ export const IntrospectedEditGuesser = ({ resource, { id, - data: { ...data, extraInformation: { hasFileField } }, + data, + meta: { hasFileField }, }, { returnPromise: true }, ); @@ -199,10 +200,6 @@ export const IntrospectedEditGuesser = ({ mutationMode={mutationMode} redirect={redirectTo} component={viewComponent} - transform={(data: Partial) => ({ - ...data, - extraInformation: { hasFileField }, - })} {...props}> { data: { bar: 'baz', foo: 'foo', - extraInformation: { - hasFileField: true, - }, + }, + meta: { + hasFileField: true, }, }); const url = mockFetchHydra.mock.calls?.[0]?.[0] ?? new URL('https://foo'); @@ -360,9 +360,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 3ece47db..55479610 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';