Skip to content

Commit 6f500ca

Browse files
authored
Merge pull request #108 from coder/jaaydenh/parameter-styling-type
chore: add type for ParameterStyling
2 parents bfd58e2 + 87fe1cd commit 6f500ca

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

extract/parameter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func ParameterFromBlock(block *terraform.Block) (*types.Parameter, hcl.Diagnosti
5757
}
5858

5959
ftmeta := optionalString(block, "styling")
60-
formTypeMeta := make(map[string]any)
60+
var formTypeMeta types.ParameterStyling
6161
if ftmeta != "" {
6262
_ = json.Unmarshal([]byte(ftmeta), &formTypeMeta)
6363
}

extract/state.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ func ParameterFromState(block *tfjson.StateResource) (types.Parameter, error) {
5454
}
5555

5656
ftmeta := st.optionalString("styling")
57-
var formTypeMeta any
57+
var formTypeMeta types.ParameterStyling
5858
if ftmeta != "" {
5959
_ = json.Unmarshal([]byte(ftmeta), &formTypeMeta)
6060
} else {
61-
formTypeMeta = map[string]any{}
61+
formTypeMeta = types.ParameterStyling{}
6262
}
6363

6464
param := types.Parameter{

site/src/types/preview.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ export interface ParameterData {
3535
readonly type: ParameterType;
3636
// this is likely an enum in an external package "github.com/coder/terraform-provider-coder/v2/provider.ParameterFormType"
3737
readonly form_type: string;
38-
// empty interface{} type, falling back to unknown
39-
readonly styling: unknown;
38+
readonly styling: ParameterStyling;
4039
readonly mutable: boolean;
4140
readonly default_value: NullHCLString;
4241
readonly icon: string;
@@ -55,6 +54,13 @@ export interface ParameterOption {
5554
readonly icon: string;
5655
}
5756

57+
// From types/parameter.go
58+
export interface ParameterStyling {
59+
readonly placeholder?: string;
60+
readonly disabled?: boolean;
61+
readonly label?: string;
62+
}
63+
5864
// From types/enum.go
5965
export type ParameterType = "bool" | "list(string)" | "number" | "string";
6066

types/parameter.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type ParameterData struct {
5050
Description string `json:"description"`
5151
Type ParameterType `json:"type"`
5252
FormType provider.ParameterFormType `json:"form_type"`
53-
Styling any `json:"styling"`
53+
Styling ParameterStyling `json:"styling"`
5454
Mutable bool `json:"mutable"`
5555
DefaultValue HCLString `json:"default_value"`
5656
Icon string `json:"icon"`
@@ -76,6 +76,12 @@ type ParameterValidation struct {
7676
Invalid *bool `json:"validation_invalid"`
7777
}
7878

79+
type ParameterStyling struct {
80+
Placeholder *string `json:"placeholder,omitempty"`
81+
Disabled *bool `json:"disabled,omitempty"`
82+
Label *string `json:"label,omitempty"`
83+
}
84+
7985
// Valid takes the type of the value and the value itself and returns an error
8086
// if the value is invalid.
8187
func (v ParameterValidation) Valid(typ string, value string) error {

0 commit comments

Comments
 (0)