`params.previousData` is undefined in `update` call with `hydraDataProvider`
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 30/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- react, typescript
Research direction
Start at the hydraDataProvider update call and the custom update override shown in the reproduction, then trace how the save action supplies params.data and params.previousData. Reproduce the edit flow and determine why previousData is absent; done means the cause and expected behavior are established, with a regression check or clear documentation of the supported update parameters.
Written by the indexing model from the issue text.
Description
API Platform version(s) affected: 3.4.4
Description
We need to use PATCH instead of PUT to update existing resources, so I drew inspiration from this comment https://github.com/api-platform/admin/issues/370#issuecomment-831749350 and overwrote the update method of our data provider, which is an instance of hydraDataProvider.
The new update method should create a diff between the current resource data (given in params.data) and the previous data (given in params.previousData) and then execute a PATCH request.
However, params.previousData is undefined when a user edits a resource and clicks the save button.
I figured it may be caused by some previous error on the page where this behavior occurs, but there are no errors in the JavaScript console on that page. The first error that occurs is that params.previousData is undefined when our diff function is called.
We haven't added much custom logic to our admin implementation, most things are done by the default implementations and automations of API Platform Admin.
What could cause this issue? Is params.previousData supposed to be empty?
How to reproduce
// We use the built-in fetchHydra() and parseHydraDocumentation() functions,
// but wrapped them to handle authorization as shown in the API Platform Admin docs and examples
const baseDataProvider = hydraDataProvider({
entrypoint: ENTRYPOINT,
httpClient: fetchHydraWithAuthentication,
apiDocumentationParser: apiDocumentationParser
});
baseDataProvider.update = function(resource, params) {
return this.httpClient(`${this.entrypoint}/${resource}/${params.id}`, {
method: 'PATCH',
body: JSON.stringify(diff(params.data, params.previousData)),
}).then(({json}) => ({data: json}));
};
// We use lodash helpers to implement this diff function
const diff = (object, base) => {
return transform(object, (result, value, key) => {
if (!isEqual(value, base[key])) {
result[key] = isObject(value) && isObject(base[key]) ? diff(value, base[key]) : value;
}
});
};
- Dominant language
- TypeScript
- Stars
- 516
- Forks
- 134
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from api-platform/admin
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
api-platform/admin#616 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 64/100
api-platform/admin#660 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 50/100
api-platform/admin#659 · 1 reaction ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
api-platform/admin#631 · 6 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
api-platform/admin#626 · 1 comment · 1 reaction ·
All issues in api-platform/admin
Similar issues
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
dennys-bd/agent-hive#184 ·
-
Add: hunch Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
AbdelStark/awesome-typesafe#104 ·
-
ai-observability bug team/ai-observability
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
vicharanashala/fln#563 ·