Skip to content

Commit

Permalink
refactor: move extraInformation to meta (#498)
Browse files Browse the repository at this point in the history
* 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 <dracono@wp.pl>
  • Loading branch information
mkg20001 and PawelSuwinski committed Mar 27, 2024
1 parent 9993bf1 commit 4645fb5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/CreateGuesser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ export const IntrospectedCreateGuesser = ({
const response = await create(
resource,
{
data: { ...data, extraInformation: { hasFileField } },
data,
meta: { hasFileField },
},
{ returnPromise: true },
);
Expand Down
7 changes: 2 additions & 5 deletions src/EditGuesser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ export const IntrospectedEditGuesser = ({
resource,
{
id,
data: { ...data, extraInformation: { hasFileField } },
data,
meta: { hasFileField },
},
{ returnPromise: true },
);
Expand Down Expand Up @@ -199,10 +200,6 @@ export const IntrospectedEditGuesser = ({
mutationMode={mutationMode}
redirect={redirectTo}
component={viewComponent}
transform={(data: Partial<RaRecord>) => ({
...data,
extraInformation: { hasFileField },
})}
{...props}>
<FormType
onSubmit={mutationMode !== 'pessimistic' ? undefined : save}
Expand Down
12 changes: 6 additions & 6 deletions src/hydra/dataProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,9 @@ describe('Transform a React Admin request to an Hydra request', () => {
data: {
bar: 'baz',
foo: 'foo',
extraInformation: {
hasFileField: true,
},
},
meta: {
hasFileField: true,
},
});
const url = mockFetchHydra.mock.calls?.[0]?.[0] ?? new URL('https://foo');
Expand Down Expand Up @@ -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',
Expand Down
5 changes: 2 additions & 3 deletions src/hydra/dataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down

0 comments on commit 4645fb5

Please sign in to comment.