Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow number options with monotonic validation #12726

Merged
merged 8 commits into from
Mar 27, 2024

Conversation

dannykopping
Copy link
Contributor

@dannykopping dannykopping commented Mar 22, 2024

Fixes #11579

NOTE: terraform-provider-coder was updated to facilitate this change, and your template will require v0.19.0 for this feature to work. You can run terraform init -upgrade in your template directory. If you have a version constraint set, ensure it points to this version.

This PR just does some light refactoring / cleanup; the real work was done in coder/terraform-provider-coder#202.

Initially we planned to extend validation in both the browser & CLI UIs, but we agreed to defer this until #7099 is implemented which would centralise all the logic. Right now the UIs don't validate the monotonicity before submit, but there is still backend validation of course.

Here's an example of how to use the new functionality:

data "coder_parameter" "home_volume_size" {
  name        = "Home Volume Size"
  description = <<-EOF
  How large should your home volume be?
  EOF
  type        = "number"
  default     = 30
  mutable     = true
  order       = 3

  option {
    name  = "30GB"
    value = 30
  }

  option {
    name  = "60GB"
    value = 60
  }

  option {
    name  = "100GB"
    value = 100
  }

  validation {
    monotonic = "increasing"
  }
}

Examples:

image

image

Signed-off-by: Danny Kopping <danny@coder.com>
Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

Initially we planned to extend validation in both the browser & CLI UIs

I don't remember now if CLI supports validation of monotonicity. As long as it uses codersdk.ValidateWorkspaceBuildParameters, it should be supported. Maybe drop another CLI test to verify the behavior?

, but we agreed to defer this until #7099 is implemented which would centralise all the logic.

Since validation might work well on the CLI, I'm wondering if it isn't a low hanging fruit to come up with a temporary fix for the frontend. I'm unsure how frontend deals with monotonicity right now.

codersdk/templateversions.go Outdated Show resolved Hide resolved
@dannykopping
Copy link
Contributor Author

dannykopping commented Mar 22, 2024

Initially we planned to extend validation in both the browser & CLI UIs

I don't remember now if CLI supports validation of monotonicity. As long as it uses codersdk.ValidateWorkspaceBuildParameters, it should be supported. Maybe drop another CLI test to verify the behavior?

The CLI doesn't seem to have any client-side validation for options that I can see. The survey lib which powers the options selector exposes a WithValidator hook which we could implement?

, but we agreed to defer this until #7099 is implemented which would centralise all the logic.

Since validation might work well on the CLI, I'm wondering if it isn't a low hanging fruit to come up with a temporary fix for the frontend. I'm unsure how frontend deals with monotonicity right now.

Frontend validation can work but it's not possible to display the error inline with the RadioGroup component according to @BrunoQuaresma.

Signed-off-by: Danny Kopping <danny@coder.com>
@mtojek
Copy link
Member

mtojek commented Mar 22, 2024

The CLI doesn't seem to have any client-side validation for options that I can see. The survey lib which powers the options selector exposes a WithValidator hook which we could implement?

AFAIR There were some problems with testing select input as survey always picked the first item on the list, hence no tests were implemented.

Anyway, if CLI and UI depend on backend validation here, then user will be warned about value conflict. If you want to try, you can modify cli/update_test.go to address the monotonicity use case, but I'm also cool if it is hard/impossible to do 👍

@dannykopping
Copy link
Contributor Author

cli/update_test.go

Will do, thanks!

@dannykopping
Copy link
Contributor Author

cli/update_test.go

Will do, thanks!

@mtojek I added a test in aae5463, PTAL?

I also updated the provider now that coder/terraform-provider-coder#202 is merged.

cli/update_test.go Outdated Show resolved Hide resolved
cli/update_test.go Outdated Show resolved Hide resolved
Signed-off-by: Danny Kopping <danny@coder.com>
Signed-off-by: Danny Kopping <danny@coder.com>
Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

One nit pick to clarify (restart or update) but otherwise it is 👍 .

cli/update_test.go Outdated Show resolved Hide resolved
Signed-off-by: Danny Kopping <danny@coder.com>
@dannykopping dannykopping enabled auto-merge (squash) March 27, 2024 08:34
@dannykopping dannykopping merged commit a74ef40 into coder:main Mar 27, 2024
23 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2024
@dannykopping dannykopping deleted the dk/monotonic branch March 27, 2024 08:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

coder_parameter doesn't support monotonic for option values
2 participants