Planner research facilities: inline use validation (#2653)¶
Symptom¶
In a Project Grant, adding a research-facility platform whose metric is %
and typing a planned use above 100 raised the red toast
"Invalid item_data for creation: 1 validation error for
ResearchFacilitiesCommonHandlerCreate … use must be at most 100 when the
unit is '%' …" plus "Could not save the platform use". The user asked for a
plain "the maximum is 100%" message; the maintainer's call was to validate
on the frontend side.
Root cause¶
PlannerResearchFacilityRows.vue saved on blur with no :rules on the
use input. The Calculator form already mirrors the backend use_bounds()
table through the conditionalBounds config on the use field
(module-config/research-facilities.ts, #2007), but the Planner grid
bypassed ModuleForm and therefore that mirror. The backend's
validate_use_within_unit_bounds was the only guard, and its message is an
internal one.
Fix¶
frontend/src/constant/module-config/research-facilities.ts: the two identicalconditionalBoundsliterals become one exportedUSE_BOUNDSconstant, so the Planner reads the same table as the Calculator form.frontend/src/utils/numeric-rules.ts:getNumericRulesacceptsinteger: trueand emits the existingvalidation_must_be_whole_numbermessage, matching whatModuleForm.getBoundsenforces.frontend/src/utils/researchFacilityRows.ts:researchFacilityUseRules(metric, bounds, t)builds the q-input rules for one row from its metric:min 0, the unit'smaxwhen it has one, whole numbers for housings.frontend/src/components/organisms/planner/PlannerResearchFacilityRows.vue: each row's input carries:rules="rulesFor(row)"(memoised per metric), andpersist()returns before any request when a rule fails. The inline message is the sharedvalidation_must_be_at_most("Must be at most 100" / "Doit être au plus 100"), the same wording the Calculator form shows.
No backend change: the server-side check stays as the fail-closed guard.
Tests¶
frontend/tests/unit/researchFacilityRows.spec.ts gains four cases on
researchFacilityUseRules: 150 % refused / 100 % accepted, a negative use
refused, a unit without a ceiling (CHF) accepting 20000, and housings
requiring whole numbers.