Skip to content

Commit

Permalink
refactor: move extraInformation to meta
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mkg20001 committed Feb 24, 2023
1 parent 33e47fa commit a03c484
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/CreateGuesser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ export const IntrospectedCreateGuesser = ({
const response = await create(
resource,
{
data: { ...data, extraInformation: { hasFileField } },
data,
meta: { hasFileField },
},
{ returnPromise: true },
);
Expand Down
5 changes: 3 additions & 2 deletions src/EditGuesser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ export const IntrospectedEditGuesser = ({
resource,
{
id,
data: { ...data, extraInformation: { hasFileField } },
data,
meta: { hasFileField },
},
{ returnPromise: true },
);
Expand Down Expand Up @@ -197,7 +198,7 @@ export const IntrospectedEditGuesser = ({
id={id}
mutationMode={mutationMode}
redirect={redirectTo}
transform={(data) => ({ ...data, extraInformation: { hasFileField } })}
transform={(data) => data}
{...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 @@ -265,9 +265,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 @@ -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',
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 a03c484

Please sign in to comment.