- Notifications
You must be signed in to change notification settings - Fork1.1k
Description
Problem
When updating workspace parameters in the Workspace Settings page, monotonic validation (forvalidation_monotonic = "increasing" or"decreasing") is not enforced in the UI. Users can enter values that violate monotonic constraints, and the error only appears after clicking "Submit and restart" and the backend rejects it.
Root Cause
TheWorkspaceParametersForm component does not pass thelastBuildParameters to the validation schema:
validationSchema:Yup.object({rich_parameter_values:useValidationSchemaForRichParameters(templateVersionRichParameters,// Missing second argument: lastBuildParameters),}),
TheuseValidationSchemaForRichParameters function signature accepts a second parameter for previous values:
https://github.com/coder/coder/blob/main/site/src/utils/richParameters.ts#L56-L58
exportconstuseValidationSchemaForRichParameters=(templateParameters?:TemplateVersionParameter[],lastBuildParameters?:WorkspaceBuildParameter[],// Not being passed!):Yup.AnySchema=>{
WithoutlastBuildParameters, the monotonic validation logic at lines 120-147 never runs.
Expected Behavior
For a parameter defined as:
data"coder_parameter""custom_value" {name="custom_value"display_name="Custom Value"default="1000"type="number"mutable=truevalidation {monotonic="increasing"min=500max=2000 }}
If the previous build hadcustom_value = 1500, the UI should:
- Show a validation error if the user enters a value less than 1500
- Display: "Value must only ever increase (last value was 1500)"
- Prevent form submission until a valid value is entered
Actual Behavior
The UI allows any value between 500-2000 to be entered. The error only appears after submitting when the backend/Terraform provider rejects it.
Solution
PassautofillParams (which contains the previous build parameters) as the second argument:
validationSchema:Yup.object({rich_parameter_values:useValidationSchemaForRichParameters(templateVersionRichParameters,autofillParams,// Add this!),}),
This will enable the frontend Yup validation to check monotonic constraints before submission.
Related
- IssueDynamic parameters to respect
monotonicvalidation #19064 - Dynamic parameters to respect monotonic validation (backend preview validation) - The HTML
min/maxattributes are set correctly on the input element, but browsers don't strictly enforce these on text inputs during typing