From ccd1012422bceb7dffe7d978619ce71d0d26ecd3 Mon Sep 17 00:00:00 2001 From: Jaayden Halko Date: Tue, 6 May 2025 15:52:50 +0100 Subject: [PATCH 1/2] chore: add type for ParameterStyling --- site/src/types/preview.ts | 10 ++++++++-- types/parameter.go | 8 +++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/site/src/types/preview.ts b/site/src/types/preview.ts index 945c7e1..0d19c4d 100644 --- a/site/src/types/preview.ts +++ b/site/src/types/preview.ts @@ -35,8 +35,7 @@ export interface ParameterData { readonly type: ParameterType; // this is likely an enum in an external package "github.com/coder/terraform-provider-coder/v2/provider.ParameterFormType" readonly form_type: string; - // empty interface{} type, falling back to unknown - readonly styling: unknown; + readonly styling: ParameterStyling; readonly mutable: boolean; readonly default_value: NullHCLString; readonly icon: string; @@ -55,6 +54,13 @@ export interface ParameterOption { readonly icon: string; } +// From types/parameter.go +export interface ParameterStyling { + readonly placeholder?: string; + readonly disabled?: boolean; + readonly label?: string; +} + // From types/enum.go export type ParameterType = "bool" | "list(string)" | "number" | "string"; diff --git a/types/parameter.go b/types/parameter.go index d5fbc67..f1f07b0 100644 --- a/types/parameter.go +++ b/types/parameter.go @@ -50,7 +50,7 @@ type ParameterData struct { Description string `json:"description"` Type ParameterType `json:"type"` FormType provider.ParameterFormType `json:"form_type"` - Styling any `json:"styling"` + Styling ParameterStyling `json:"styling"` Mutable bool `json:"mutable"` DefaultValue HCLString `json:"default_value"` Icon string `json:"icon"` @@ -76,6 +76,12 @@ type ParameterValidation struct { Invalid *bool `json:"validation_invalid"` } +type ParameterStyling struct { + Placeholder *string `json:"placeholder,omitempty"` + Disabled *bool `json:"disabled,omitempty"` + Label *string `json:"label,omitempty"` +} + // Valid takes the type of the value and the value itself and returns an error // if the value is invalid. func (v ParameterValidation) Valid(typ string, value string) error { From 87fe1cd89f5b400821d175427ce030210d00bc37 Mon Sep 17 00:00:00 2001 From: Jaayden Halko Date: Tue, 6 May 2025 16:14:18 +0100 Subject: [PATCH 2/2] chore: update extract logic for parameter styling --- extract/parameter.go | 2 +- extract/state.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/extract/parameter.go b/extract/parameter.go index 6cbd791..198173c 100644 --- a/extract/parameter.go +++ b/extract/parameter.go @@ -57,7 +57,7 @@ func ParameterFromBlock(block *terraform.Block) (*types.Parameter, hcl.Diagnosti } ftmeta := optionalString(block, "styling") - formTypeMeta := make(map[string]any) + var formTypeMeta types.ParameterStyling if ftmeta != "" { _ = json.Unmarshal([]byte(ftmeta), &formTypeMeta) } diff --git a/extract/state.go b/extract/state.go index bb1a942..048ae85 100644 --- a/extract/state.go +++ b/extract/state.go @@ -54,11 +54,11 @@ func ParameterFromState(block *tfjson.StateResource) (types.Parameter, error) { } ftmeta := st.optionalString("styling") - var formTypeMeta any + var formTypeMeta types.ParameterStyling if ftmeta != "" { _ = json.Unmarshal([]byte(ftmeta), &formTypeMeta) } else { - formTypeMeta = map[string]any{} + formTypeMeta = types.ParameterStyling{} } param := types.Parameter{