fix: improve 'move' handling of controls in form array#4763
Conversation
- Refactored control retrieval logic by replacing `getControlOfGroup` with direct use of `control.get` without using a startingIndex - Added `moveFormControlToPosition` method to handle control positioning during drag-and-drop operations. Ensured controls remain correctly linked to their respective groups
|
I have tested, it worked for me. pr_4763.mp4 |
|
Temporarily closing & reopening to trigger tests to rerun. This PR never seems to have run the tests for Node 22. |
lgeggleston
left a comment
There was a problem hiding this comment.
+1, looks good to me as well! (Note: Test and not a full code review).
Confirmed the main fix of not re-ordering on a save, with several different repeatable fields (Other titles, Type, Author). The order remains consistent after archiving the item as well. Tried some random edits to repeatable fields and did not see regressions.
tdonohue
left a comment
There was a problem hiding this comment.
👍 Thanks @jlipka ! With your instructions in this PR, I was able to reproduce the bug on Sandbox. I've verified this fixes the bug. I did some of my own complex reordering of values and couldn't find a way to break anything anymore. So, I'm not seeing any regression issues either. Code looks good too!
|
Backport failed for Please cherry-pick the changes locally and resolve any conflicts. git fetch origin dspace-7_x
git worktree add -d .worktree/backport-4763-to-dspace-7_x origin/dspace-7_x
cd .worktree/backport-4763-to-dspace-7_x
git switch --create backport-4763-to-dspace-7_x
git cherry-pick -x e7212843e988b2c2f6ddcfd31f2d16560192b348 |
|
Backport failed for Please cherry-pick the changes locally and resolve any conflicts. git fetch origin dspace-8_x
git worktree add -d .worktree/backport-4763-to-dspace-8_x origin/dspace-8_x
cd .worktree/backport-4763-to-dspace-8_x
git switch --create backport-4763-to-dspace-8_x
git cherry-pick -x e7212843e988b2c2f6ddcfd31f2d16560192b348 |
|
Successfully created backport PR for |
|
@jlipka : This was only able to be auto-backported to 9.x. However, that's all we require for bug fixes (we only require backports to the latest major version). If you (or anyone else) would like to see this fix in earlier releases (8.x or 7.x), please create a separate backport PR against the |
References
Description
If a form element is repeatable, the values in the form array will no longer become disorganised when items are moved or deleted from the list in multiple operations. Each individual operation does not necessarily cause a problem, but if one operation is performed after another, the final values may not be correctly sent to the backend due to wrong values used in the form-array.
Instructions for Reviewers / Steps to reproduce
Create a list of six items in a repeatable form control field, e.g. "Other titles". Enter values from 1 to 6. Now, move the last item (value: 6) to second place. Remove this moved item (from the second place). Move the new last item (value: 5) to the first place, then move the item with the "value: 4" to the first place, followed by pressing (the first time) the Save button. Check the corresponding PATCH request as also the form itself for the correct values and their sorting order. To double-check the correct data, hard-reload the submission to verify the values and their order are still right. The result should look like "4, 5, 1, 2, 3".
Before this patch, the result after pressing the Save button was: "5, 6, 1, 3 ,4" - in the PATCH request payload, as well in the form itself after the request was processed. This behaviour ist reproducable on the demo.dspace.org and sandbox.dspace.org pages using a workspace or workflow item.
To ensure that no new errors are introduced, I would be grateful if the reviewer(s) could carry out a few checks. For example, could you check that repeatable fields with controlled vocabularies are also still saved correctly alongside regular input fields, and that relationships between entities within a list are still saved the right way.
List of changes in this PR:
getControlOfGroupwith direct use ofcontrol.getand using the regular index instead of startingIndexmoveFormControlToPositionmethod to handle control positioning during drag-and-drop operations. Ensured controls remain correctly linked to their respective groupsChecklist
mainbranch of code (unless it is a backport or is fixing an issue specific to an older branch).npm run lintnpm run check-circ-deps)package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.