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: form_type and styling metadata arguments added #375

Merged
merged 35 commits into from
Apr 8, 2025

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Apr 3, 2025

This PR is in support of dynamic parameters. Changes to coder/coder intends to support this experimentally by the end of April. For current versions of coder, these arguments will be ignored.

What is this?

This adds form_type as a field to parameters. By default, legacy behavior is maintained by deducing the default form_type value from the existing inputs.

Why do this?

To support more form type options in the UI. See the truth table here of all the new types:

// formTypeTruthTable is a map of [`type`][`optionCount` > 0] to `form_type`.
// The first value in the slice is the default value assuming `form_type` is
// not specified.
//
// The boolean key indicates whether the `options` field is specified.
// | Type | Options | Specified Form Type | form_type | Notes |
// |-------------------|---------|---------------------|----------------|--------------------------------|
// | `string` `number` | Y | | `radio` | |
// | `string` `number` | Y | `dropdown` | `dropdown` | |
// | `string` `number` | N | | `input` | |
// | `string` | N | 'textarea' | `textarea` | |
// | `number` | N | 'slider' | `slider` | min/max validation |
// | `bool` | Y | | `radio` | |
// | `bool` | N | | `checkbox` | |
// | `bool` | N | `switch` | `switch` | |
// | `list(string)` | Y | | `radio` | |
// | `list(string)` | N | | `tag-select` | |
// | `list(string)` | Y | `multi-select` | `multi-select` | Option values will be `string` |

Example new param

data "coder_parameter" "tools" {
  name        = "Tools"
  description = "What tools do you want to install?"
  type        = "list(string)"
  form_type   = "multi-select"
  styling = jsonencode({
    # Arbitrary JSON object to be passed to the frontend
  })
  default = jsonencode(["git", "docker"])

  option {
    value = "Docker"
    name  = "docker"
    icon  = "/icon/docker.svg"
  }
  option {
    value = "Git"
    name  = "git"
    icon  = "/icon/git.svg"
  }
  option {
    value = "Golang"
    name  = "go"
    icon  = "/icon/go.svg"
  }
  option {
    value = "Typescript"
    name  = "ts"
    icon  = "/icon/typescript.svg"
  }
}

Note on docs

I am unable to add more example params to the docs, as they are used in integration tests that seem to use provider versions without this change? I get this error for above:

2025-04-07T18:26:57.1664097Z     examples_test.go:30: Step 1/1 error: Error running pre-apply refresh: exit status 1
2025-04-07T18:26:57.1664830Z         
2025-04-07T18:26:57.1665915Z         Error: default value "[\"git\",\"docker\"]" is not a valid option, values "git, docker" are missing from the option
2025-04-07T18:26:57.1666653Z         
2025-04-07T18:26:57.1667135Z           with data.coder_parameter.tools,
2025-04-07T18:26:57.1668078Z           on terraform_plugin_test.tf line 119, in data "coder_parameter" "tools":
2025-04-07T18:26:57.1668889Z          119: data "coder_parameter" "tools" {

That error is the error you get using this param on the existing terraform provider. Maybe I have to do some skips with past versions. Regardless, I will update the docs when this gets further upstream to a release.

@Emyrk Emyrk changed the title feat: form_type and form_type metadata arguments added feat: form_type and styling metadata arguments added Apr 4, 2025
@Emyrk Emyrk marked this pull request as ready for review April 7, 2025 15:59
@Emyrk Emyrk mentioned this pull request Apr 7, 2025
8 tasks
Emyrk added 2 commits April 7, 2025 14:11
The example needs the release. So it's invalid until we push a
tag
@Emyrk Emyrk requested a review from johnstcn April 7, 2025 19:17
Comment on lines 14 to 15
// The value have to be string literals, as type constraint keywords are not
// supported in providers. :'(
Copy link
Member

Choose a reason for hiding this comment

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

For future readers wishing to understand the source of our woes, it might be good to add some relevant links to existing issues.

Copy link
Member Author

Choose a reason for hiding this comment

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

I actually do not know what to link 🤔.

Comment on lines +37 to +38
// For example, "multi-select" has the type "list(string)" but the option
// values are "string".
Copy link
Member

Choose a reason for hiding this comment

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

Might be good to explicitly document each type + option value for the possible values of ParameterFormType below.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd rather defer that to the truth table below. I do not want to document it in 2 places.

Comment on lines +194 to +198
// TODO: We do this unmarshal in a few spots. It should be standardized.
err = json.Unmarshal([]byte(parameter.Default), &defaultValues)
if err != nil {
return diag.Errorf("default value %q is not a list of strings", parameter.Default)
}
Copy link
Member

Choose a reason for hiding this comment

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

Good spot! 👍

@Emyrk Emyrk requested a review from johnstcn April 8, 2025 13:38
@Emyrk Emyrk merged commit 8804c44 into main Apr 8, 2025
1 check passed
@Emyrk Emyrk deleted the stevenmasley/form_control branch April 8, 2025 18:04
@github-actions github-actions bot locked and limited conversation to collaborators Apr 8, 2025
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.

3 participants