SimpleFormIterator issue when editing resources
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- react, typescript
- Ambito
- frontend
Direzione di ricerca
Inizia dal repository di riproduzione collegato e dal suo file pwa/components/Admin.tsx, in particolare dalla trasformazione dirtyFix sull’elemento Edit. Riproduci il flusso di modifica di Author aggiungendo un Book tramite SimpleFormIterator e controlla l’array salvato alla ricerca di valori @id e @type vuoti. Il lavoro è completato quando il nuovo Book annidato può essere salvato senza l’errore “No resource associated to ""”.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
API Platform version(s) affected: 3.0.2 (also 2.6.8 with last Admin version)
Description
Since react-admin 4.4+, I am not able to dynamically create sub-elements when editing a resource. Let's say I have Book and Author resources, you can create books from the Author edit page thanks to an ArrayInput and a SimpleFormIterator. When I tried to add Books to an Author with the Author edit page, the following error occurred : No resource associated to "".
How to reproduce
Here is an example repo to reproduce my issue : https://github.com/gaspardphilibert/issue-api-platform-admin-simpleformiterator. To experience the bug, you can create an Author with one Book, then edit the Author and try to add another Book. You shouldn't be able to add the second Book.
The reason
Version 4.4.0 of react-admin fixes an issue (https://github.com/marmelab/react-admin/pull/8204) linked to SimpleFormIterator default values when adding a record. It seems that it takes the first array value and reset its fields to make a default value for new elements. Obviously, during the process an empty @id field is also injected. So, when I add a new value in my SimpleFormIterator and save the entity, it sends the array with an item with an empty string @id. Like this for example :
{
"@context": "/contexts/Author",
"@id": "/authors/1",
"@type": "Author",
"name": "Shakespeare",
"books": [
{
"@id": "/books/1",
"@type": "Books",
"name": "Roméo et Juliette"
},
{
"@id": "",
"@type": "",
"name": "Macbeth"
}
],
"id": "/authors/1"
}
Hence the No resource associated to "". error.
Possible Solution
I used the transform property (dirtyFix function in my example repo) on the Edit element to remove the empty @id and it worked well but I am wondering if it's the best solution (I am quite new in the API Platform world, maybe it could be solved at a lower level).
Thanks for your help !
- Lingua principale
- TypeScript
- Stelle
- 516
- Fork
- 134
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di api-platform/admin
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
api-platform/admin#616 · 1 commento ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 64/100
api-platform/admin#660 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 50/100
api-platform/admin#659 · 1 reazione ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
api-platform/admin#631 · 6 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
api-platform/admin#626 · 1 commento · 1 reazione ·
Tutte le issue di api-platform/admin
Issue simili
-
blocklist removal
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
MetaMask/eth-phishing-detect#296544 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
pastelsky/bundlephobia#1122 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
category/development priority/P2 scope/file-operations scope/testing type/enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Enatega Customer and Rider app: Add-ons price is not visible to customer after order is placed. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100