chore: add form_type parameter argument to db (#17920)

`form_type` is a new parameter field in the terraform provider. Bring
that field into coder/coder.

Validation for `multi-select` has also been added.
This commit is contained in:
Steven Masley
2025-05-29 08:55:19 -05:00
committed by GitHub
parent 776c144128
commit 8387dd27ab
35 changed files with 1556 additions and 822 deletions
+88
View File
@@ -1108,6 +1108,92 @@ func AllParameterDestinationSchemeValues() []ParameterDestinationScheme {
}
}
// Enum set should match the terraform provider set. This is defined as future form_types are not supported, and should be rejected. Always include the empty string for using the default form type.
type ParameterFormType string
const (
ParameterFormTypeValue0 ParameterFormType = ""
ParameterFormTypeError ParameterFormType = "error"
ParameterFormTypeRadio ParameterFormType = "radio"
ParameterFormTypeDropdown ParameterFormType = "dropdown"
ParameterFormTypeInput ParameterFormType = "input"
ParameterFormTypeTextarea ParameterFormType = "textarea"
ParameterFormTypeSlider ParameterFormType = "slider"
ParameterFormTypeCheckbox ParameterFormType = "checkbox"
ParameterFormTypeSwitch ParameterFormType = "switch"
ParameterFormTypeTagSelect ParameterFormType = "tag-select"
ParameterFormTypeMultiSelect ParameterFormType = "multi-select"
)
func (e *ParameterFormType) Scan(src interface{}) error {
switch s := src.(type) {
case []byte:
*e = ParameterFormType(s)
case string:
*e = ParameterFormType(s)
default:
return fmt.Errorf("unsupported scan type for ParameterFormType: %T", src)
}
return nil
}
type NullParameterFormType struct {
ParameterFormType ParameterFormType `json:"parameter_form_type"`
Valid bool `json:"valid"` // Valid is true if ParameterFormType is not NULL
}
// Scan implements the Scanner interface.
func (ns *NullParameterFormType) Scan(value interface{}) error {
if value == nil {
ns.ParameterFormType, ns.Valid = "", false
return nil
}
ns.Valid = true
return ns.ParameterFormType.Scan(value)
}
// Value implements the driver Valuer interface.
func (ns NullParameterFormType) Value() (driver.Value, error) {
if !ns.Valid {
return nil, nil
}
return string(ns.ParameterFormType), nil
}
func (e ParameterFormType) Valid() bool {
switch e {
case ParameterFormTypeValue0,
ParameterFormTypeError,
ParameterFormTypeRadio,
ParameterFormTypeDropdown,
ParameterFormTypeInput,
ParameterFormTypeTextarea,
ParameterFormTypeSlider,
ParameterFormTypeCheckbox,
ParameterFormTypeSwitch,
ParameterFormTypeTagSelect,
ParameterFormTypeMultiSelect:
return true
}
return false
}
func AllParameterFormTypeValues() []ParameterFormType {
return []ParameterFormType{
ParameterFormTypeValue0,
ParameterFormTypeError,
ParameterFormTypeRadio,
ParameterFormTypeDropdown,
ParameterFormTypeInput,
ParameterFormTypeTextarea,
ParameterFormTypeSlider,
ParameterFormTypeCheckbox,
ParameterFormTypeSwitch,
ParameterFormTypeTagSelect,
ParameterFormTypeMultiSelect,
}
}
type ParameterScope string
const (
@@ -3308,6 +3394,8 @@ type TemplateVersionParameter struct {
DisplayOrder int32 `db:"display_order" json:"display_order"`
// The value of an ephemeral parameter will not be preserved between consecutive workspace builds.
Ephemeral bool `db:"ephemeral" json:"ephemeral"`
// Specify what form_type should be used to render the parameter in the UI. Unsupported values are rejected.
FormType ParameterFormType `db:"form_type" json:"form_type"`
}
type TemplateVersionPreset struct {