Skip to content

Commit 633dfbd

Browse files
mtojekKira-Pilot
andauthored
feat: rich parameters: introduce display_name (#6919)
* model * DB * fix: DisplayName * proto * Proto * Update go dep * fixme * fix format * config * fmt * fix * Fix * fix * chore(UI): redirecting from workspace page if 404 (#6880) * model * CLI: Display parameter * fix * update dep * fix * fix * fix * UI changes * fmt --------- Co-authored-by: Kira Pilot <kira@coder.com>
1 parent d9d44c1 commit 633dfbd

25 files changed

+370
-297
lines changed

cli/cliui/parameter.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ func ParameterSchema(inv *clibase.Invocation, parameterSchema codersdk.Parameter
6262
}
6363

6464
func RichParameter(inv *clibase.Invocation, templateVersionParameter codersdk.TemplateVersionParameter) (string, error) {
65-
_, _ = fmt.Fprintln(inv.Stdout, Styles.Bold.Render(templateVersionParameter.Name))
65+
label := templateVersionParameter.Name
66+
if templateVersionParameter.DisplayName != "" {
67+
label = templateVersionParameter.DisplayName
68+
}
69+
70+
_, _ = fmt.Fprintln(inv.Stdout, Styles.Bold.Render(label))
6671
if templateVersionParameter.DescriptionPlaintext != "" {
6772
_, _ = fmt.Fprintln(inv.Stdout, " "+strings.TrimSpace(strings.Join(strings.Split(templateVersionParameter.DescriptionPlaintext, "\n"), "\n "))+"\n")
6873
}

cli/create_test.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ func TestCreateWithRichParameters(t *testing.T) {
366366
firstParameterValue = "1"
367367

368368
secondParameterName = "second_parameter"
369+
secondParameterDisplayName = "Second Parameter"
369370
secondParameterDescription = "This is second parameter"
370371
secondParameterValue = "2"
371372

@@ -382,7 +383,7 @@ func TestCreateWithRichParameters(t *testing.T) {
382383
Complete: &proto.Provision_Complete{
383384
Parameters: []*proto.RichParameter{
384385
{Name: firstParameterName, Description: firstParameterDescription, Mutable: true},
385-
{Name: secondParameterName, Description: secondParameterDescription, Mutable: true},
386+
{Name: secondParameterName, DisplayName: secondParameterDisplayName, Description: secondParameterDescription, Mutable: true},
386387
{Name: immutableParameterName, Description: immutableParameterDescription, Mutable: false},
387388
},
388389
},
@@ -418,6 +419,7 @@ func TestCreateWithRichParameters(t *testing.T) {
418419

419420
matches := []string{
420421
firstParameterDescription, firstParameterValue,
422+
secondParameterDisplayName, "",
421423
secondParameterDescription, secondParameterValue,
422424
immutableParameterDescription, immutableParameterValue,
423425
"Confirm create?", "yes",
@@ -426,7 +428,10 @@ func TestCreateWithRichParameters(t *testing.T) {
426428
match := matches[i]
427429
value := matches[i+1]
428430
pty.ExpectMatch(match)
429-
pty.WriteLine(value)
431+
432+
if value != "" {
433+
pty.WriteLine(value)
434+
}
430435
}
431436
<-doneChan
432437
})

coderd/apidoc/docs.go

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dbfake/databasefake.go

+1
Original file line numberDiff line numberDiff line change
@@ -2944,6 +2944,7 @@ func (q *fakeQuerier) InsertTemplateVersionParameter(_ context.Context, arg data
29442944
param := database.TemplateVersionParameter{
29452945
TemplateVersionID: arg.TemplateVersionID,
29462946
Name: arg.Name,
2947+
DisplayName: arg.DisplayName,
29472948
Description: arg.Description,
29482949
Type: arg.Type,
29492950
Mutable: arg.Mutable,

coderd/database/dump.sql

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE template_version_parameters DROP COLUMN display_name;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ALTER TABLE template_version_parameters ADD COLUMN display_name text NOT NULL DEFAULT '';
2+
3+
COMMENT ON COLUMN template_version_parameters.display_name
4+
IS 'Display name of the rich parameter';

coderd/database/models.go

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

+10-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/templateversionparameters.sql

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ INSERT INTO
1515
validation_error,
1616
validation_monotonic,
1717
required,
18-
legacy_variable_name
18+
legacy_variable_name,
19+
display_name
1920
)
2021
VALUES
2122
(
@@ -33,7 +34,8 @@ VALUES
3334
$12,
3435
$13,
3536
$14,
36-
$15
37+
$15,
38+
$16
3739
) RETURNING *;
3840

3941
-- name: GetTemplateVersionParameters :many

coderd/provisionerdserver/provisionerdserver.go

+1
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,7 @@ func (server *Server) CompleteJob(ctx context.Context, completed *proto.Complete
879879
_, err = server.Database.InsertTemplateVersionParameter(ctx, database.InsertTemplateVersionParameterParams{
880880
TemplateVersionID: input.TemplateVersionID,
881881
Name: richParameter.Name,
882+
DisplayName: richParameter.DisplayName,
882883
Description: richParameter.Description,
883884
Type: richParameter.Type,
884885
Mutable: richParameter.Mutable,

coderd/templateversions.go

+1
Original file line numberDiff line numberDiff line change
@@ -1596,6 +1596,7 @@ func convertTemplateVersionParameter(param database.TemplateVersionParameter) (c
15961596
}
15971597
return codersdk.TemplateVersionParameter{
15981598
Name: param.Name,
1599+
DisplayName: param.DisplayName,
15991600
Description: param.Description,
16001601
DescriptionPlaintext: descriptionPlaintext,
16011602
Type: param.Type,

coderd/workspaces_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -1792,6 +1792,7 @@ func TestWorkspaceWithRichParameters(t *testing.T) {
17921792
firstParameterValue = "1"
17931793

17941794
secondParameterName = "second_parameter"
1795+
secondParameterDisplayName = "Second Parameter"
17951796
secondParameterType = "number"
17961797
secondParameterDescription = "_This_ is second *parameter*"
17971798
secondParameterValue = "2"
@@ -1814,6 +1815,7 @@ func TestWorkspaceWithRichParameters(t *testing.T) {
18141815
},
18151816
{
18161817
Name: secondParameterName,
1818+
DisplayName: secondParameterDisplayName,
18171819
Type: secondParameterType,
18181820
Description: secondParameterDescription,
18191821
ValidationMin: 1,
@@ -1850,6 +1852,7 @@ func TestWorkspaceWithRichParameters(t *testing.T) {
18501852
require.Equal(t, firstParameterDescriptionPlaintext, templateRichParameters[0].DescriptionPlaintext)
18511853
require.Equal(t, codersdk.ValidationMonotonicOrder(""), templateRichParameters[0].ValidationMonotonic) // no validation for string
18521854
require.Equal(t, secondParameterName, templateRichParameters[1].Name)
1855+
require.Equal(t, secondParameterDisplayName, templateRichParameters[1].DisplayName)
18531856
require.Equal(t, secondParameterType, templateRichParameters[1].Type)
18541857
require.Equal(t, secondParameterDescription, templateRichParameters[1].Description)
18551858
require.Equal(t, secondParameterDescriptionPlaintext, templateRichParameters[1].DescriptionPlaintext)

codersdk/templateversions.go

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const (
4141
// TemplateVersionParameter represents a parameter for a template version.
4242
type TemplateVersionParameter struct {
4343
Name string `json:"name"`
44+
DisplayName string `json:"display_name,omitempty"`
4445
Description string `json:"description"`
4546
DescriptionPlaintext string `json:"description_plaintext"`
4647
Type string `json:"type" enums:"string,number,bool,list(string)"`

docs/api/schemas.md

+2
Original file line numberDiff line numberDiff line change
@@ -3888,6 +3888,7 @@ Parameter represents a set value for the scope.
38883888
"default_value": "string",
38893889
"description": "string",
38903890
"description_plaintext": "string",
3891+
"display_name": "string",
38913892
"icon": "string",
38923893
"legacy_variable_name": "string",
38933894
"mutable": true,
@@ -3917,6 +3918,7 @@ Parameter represents a set value for the scope.
39173918
| `default_value` | string | false | | |
39183919
| `description` | string | false | | |
39193920
| `description_plaintext` | string | false | | |
3921+
| `display_name` | string | false | | |
39203922
| `icon` | string | false | | |
39213923
| `legacy_variable_name` | string | false | | |
39223924
| `mutable` | boolean | false | | |

docs/api/templates.md

+2
Original file line numberDiff line numberDiff line change
@@ -2301,6 +2301,7 @@ curl -X GET http://coder-server:8080/api/v2/templateversions/{templateversion}/r
23012301
"default_value": "string",
23022302
"description": "string",
23032303
"description_plaintext": "string",
2304+
"display_name": "string",
23042305
"icon": "string",
23052306
"legacy_variable_name": "string",
23062307
"mutable": true,
@@ -2340,6 +2341,7 @@ Status Code **200**
23402341
| `» default_value` | string | false | | |
23412342
| `» description` | string | false | | |
23422343
| `» description_plaintext` | string | false | | |
2344+
| `» display_name` | string | false | | |
23432345
| `» icon` | string | false | | |
23442346
| `» legacy_variable_name` | string | false | | |
23452347
| `» mutable` | boolean | false | | |

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ require (
7272
github.com/codeclysm/extract v2.2.0+incompatible
7373
github.com/coder/flog v1.1.0
7474
github.com/coder/retry v1.3.1-0.20230210155434-e90a2e1e091d
75-
github.com/coder/terraform-provider-coder v0.6.21
75+
github.com/coder/terraform-provider-coder v0.6.23
7676
github.com/coder/wgtunnel v0.1.5
7777
github.com/coreos/go-oidc/v3 v3.4.0
7878
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,8 @@ github.com/coder/ssh v0.0.0-20220811105153-fcea99919338 h1:tN5GKFT68YLVzJoA8AHui
382382
github.com/coder/ssh v0.0.0-20220811105153-fcea99919338/go.mod h1:ZSS+CUoKHDrqVakTfTWUlKSr9MtMFkC4UvtQKD7O914=
383383
github.com/coder/tailscale v1.1.1-0.20230329230537-76a675d945b7 h1:07rCDmnCKGG666bR0WI1grlI/RnI54xj0C+2d2gWeE4=
384384
github.com/coder/tailscale v1.1.1-0.20230329230537-76a675d945b7/go.mod h1:jpg+77g19FpXL43U1VoIqoSg1K/Vh5CVxycGldQ8KhA=
385-
github.com/coder/terraform-provider-coder v0.6.21 h1:TIH6+/VQFreT8q/CkRvpHtbIeM5cOAhuDS5Sh1Nm21Q=
386-
github.com/coder/terraform-provider-coder v0.6.21/go.mod h1:UIfU3bYNeSzJJvHyJ30tEKjD6Z9utloI+HUM/7n94CY=
385+
github.com/coder/terraform-provider-coder v0.6.23 h1:O2Rcj0umez4DfVdGnKZi63z1Xzxd0IQOn9VQDB8YU8g=
386+
github.com/coder/terraform-provider-coder v0.6.23/go.mod h1:UIfU3bYNeSzJJvHyJ30tEKjD6Z9utloI+HUM/7n94CY=
387387
github.com/coder/wgtunnel v0.1.5 h1:WP3sCj/3iJ34eKvpMQEp1oJHvm24RYh0NHbj1kfUKfs=
388388
github.com/coder/wgtunnel v0.1.5/go.mod h1:bokoUrHnUFY4lu9KOeSYiIcHTI2MO1KwqumU4DPDyJI=
389389
github.com/containerd/aufs v0.0.0-20200908144142-dab0cbea06f4/go.mod h1:nukgQABAEopAHvB6j7cnP5zJ+/3aVcE7hCYqvIwAHyE=

provisioner/terraform/resources.go

+1
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ func ConvertState(modules []*tfjson.StateModule, rawGraph string, rawParameterNa
471471
}
472472
protoParam := &proto.RichParameter{
473473
Name: param.Name,
474+
DisplayName: param.DisplayName,
474475
Description: param.Description,
475476
Type: param.Type,
476477
Mutable: param.Mutable,

0 commit comments

Comments
 (0)