Thanks to visit codestin.com
Credit goes to github.com

Skip to content

chore: add type for ParameterStyling #108

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

Merged
merged 2 commits into from
May 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion extract/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions extract/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
10 changes: 8 additions & 2 deletions site/src/types/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";

Expand Down
8 changes: 7 additions & 1 deletion types/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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"`
Copy link
Member

Choose a reason for hiding this comment

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

This one is new to me

}

// 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 {
Expand Down
Loading