Skip to content

stabilize form array reorder/delete behavior#120

Merged
kosarko merged 3 commits intoclarin-v7from
118-form-array-items-reappear-after-deletion-due-to-stale-index-cache
Mar 26, 2026
Merged

stabilize form array reorder/delete behavior#120
kosarko merged 3 commits intoclarin-v7from
118-form-array-items-reappear-after-deletion-due-to-stale-index-cache

Conversation

@amadulhaxxani
Copy link
Copy Markdown

synchronize FormArray controls with model on reorder, dedupe patch operations by latest op+path, and fix place handling for index 0 to prevent deleted or duplicate values reappearing after save.

Problem description

Issue #118 caused repeatable form array values to behave inconsistently after reorder/delete flows. Users could see deleted values reappear or duplicate values persist after save because model row order, FormArray control order, and generated patch operations could diverge.

Analysis

The fix addresses three root causes:

  • Reorder path now moves FormArray controls and model groups together, so index mapping stays consistent during drag/keyboard reordering and follow-up edits/deletes.
  • Patch deduplication now keeps the latest operation per op+path globally (not only adjacent duplicates), preventing stale duplicate operations from being sent in one PATCH cycle.
  • Metadata value normalization now preserves place = 0 correctly for object-valued entries, avoiding incorrect fallback to stale place values.

Copilot review

  • Requested review from Copilot

synchronize FormArray controls with model on reorder, dedupe patch operations by latest op+path, and fix place handling for index 0 to prevent deleted or duplicate values reappearing after save.
Copilot AI review requested due to automatic review settings March 25, 2026 09:35
@amadulhaxxani amadulhaxxani linked an issue Mar 25, 2026 that may be closed by this pull request
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to stabilize repeatable (FormArray-backed) submission form fields by keeping Angular FormArray controls aligned with their corresponding model groups during reorder/delete flows, reducing stale/duplicate JSON Patch operations, and correctly preserving place = 0 when normalizing metadata values.

Changes:

  • Align drag/keyboard reorder logic to move both the DynamicRowArrayModel groups and the underlying FormArray controls together, removing the stale startingIndex mapping.
  • Change JSON Patch operation deduplication to keep only the latest operation per op+path across the whole patch list.
  • Fix metadata normalization so object-valued array entries correctly keep place = 0 (instead of falling back to a stale place).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/app/shared/form/builder/form-builder.service.ts Fixes place derivation so index 0 is preserved for object-valued array entries.
src/app/shared/form/builder/form-builder.service.spec.ts Adds a regression test ensuring place = 0 is preserved for object-valued fields in arrays.
src/app/shared/form/builder/ds-dynamic-form-ui/models/array-group/dynamic-form-array.component.ts Reorder now uses FormBuilderService.moveFormArrayGroup and drops startingIndex caching so controls/model stay aligned.
src/app/shared/form/builder/ds-dynamic-form-ui/models/array-group/dynamic-form-array.component.spec.ts Adds coverage verifying reorder moves both model groups and FormArray controls together.
src/app/core/json-patch/json-patch-operations.reducer.ts Updates patch dedupe to keep the latest op per op+path globally.
src/app/core/json-patch/json-patch-operations.reducer.spec.ts Updates expectations to match the new “latest op wins” dedupe behavior.

Document dedupe behavior for json-patch ops
Simplify array index presence check
@kosarko kosarko merged commit b261513 into clarin-v7 Mar 26, 2026
5 checks passed
@port-pr
Copy link
Copy Markdown

port-pr bot commented Mar 26, 2026

Backport branch created but failed to create PR.
Request to create PR rejected with status 403.

Please create the PR manually:

Or via GitHub CLI:

gh pr create --repo dataquest-dev/dspace-angular --base dtq-dev --head ufal:backport-120-to-dtq-dev --title "[Port dtq-dev] stabilize form array reorder/delete behavior" --body "Port of #120 by @amadulhaxxani to `dtq-dev`."

(see action log for full error response)

port-pr bot pushed a commit that referenced this pull request Mar 26, 2026
* stabilize form array reorder/delete behavior

synchronize FormArray controls with model on reorder, dedupe patch operations by latest op+path, and fix place handling for index 0 to prevent deleted or duplicate values reappearing after save.

* Document dedupe behavior for json-patch ops

Document dedupe behavior for json-patch ops

* Simplify array index presence check

Simplify array index presence check

(cherry picked from commit b261513)
milanmajchrak pushed a commit to dataquest-dev/dspace-angular that referenced this pull request Mar 27, 2026
* stabilize form array reorder/delete behavior

synchronize FormArray controls with model on reorder, dedupe patch operations by latest op+path, and fix place handling for index 0 to prevent deleted or duplicate values reappearing after save.

* Document dedupe behavior for json-patch ops

Document dedupe behavior for json-patch ops

* Simplify array index presence check

Simplify array index presence check

(cherry picked from commit b261513)

Co-authored-by: Amad Ul Hassan <hassan@ufal.mff.cuni.cz>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Form array items reappear after deletion due to stale index cache

4 participants