SimpleFormIterator issue when editing resources
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- react, typescript
- Domain
- frontend
Research direction
Start with the linked reproduction repository and its pwa/components/Admin.tsx file, especially the dirtyFix transform on the Edit element. Reproduce the Author edit flow by adding a Book through SimpleFormIterator and inspect the saved array for empty @id and @type values. Done means the new nested Book can be saved without the “No resource associated to ""” error.
Written by the indexing model from the issue text.
Description
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 !
- 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
-
clawsweeper:linked-pr-open clawsweeper:no-new-fix-pr clawsweeper:source-repro impact:message-loss issue-rating: 🦞 diamond lobster maturity:stable P2
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#616 ·
-
ZCode 3.14.3 に対応する Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
supermomonga/zcode-acp#24 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
growthbook/growthbook#7100 ·
-
triage
Difficulty 1/5 1-3 hours Newbie friendliness 88/100