Skip to content

Commit 0c4f4c6

Browse files
committed
form_type_metadata -> styling
1 parent 3fc424c commit 0c4f4c6

File tree

11 files changed

+64
-62
lines changed

11 files changed

+64
-62
lines changed

extract/parameter.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func ParameterFromBlock(block *terraform.Block) (*types.Parameter, hcl.Diagnosti
5656
def = types.ToHCLString(block, defAttr)
5757
}
5858

59-
ftmeta := optionalString(block, "form_type_metadata")
59+
ftmeta := optionalString(block, "styling")
6060
formTypeMeta := make(map[string]any)
6161
if ftmeta != "" {
6262
_ = json.Unmarshal([]byte(ftmeta), &formTypeMeta)
@@ -65,12 +65,12 @@ func ParameterFromBlock(block *terraform.Block) (*types.Parameter, hcl.Diagnosti
6565
p := types.Parameter{
6666
Value: pVal,
6767
ParameterData: types.ParameterData{
68-
Name: pName,
69-
Description: optionalString(block, "description"),
70-
Type: pType,
71-
FormType: formType,
72-
FormTypeMetadata: formTypeMeta,
73-
Mutable: optionalBoolean(block, "mutable"),
68+
Name: pName,
69+
Description: optionalString(block, "description"),
70+
Type: pType,
71+
FormType: formType,
72+
Styling: formTypeMeta,
73+
Mutable: optionalBoolean(block, "mutable"),
7474
// Default value is always written as a string, then converted
7575
// to the correct type.
7676
DefaultValue: def,

extract/state.go

+17-15
Original file line numberDiff line numberDiff line change
@@ -53,29 +53,31 @@ func ParameterFromState(block *tfjson.StateResource) (types.Parameter, error) {
5353
return types.Parameter{}, fmt.Errorf("convert param validations: %w", err)
5454
}
5555

56-
ftmeta := st.optionalString("form_type_metadata")
56+
ftmeta := st.optionalString("styling")
5757
var formTypeMeta any
5858
if ftmeta != "" {
5959
_ = json.Unmarshal([]byte(ftmeta), &formTypeMeta)
60+
} else {
61+
formTypeMeta = map[string]any{}
6062
}
6163

6264
param := types.Parameter{
6365
Value: types.StringLiteral(st.string("value")),
6466
ParameterData: types.ParameterData{
65-
Name: st.string("name"),
66-
Description: st.optionalString("description"),
67-
Type: types.ParameterType(st.optionalString("type")),
68-
FormType: provider.ParameterFormType(st.optionalString("form_type")),
69-
FormTypeMetadata: formTypeMeta,
70-
Mutable: st.optionalBool("mutable"),
71-
DefaultValue: types.StringLiteral(st.optionalString("default")),
72-
Icon: st.optionalString("icon"),
73-
Options: options,
74-
Validations: validations,
75-
Required: st.optionalBool("required"),
76-
DisplayName: st.optionalString("display_name"),
77-
Order: st.optionalInteger("order"),
78-
Ephemeral: st.optionalBool("ephemeral"),
67+
Name: st.string("name"),
68+
Description: st.optionalString("description"),
69+
Type: types.ParameterType(st.optionalString("type")),
70+
FormType: provider.ParameterFormType(st.optionalString("form_type")),
71+
Styling: formTypeMeta,
72+
Mutable: st.optionalBool("mutable"),
73+
DefaultValue: types.StringLiteral(st.optionalString("default")),
74+
Icon: st.optionalString("icon"),
75+
Options: options,
76+
Validations: validations,
77+
Required: st.optionalBool("required"),
78+
DisplayName: st.optionalString("display_name"),
79+
Order: st.optionalInteger("order"),
80+
Ephemeral: st.optionalBool("ephemeral"),
7981
},
8082
}
8183

site/src/DynamicForm.tsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export function DynamicForm() {
216216
<Select
217217
onValueChange={field.onChange}
218218
defaultValue={parameterValue(param.default_value)}
219-
disabled={(param.form_type_metadata as { disabled?: boolean })?.disabled}
219+
disabled={(param.styling as { disabled?: boolean })?.disabled}
220220
>
221221
<SelectTrigger>
222222
<SelectValue placeholder={param.description} />
@@ -267,7 +267,7 @@ export function DynamicForm() {
267267
// }))
268268
// : []}
269269
emptyIndicator={<p className="text-sm">No results found</p>}
270-
disabled={(param.form_type_metadata as { disabled?: boolean })?.disabled}
270+
disabled={(param.styling as { disabled?: boolean })?.disabled}
271271
/>
272272
</div>
273273
)}
@@ -298,7 +298,7 @@ export function DynamicForm() {
298298
onValueChange={(value) => {
299299
field.onChange(value[0].toString());
300300
}}
301-
disabled={(param.form_type_metadata as { disabled?: boolean })?.disabled}
301+
disabled={(param.styling as { disabled?: boolean })?.disabled}
302302
/>
303303
</div>
304304
)}
@@ -315,7 +315,7 @@ export function DynamicForm() {
315315
control={methods.control}
316316
render={({ field }) => (
317317
<div>
318-
<RadioGroup defaultValue={parameterValue(param.default_value)} onValueChange={field.onChange} disabled={(param.form_type_metadata as { disabled?: boolean })?.disabled}>
318+
<RadioGroup defaultValue={parameterValue(param.default_value)} onValueChange={field.onChange} disabled={(param.styling as { disabled?: boolean })?.disabled}>
319319
{(param.options || []).map((option, idx) => {
320320
if (!option) return null;
321321
return (
@@ -344,7 +344,7 @@ export function DynamicForm() {
344344
<Switch
345345
checked={Boolean(field.value === "true")}
346346
onCheckedChange={(checked) => field.onChange(checked.toString())}
347-
disabled={(param.form_type_metadata as { disabled?: boolean })?.disabled}
347+
disabled={(param.styling as { disabled?: boolean })?.disabled}
348348
/>
349349
</div>
350350
)}
@@ -361,7 +361,7 @@ export function DynamicForm() {
361361
control={methods.control}
362362
render={({ field }) => (
363363
<div>
364-
<Checkbox checked={Boolean(field.value === "true")} onCheckedChange={(checked) => field.onChange(checked.toString())} disabled={(param.form_type_metadata as { disabled?: boolean })?.disabled} />
364+
<Checkbox checked={Boolean(field.value === "true")} onCheckedChange={(checked) => field.onChange(checked.toString())} disabled={(param.styling as { disabled?: boolean })?.disabled} />
365365
</div>
366366
)}
367367
/>
@@ -380,7 +380,7 @@ export function DynamicForm() {
380380
<Textarea
381381
value={field.value}
382382
onChange={(e) => field.onChange(e)}
383-
disabled={(param.form_type_metadata as { disabled?: boolean })?.disabled}
383+
disabled={(param.styling as { disabled?: boolean })?.disabled}
384384
/>
385385
</div>
386386
)}
@@ -402,7 +402,7 @@ export function DynamicForm() {
402402
}}
403403
type={mapParamTypeToInputType(param.type)}
404404
defaultValue={parameterValue(param.default_value)}
405-
disabled={(param.form_type_metadata as { disabled?: boolean })?.disabled}
405+
disabled={(param.styling as { disabled?: boolean })?.disabled}
406406
/>
407407
)}
408408
/>

site/src/types/preview.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export interface ParameterData {
3636
// this is likely an enum in an external package "github.com/coder/terraform-provider-coder/v2/provider.ParameterFormType"
3737
readonly form_type: string;
3838
// empty interface{} type, falling back to unknown
39-
readonly form_type_metadata: unknown;
39+
readonly styling: unknown;
4040
readonly mutable: boolean;
4141
readonly default_value: NullHCLString;
4242
readonly icon: string;

testdata/connections/main.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ data "coder_parameter" display {
6363
default = local.solved ? false : true
6464
# default = local.solved ? "" : "Keep guessing!"
6565

66-
form_type_metadata = jsonencode({
66+
styling = jsonencode({
6767
disabled = !local.solved
6868
})
6969
}
@@ -81,7 +81,7 @@ data "coder_parameter" "rows" {
8181
# name = "rows"
8282
type = "list(string)"
8383
form_type = "multi-select"
84-
form_type_metadata = jsonencode({
84+
styling = jsonencode({
8585
disabled = module.checker[each.value].solved
8686
})
8787
default = "[]"

testdata/demo/parameters.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ data "coder_parameter" "cpu" {
7171
mutable = true
7272
order = 20
7373

74-
form_type_metadata = jsonencode({
74+
styling = jsonencode({
7575
"minumum" = 1
7676
"budget" = 2
7777
"performance" = module.base.security_level == "high" ? 4 : 8

testdata/demo/plan.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
"display_name": null,
124124
"ephemeral": false,
125125
"form_type": "radio",
126-
"form_type_metadata": "{}",
126+
"styling": "{}",
127127
"icon": null,
128128
"id": "5e27a5d3-52ef-41ba-9c6b-cc4cdb1c98ff",
129129
"mutable": false,
@@ -190,7 +190,7 @@
190190
"display_name": "CPU",
191191
"ephemeral": false,
192192
"form_type": "slider",
193-
"form_type_metadata": "{\"budget\":2,\"minumum\":1,\"performance\":4}",
193+
"styling": "{\"budget\":2,\"minumum\":1,\"performance\":4}",
194194
"icon": "/icon/memory.svg",
195195
"id": "6e2e551e-b126-490a-a061-08504848bdb5",
196196
"mutable": true,
@@ -231,7 +231,7 @@
231231
"display_name": "Region",
232232
"ephemeral": false,
233233
"form_type": "radio",
234-
"form_type_metadata": "{}",
234+
"styling": "{}",
235235
"icon": "/icon/memory.svg",
236236
"id": "c60ab269-96a7-42a7-9aaa-d9a6f0f60ecd",
237237
"mutable": false,
@@ -298,7 +298,7 @@
298298
"display_name": null,
299299
"ephemeral": false,
300300
"form_type": "radio",
301-
"form_type_metadata": "{}",
301+
"styling": "{}",
302302
"icon": null,
303303
"id": "09c65d3c-f116-49a0-855c-6675c4aa1c21",
304304
"mutable": false,
@@ -474,7 +474,7 @@
474474
"display_name": "JetBrains IDE",
475475
"ephemeral": false,
476476
"form_type": "radio",
477-
"form_type_metadata": "{}",
477+
"styling": "{}",
478478
"icon": "/icon/gateway.svg",
479479
"id": "a56f76ad-7626-4a22-b7b4-d0dac5c6e93a",
480480
"mutable": true,
@@ -709,7 +709,7 @@
709709
"form_type": {
710710
"constant_value": "slider"
711711
},
712-
"form_type_metadata": {
712+
"styling": {
713713
"references": [
714714
"module.base.security_level",
715715
"module.base"

testdata/demo_flat/parameters.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ data "coder_parameter" "cpu" {
7272
mutable = true
7373
order = 20
7474

75-
form_type_metadata = jsonencode({
75+
styling = jsonencode({
7676
"minumum" = 1
7777
"budget" = 2
7878
"performance" = local.secutity_level == "high" ? 4 : 8

testdata/module/plan.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@
172172
"display_name": "Extra Param",
173173
"ephemeral": false,
174174
"form_type": "input",
175-
"form_type_metadata": "{}",
175+
"styling": "{}",
176176
"icon": null,
177177
"id": "792c6343-65bf-470a-8edb-f88d89e03cce",
178178
"mutable": false,
@@ -257,7 +257,7 @@
257257
"display_name": "JetBrains IDE",
258258
"ephemeral": false,
259259
"form_type": "radio",
260-
"form_type_metadata": "{}",
260+
"styling": "{}",
261261
"icon": "/icon/gateway.svg",
262262
"id": "5cacbcbc-adcf-46dd-bd54-6292a6797fbf",
263263
"mutable": true,

testdata/wordle/main.tf

+7-7
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ data "coder_parameter" "letter_bank" {
4949
order = 9
5050
default = ""
5151
form_type = "input"
52-
form_type_metadata = jsonencode({
52+
styling = jsonencode({
5353
disabled = !local.solved
5454
})
5555
# count = 0
@@ -63,7 +63,7 @@ data "coder_parameter" "one" {
6363
order = 11
6464
default = ""
6565

66-
form_type_metadata = jsonencode({
66+
styling = jsonencode({
6767
disabled = (length(data.coder_parameter.one.value) == 5 && contains(local.wordlist,data.coder_parameter.one.value)) || local.solved
6868
})
6969

@@ -89,7 +89,7 @@ data "coder_parameter" "two" {
8989
order = 12
9090
default = ""
9191

92-
form_type_metadata = jsonencode({
92+
styling = jsonencode({
9393
disabled = (length(data.coder_parameter.two.value) == 5 && contains(local.wordlist,data.coder_parameter.two.value)) || local.solved
9494
})
9595

@@ -115,7 +115,7 @@ data "coder_parameter" "three" {
115115
order = 13
116116
default = ""
117117

118-
form_type_metadata = jsonencode({
118+
styling = jsonencode({
119119
disabled = (length(data.coder_parameter.three.value) == 5 && contains(local.wordlist,data.coder_parameter.three.value)) || local.solved
120120
})
121121

@@ -141,7 +141,7 @@ data "coder_parameter" "four" {
141141
order = 14
142142
default = ""
143143

144-
form_type_metadata = jsonencode({
144+
styling = jsonencode({
145145
disabled = (length(data.coder_parameter.four.value) == 5 && contains(local.wordlist,data.coder_parameter.four.value)) || local.solved
146146
})
147147

@@ -167,7 +167,7 @@ data "coder_parameter" "five" {
167167
order = 15
168168
default = ""
169169

170-
form_type_metadata = jsonencode({
170+
styling = jsonencode({
171171
disabled = (length(data.coder_parameter.five.value) == 5 && contains(local.wordlist,data.coder_parameter.five.value)) || local.solved
172172
})
173173

@@ -193,7 +193,7 @@ data "coder_parameter" "six" {
193193
order = 16
194194
default = ""
195195

196-
form_type_metadata = jsonencode({
196+
styling = jsonencode({
197197
disabled = (length(data.coder_parameter.six.value) == 5 && contains(local.wordlist,data.coder_parameter.six.value)) || local.solved
198198
})
199199

types/parameter.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,18 @@ type Parameter struct {
4545
}
4646

4747
type ParameterData struct {
48-
Name string `json:"name"`
49-
DisplayName string `json:"display_name"`
50-
Description string `json:"description"`
51-
Type ParameterType `json:"type"`
52-
FormType provider.ParameterFormType `json:"form_type"`
53-
FormTypeMetadata any `json:"form_type_metadata"`
54-
Mutable bool `json:"mutable"`
55-
DefaultValue HCLString `json:"default_value"`
56-
Icon string `json:"icon"`
57-
Options []*ParameterOption `json:"options"`
58-
Validations []*ParameterValidation `json:"validations"`
59-
Required bool `json:"required"`
48+
Name string `json:"name"`
49+
DisplayName string `json:"display_name"`
50+
Description string `json:"description"`
51+
Type ParameterType `json:"type"`
52+
FormType provider.ParameterFormType `json:"form_type"`
53+
Styling any `json:"styling"`
54+
Mutable bool `json:"mutable"`
55+
DefaultValue HCLString `json:"default_value"`
56+
Icon string `json:"icon"`
57+
Options []*ParameterOption `json:"options"`
58+
Validations []*ParameterValidation `json:"validations"`
59+
Required bool `json:"required"`
6060
// legacy_variable_name was removed (= 14)
6161
Order int64 `json:"order"`
6262
Ephemeral bool `json:"ephemeral"`

0 commit comments

Comments
 (0)