api-platform / admin

A beautiful and fully-featured administration interface builder for hypermedia APIs
https://api-platform.com/docs/admin/
MIT License
483 stars 131 forks source link

Not Found error is shown when deleting items from edit view #363

Closed zoundfreak closed 3 years ago

zoundfreak commented 3 years ago

API Platform version(s) affected 2.6.1 (standard distribution) with 2.5.8 admin

Description
When I delete any item from the edit view by clicking the delete button, the following happens:

For example deleting a book (following the APIP setup guide examples) with id 6, a DELETE request is sent to https://localhost/books/6. That request gets 204 as a response code with empty response body.

Right after the previous request a new GET request is now sent to https://localhost/books/6. Now the book with id 6 doesn't exist anymore and the request gets a 404 response, which in turn is shown in the UI.

NOTE: This only happens when deleting items by clicking the delete button. Deleting directly from the listing works fine.

I tried this with both a fresh install of the latest standard distribution and custom built apps with the same versions. I've tried setting undoable to both true and false.

This causes two kinds of problems for me:

  1. Annoying error messages
  2. Automatic redirection to a wrong page when I have a custom redirection path set for delete success

I need to release my application in the coming days and this is a huge show stopper. I cannot figure out a way to fix this myself.

How to reproduce

  1. Install the latest standard distribution following the instructions on the APIP get started manual.
  2. Create any entity and set it as ApiResource (like Book and Review in the example).
  3. Go to admin UI and create a new instance
  4. Go to the edit page of the created instance
  5. Press delete button to delete the instance

Possible Solution
To my understanding, React Admin expects DELETE to return the deleted instance back. Currently nothing is returned. Could this be the reason for the extra request?

zoundfreak commented 3 years ago

Could the following promise in the hydra data provider cause this issue? The data content id is set to null.

https://github.com/api-platform/admin/blob/3e15a384c924e664e9fafd8c64c281bee202328a/src/hydra/dataProvider.js#L429

React Admin documentation states:

Data Providers methods must return a Promise for an object with a data property.

delete => { data: {Record} } The record that has been deleted

A {Record} is an object literal with at least an id property, e.g. { id: 123, title: "hello, world" }.

The documentation can be found here:

https://marmelab.com/react-admin/doc/3.6/DataProviders.html#response-format

alanpoulain commented 3 years ago

Hello. That was not the right fix, but it's a good thing anyway, so I've done it in this PR: https://github.com/api-platform/admin/pull/365. For your issue, it will be fixed in the next release.

zoundfreak commented 3 years ago

Nice! Good to know!