Skip to content

Clarin9/Save submission immediately when a type/sponsor/author field changes - #1489

Merged
milanmajchrak merged 2 commits into
dtq-dev-9-basefrom
clarin9/submission-save-on-type-change
Sep 3, 2026
Merged

Clarin9/Save submission immediately when a type/sponsor/author field changes#1489
milanmajchrak merged 2 commits into
dtq-dev-9-basefrom
clarin9/submission-save-on-type-change

Conversation

@Kasinhou

Copy link
Copy Markdown

The regression (confirmed live on both dev machines)

In v7 (dev-5), selecting a value in a dropdown that drives type-bind (e.g. the resource type) — or picking a sponsor/author autocomplete value — saved the submission immediately. I verified it live: choosing a resource type fires a PATCH .../workspaceitems/{id} right away, with no need to leave the section.

In v9 (dev-6) this does not happen — the choice is only persisted once the whole section loses focus (i.e. when you click into another section). If the user picks a type and then leaves/loses the session, the choice is lost.

Root cause

The CLARIN logic in SubmissionSectionFormComponent.onChange was not propagated in the DSpace 9 upgrade. v7 (dtq-dev) had:

[...this.typeFields.values()].some(typeValue => {
  if (typeValue.replace('_', '.') === metadata) {
    this.dispatchFormSaveAndReinitialize(typeValue, value); // -> dispatchSaveSection + reinit
    return true;
  }
});
if ([SPONSOR_METADATA_NAME, AUTHOR_METADATA_FIELD_NAME].includes(metadata)) {
  this.dispatchFormSaveAndReinitialize(metadata, value);
}

v9's onChange only kept the (disabled-by-default) autosave.metadata check — none of the type/sponsor/author handling.

Fix

Restore the immediate save in onChange for type-bind controlling fields and the sponsor/author fields.

  • form-builder.service.ts — new getTypeFieldValues() accessor. In v9 the type-bind field map moved into FormBuilderService (populated from submit.type-bind.field), so the component reads the controlling field names from there instead of maintaining its own copy (as v7 did).
  • section-form.component.ts — in onChange, when the changed field is a type-bind controlling field (e.g. dc.type, edm.type) or local.sponsor / dc.contributor.author, dispatch dispatchSaveSection immediately.
  • form-builder-service.mock.ts, section-form.component.spec.ts — mock + tests.

Scope note — save vs. reinitialize

v7's dispatchFormSaveAndReinitialize did two things: save the section and reinitialize the form (a 20s DB-polling reinitializeForm that rebuilt the form via ngOnInit). This PR restores the save — the observed regression. The form reconfiguration on type change is already handled reactively in v9 (FormBuilderService.typeBindModelUpdates / registerTypeBindModels), so the old polling reinit is not re-added. If, after testing on a dev deploy, the author/sponsor sub-fields don't refresh with server-computed values the way they did in v7, I'll port that refresh too as a follow-up.

Testing

  • tsc -p tsconfig.app.json --noEmit and tsconfig.spec.json pass (the only spec error is pre-existing in an unrelated file, server-hard-redirect.service.spec.ts).
  • Added unit tests: save fires on dc.type change and on local.sponsor change; does not fire for a regular field.
  • v7 behaviour confirmed live (PATCH on type selection); this change makes v9 do the same. Should be re-verified on a dev deploy.

🤖 Generated with Claude Code

…changes

In the DSpace 9 upgrade, the CLARIN section-form lost the logic that persisted
the submission as soon as a type-bind controlling field (e.g. dc.type) or a
sponsor/author autocomplete value was picked. In v7, selecting such a value in
a dropdown fired an immediate section save (verified live on dev-5: choosing a
resource type triggers a PATCH). In v9 nothing was saved until the whole
section lost focus, so the choice could be lost.

Restore the v7 behaviour in SubmissionSectionFormComponent.onChange: when the
changed field is a type-bind controlling field or the sponsor/author field,
dispatch a section save immediately.

The set of type-bind controlling fields is owned by FormBuilderService in v9
(populated from `submit.type-bind.field`), so expose it via a new
getTypeFieldValues() accessor rather than duplicating the map in the component.
Form reconfiguration on type change is already handled reactively by v9's
type-bind machinery, so only the save is restored here.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Kasinhou
Kasinhou force-pushed the clarin9/submission-save-on-type-change branch from 0837dba to 0447307 Compare August 26, 2026 13:43
@Kasinhou
Kasinhou requested a lite review from Copilot September 1, 2026 11:41

Copilot AI left a comment

Copy link
Copy Markdown

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 restores DSpace 7 / CLARIN behavior in the Angular v9 submission UI by triggering an immediate section save when key “type-bind controlling” dropdowns and sponsor/author autocompletes change, preventing user selections from being lost before leaving the section.

Changes:

  • Add FormBuilderService.getTypeFieldValues() accessor to expose type-bind controlling field ids from submit.type-bind.field.
  • Update SubmissionSectionFormComponent.onChange to immediately dispatchSaveSection when a type-bind controlling field or sponsor/author field changes.
  • Extend mocks and add unit tests verifying immediate save behavior for type-bind fields and sponsor fields.

Reviewed changes

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

File Description
src/app/submission/sections/form/section-form.component.ts Triggers immediate section save on type-bind controlling fields and sponsor/author changes.
src/app/submission/sections/form/section-form.component.spec.ts Adds unit tests for the new immediate-save triggers.
src/app/shared/mocks/form-builder-service.mock.ts Updates the FormBuilderService mock to support getTypeFieldValues().
src/app/shared/form/builder/form-builder.service.ts Adds getTypeFieldValues() accessor for type-bind controlling fields.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/app/submission/sections/form/section-form.component.ts Outdated
Convert metadata to underscore notation instead of replacing only the
first underscore in the field id (addresses Copilot review).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Kasinhou Kasinhou self-assigned this Sep 1, 2026
@Kasinhou
Kasinhou requested review from milanmajchrak and removed request for milanmajchrak September 2, 2026 14:50
@milanmajchrak
milanmajchrak merged commit 10a4e27 into dtq-dev-9-base Sep 3, 2026
9 checks passed
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.

3 participants