Skip to content

feat(editor): datatype-driven scenario parameter inputs#748

Open
tdjager wants to merge 1 commit into
feat/units-validationfrom
feat/scenario-typed-inputs
Open

feat(editor): datatype-driven scenario parameter inputs#748
tdjager wants to merge 1 commit into
feat/units-validationfrom
feat/scenario-typed-inputs

Conversation

@tdjager

@tdjager tdjager commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

Scenario parameter inputs in the editor always rendered as a plain text field, regardless of the parameter's declared datatype — so a boolean was typed as the literal text true, an amount as a raw number, a date as a free-text string.

This adds a generic, datatype-driven control (ScenarioParameterInput.vue) that renders the NDD component matching each parameter's declared datatype:

datatype control
boolean nldd-switch-field (consistent with EditSheet)
number nldd-number-field
amount nldd-number-field, unit-aware
date nldd-text-field type="date"
string nldd-text-field (fallback)

Scenario inputs per datatype

The "Datum" (calculation date) field reuses the same control.

How it works

  • buildTypeMap(articles) (new, sibling of buildArticleMap) resolves each parameter's { type, unit } from the law's execution.parameters / execution.input. ScenarioBuilder threads it into ScenarioForm.
  • The control coerces values to real JS types (boolean / number / string) on the way out; they round-trip cleanly through formMapper / parseValue (verified by test) — no formMapper change needed.
  • Amount is unit-aware. With type_spec.unit: eurocent, the user enters euros and the value is stored as integer eurocents (e.g. 1500001500); with unit: euro or no declared unit it stays a raw number, so we never silently scale a value whose unit we don't know. The euro⇄eurocent math is extracted into utils/currency.js and reused by EditSheet.

Stacked on #729

This builds on #729 (RFC-019, units of measurement), which adds type_spec.unit to parameterField — that's what makes the amount control's unit-awareness real rather than dormant. Base this PR's merge on #729; once #729 lands, rebase onto main.

Parameters without a declared unit fall back to a raw number-field, so un-annotated laws keep working unchanged.

Tests

  • Unit: currency, buildTypeMap, ScenarioParameterInput (control selection + display/emit coercion per type), and a typed formMapper round-trip — all green (247 frontend tests pass).
  • E2E: e2e/scenario-param-inputs.spec.js opens a scenario with a boolean / amount-eurocent / string parameter and asserts each renders the right control (switch checked, number-field showing 1500 euros, text-field).

Custom CSS

None. Only NDD design-system components; no <style> added.

@tdjager tdjager force-pushed the feat/units-validation branch from 0e8a585 to 9ff7bc1 Compare June 4, 2026 15:21
Scenario parameter inputs always rendered as a text field regardless of
the parameter's declared datatype. Add a generic ScenarioParameterInput
control that renders the matching NDD component per datatype:

- boolean -> nldd-switch-field (consistent with EditSheet)
- number  -> nldd-number-field
- amount  -> nldd-number-field, unit-aware (eurocent shows euros / stores
             eurocents via shared currency helpers; otherwise raw number)
- date    -> nldd-text-field type=date
- string  -> nldd-text-field (fallback)

buildTypeMap() resolves each parameter's type+unit from the law's
execution.parameters/input; ScenarioBuilder threads it into ScenarioForm.
Extract centsToEuros/eurosToCents into utils/currency.js (reused by
EditSheet). Values are coerced to real JS types and round-trip cleanly
through formMapper/parseValue.

The calculation-date field reuses the same control.
@tdjager tdjager force-pushed the feat/scenario-typed-inputs branch from 5dca077 to 8f90816 Compare June 4, 2026 15:48
@tdjager tdjager marked this pull request as ready for review June 4, 2026 15:48
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

Preview Deployment — editor — editor

Your changes have been deployed to a preview environment:

URL: https://editor.pr748.rig.prd1.gn2.quattro.rijksapps.nl

This deployment will be automatically cleaned up when the PR is closed.

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.

1 participant