Skip to content

fix(#7594): edit reports without duplicating their extra docs#11114

Open
benkags wants to merge 8 commits into
medic:masterfrom
benkags:7594-edit-reports-extra-docs
Open

fix(#7594): edit reports without duplicating their extra docs#11114
benkags wants to merge 8 commits into
medic:masterfrom
benkags:7594-edit-reports-extra-docs

Conversation

@benkags
Copy link
Copy Markdown
Contributor

@benkags benkags commented May 26, 2026

Description

Editing a report created with db-doc="true" extra-document sections used to duplicate every extra doc on each save. This PR fixes the duplication and adds a policy that lets form authors choose how extra docs behave on edit.

  • Each db-doc child's id is now written into a direct <_id> node inside its section, so it serialises into doc.fields and recovered on edit.
  • db-doc-edit attribute. New attribute link | readonly lets the form author declare intent, with a safe type-based default: non-contacts default to link (the report owns the data), contacts to readonly (they have their own editor). Authored via an instance::db-doc-edit XLSForm column — no cht-conf change needed.
  • Only the fields the parent user changed this edit are overlaid onto the CouchDB document - independent edits and transition-added fields are preserved.

Fixes #7594

Code review checklist

  • Readable: Concise, well named, follows the style guide
  • Documented: Configuration and user documentation on cht-docs — pending a follow-up PR on cht-docs for the db-doc-edit XLSForm authoring guidance.
  • Tested: Unit (karma) coverage in enketo.service.spec.ts (links/readonly/recreate, repeat-matched ids, per-field merge, attachment overlay), form.service.spec.ts and reports-add.component.spec.ts; the existing pregnancy-complete-a-delivery.wdio-spec.js e2e is updated to assert ids are reused on edit.
  • Backwards compatible: Existing reports without a stored <_id> still work — their first edit duplicates once (no id to recover yet), then stabilises on subsequent edits. No migration. recreate reproduces the pre-fix behaviour exactly for forms that want it.
  • AI disclosure: Claude Code to navigate the code base and bootstrap initial version as per spec in Editing a report that created extra docs duplicates all extra docs #7594

@benkags benkags force-pushed the 7594-edit-reports-extra-docs branch from b2b1f02 to 3e2b1e2 Compare May 26, 2026 13:09
Comment thread webapp/src/ts/services/enketo.service.ts Fixed
@benkags benkags force-pushed the 7594-edit-reports-extra-docs branch from 3e2b1e2 to 624b437 Compare May 26, 2026 13:19
this.applyChangedFields(target[key], next[key], prev[key]);
return;
}
target[key] = _cloneDeep(next[key]);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

benkags added 7 commits May 26, 2026 16:28
…g them

Persist each db-doc child id into <_id> and recover it on edit from the previous fields; add a db-doc-edit attribute (link|readonly|recreate) with a type-based default.
…ence

Overlay only the fields the parent user changed onto the live linked doc, and surface diverged fields via an out-accumulator the component folds into its post-save snackbar.
Add /local/ to .gitignore so personal scratch files do not appear in git status.
Remove the divergence notification and its plumbing (interface, accumulator, snackbar key, helpers); the per-field merge still preserves independent edits silently.
…c child

Stop reserving _attachments; merge them last-writer-wins per name so binary uploads on linked children reach the child doc instead of being silently dropped.
Remove the legacy `recreate` option (mint a new child every save) from DbDocEdit; unknown attribute values now fall back to the type-based default with a console warn.
@benkags benkags force-pushed the 7594-edit-reports-extra-docs branch from 624b437 to aeaf3c1 Compare May 26, 2026 13:29
@benkags
Copy link
Copy Markdown
Contributor Author

benkags commented May 26, 2026

@dianabarsan @jkuester this is ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Editing a report that created extra docs duplicates all extra docs

2 participants