Skip to content

feat: rich parameters: introduce display_name #6919

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 26 commits into from
Apr 3, 2023
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
7 changes: 6 additions & 1 deletion cli/cliui/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ func ParameterSchema(inv *clibase.Invocation, parameterSchema codersdk.Parameter
}

func RichParameter(inv *clibase.Invocation, templateVersionParameter codersdk.TemplateVersionParameter) (string, error) {
_, _ = fmt.Fprintln(inv.Stdout, Styles.Bold.Render(templateVersionParameter.Name))
label := templateVersionParameter.Name
if templateVersionParameter.DisplayName != "" {
label = templateVersionParameter.DisplayName
}

_, _ = fmt.Fprintln(inv.Stdout, Styles.Bold.Render(label))
if templateVersionParameter.DescriptionPlaintext != "" {
_, _ = fmt.Fprintln(inv.Stdout, " "+strings.TrimSpace(strings.Join(strings.Split(templateVersionParameter.DescriptionPlaintext, "\n"), "\n "))+"\n")
}
Expand Down
9 changes: 7 additions & 2 deletions cli/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ func TestCreateWithRichParameters(t *testing.T) {
firstParameterValue = "1"

secondParameterName = "second_parameter"
secondParameterDisplayName = "Second Parameter"
secondParameterDescription = "This is second parameter"
secondParameterValue = "2"

Expand All @@ -382,7 +383,7 @@ func TestCreateWithRichParameters(t *testing.T) {
Complete: &proto.Provision_Complete{
Parameters: []*proto.RichParameter{
{Name: firstParameterName, Description: firstParameterDescription, Mutable: true},
{Name: secondParameterName, Description: secondParameterDescription, Mutable: true},
{Name: secondParameterName, DisplayName: secondParameterDisplayName, Description: secondParameterDescription, Mutable: true},
{Name: immutableParameterName, Description: immutableParameterDescription, Mutable: false},
},
},
Expand Down Expand Up @@ -418,6 +419,7 @@ func TestCreateWithRichParameters(t *testing.T) {

matches := []string{
firstParameterDescription, firstParameterValue,
secondParameterDisplayName, "",
secondParameterDescription, secondParameterValue,
immutableParameterDescription, immutableParameterValue,
"Confirm create?", "yes",
Expand All @@ -426,7 +428,10 @@ func TestCreateWithRichParameters(t *testing.T) {
match := matches[i]
value := matches[i+1]
pty.ExpectMatch(match)
pty.WriteLine(value)

if value != "" {
pty.WriteLine(value)
}
}
<-doneChan
})
Expand Down
3 changes: 3 additions & 0 deletions coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions coderd/database/dbfake/databasefake.go
Original file line number Diff line number Diff line change
Expand Up @@ -2944,6 +2944,7 @@ func (q *fakeQuerier) InsertTemplateVersionParameter(_ context.Context, arg data
param := database.TemplateVersionParameter{
TemplateVersionID: arg.TemplateVersionID,
Name: arg.Name,
DisplayName: arg.DisplayName,
Description: arg.Description,
Type: arg.Type,
Mutable: arg.Mutable,
Expand Down
3 changes: 3 additions & 0 deletions coderd/database/dump.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE template_version_parameters DROP COLUMN display_name;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE template_version_parameters ADD COLUMN display_name text NOT NULL DEFAULT '';

COMMENT ON COLUMN template_version_parameters.display_name
IS 'Display name of the rich parameter';
2 changes: 2 additions & 0 deletions coderd/database/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions coderd/database/queries/templateversionparameters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ INSERT INTO
validation_error,
validation_monotonic,
required,
legacy_variable_name
legacy_variable_name,
display_name
)
VALUES
(
Expand All @@ -33,7 +34,8 @@ VALUES
$12,
$13,
$14,
$15
$15,
$16
) RETURNING *;

-- name: GetTemplateVersionParameters :many
Expand Down
1 change: 1 addition & 0 deletions coderd/provisionerdserver/provisionerdserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,7 @@ func (server *Server) CompleteJob(ctx context.Context, completed *proto.Complete
_, err = server.Database.InsertTemplateVersionParameter(ctx, database.InsertTemplateVersionParameterParams{
TemplateVersionID: input.TemplateVersionID,
Name: richParameter.Name,
DisplayName: richParameter.DisplayName,
Description: richParameter.Description,
Type: richParameter.Type,
Mutable: richParameter.Mutable,
Expand Down
1 change: 1 addition & 0 deletions coderd/templateversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,7 @@ func convertTemplateVersionParameter(param database.TemplateVersionParameter) (c
}
return codersdk.TemplateVersionParameter{
Name: param.Name,
DisplayName: param.DisplayName,
Description: param.Description,
DescriptionPlaintext: descriptionPlaintext,
Type: param.Type,
Expand Down
3 changes: 3 additions & 0 deletions coderd/workspaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1792,6 +1792,7 @@ func TestWorkspaceWithRichParameters(t *testing.T) {
firstParameterValue = "1"

secondParameterName = "second_parameter"
secondParameterDisplayName = "Second Parameter"
secondParameterType = "number"
secondParameterDescription = "_This_ is second *parameter*"
secondParameterValue = "2"
Expand All @@ -1814,6 +1815,7 @@ func TestWorkspaceWithRichParameters(t *testing.T) {
},
{
Name: secondParameterName,
DisplayName: secondParameterDisplayName,
Type: secondParameterType,
Description: secondParameterDescription,
ValidationMin: 1,
Expand Down Expand Up @@ -1850,6 +1852,7 @@ func TestWorkspaceWithRichParameters(t *testing.T) {
require.Equal(t, firstParameterDescriptionPlaintext, templateRichParameters[0].DescriptionPlaintext)
require.Equal(t, codersdk.ValidationMonotonicOrder(""), templateRichParameters[0].ValidationMonotonic) // no validation for string
require.Equal(t, secondParameterName, templateRichParameters[1].Name)
require.Equal(t, secondParameterDisplayName, templateRichParameters[1].DisplayName)
require.Equal(t, secondParameterType, templateRichParameters[1].Type)
require.Equal(t, secondParameterDescription, templateRichParameters[1].Description)
require.Equal(t, secondParameterDescriptionPlaintext, templateRichParameters[1].DescriptionPlaintext)
Expand Down
1 change: 1 addition & 0 deletions codersdk/templateversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const (
// TemplateVersionParameter represents a parameter for a template version.
type TemplateVersionParameter struct {
Name string `json:"name"`
DisplayName string `json:"display_name,omitempty"`
Description string `json:"description"`
DescriptionPlaintext string `json:"description_plaintext"`
Type string `json:"type" enums:"string,number,bool,list(string)"`
Expand Down
2 changes: 2 additions & 0 deletions docs/api/schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -3888,6 +3888,7 @@ Parameter represents a set value for the scope.
"default_value": "string",
"description": "string",
"description_plaintext": "string",
"display_name": "string",
"icon": "string",
"legacy_variable_name": "string",
"mutable": true,
Expand Down Expand Up @@ -3917,6 +3918,7 @@ Parameter represents a set value for the scope.
| `default_value` | string | false | | |
| `description` | string | false | | |
| `description_plaintext` | string | false | | |
| `display_name` | string | false | | |
| `icon` | string | false | | |
| `legacy_variable_name` | string | false | | |
| `mutable` | boolean | false | | |
Expand Down
2 changes: 2 additions & 0 deletions docs/api/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -2301,6 +2301,7 @@ curl -X GET http://coder-server:8080/api/v2/templateversions/{templateversion}/r
"default_value": "string",
"description": "string",
"description_plaintext": "string",
"display_name": "string",
"icon": "string",
"legacy_variable_name": "string",
"mutable": true,
Expand Down Expand Up @@ -2340,6 +2341,7 @@ Status Code **200**
| `» default_value` | string | false | | |
| `» description` | string | false | | |
| `» description_plaintext` | string | false | | |
| `» display_name` | string | false | | |
| `» icon` | string | false | | |
| `» legacy_variable_name` | string | false | | |
| `» mutable` | boolean | false | | |
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ require (
github.com/codeclysm/extract v2.2.0+incompatible
github.com/coder/flog v1.1.0
github.com/coder/retry v1.3.1-0.20230210155434-e90a2e1e091d
github.com/coder/terraform-provider-coder v0.6.21
github.com/coder/terraform-provider-coder v0.6.23
github.com/coder/wgtunnel v0.1.5
github.com/coreos/go-oidc/v3 v3.4.0
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ github.com/coder/ssh v0.0.0-20220811105153-fcea99919338 h1:tN5GKFT68YLVzJoA8AHui
github.com/coder/ssh v0.0.0-20220811105153-fcea99919338/go.mod h1:ZSS+CUoKHDrqVakTfTWUlKSr9MtMFkC4UvtQKD7O914=
github.com/coder/tailscale v1.1.1-0.20230329230537-76a675d945b7 h1:07rCDmnCKGG666bR0WI1grlI/RnI54xj0C+2d2gWeE4=
github.com/coder/tailscale v1.1.1-0.20230329230537-76a675d945b7/go.mod h1:jpg+77g19FpXL43U1VoIqoSg1K/Vh5CVxycGldQ8KhA=
github.com/coder/terraform-provider-coder v0.6.21 h1:TIH6+/VQFreT8q/CkRvpHtbIeM5cOAhuDS5Sh1Nm21Q=
github.com/coder/terraform-provider-coder v0.6.21/go.mod h1:UIfU3bYNeSzJJvHyJ30tEKjD6Z9utloI+HUM/7n94CY=
github.com/coder/terraform-provider-coder v0.6.23 h1:O2Rcj0umez4DfVdGnKZi63z1Xzxd0IQOn9VQDB8YU8g=
github.com/coder/terraform-provider-coder v0.6.23/go.mod h1:UIfU3bYNeSzJJvHyJ30tEKjD6Z9utloI+HUM/7n94CY=
github.com/coder/wgtunnel v0.1.5 h1:WP3sCj/3iJ34eKvpMQEp1oJHvm24RYh0NHbj1kfUKfs=
github.com/coder/wgtunnel v0.1.5/go.mod h1:bokoUrHnUFY4lu9KOeSYiIcHTI2MO1KwqumU4DPDyJI=
github.com/containerd/aufs v0.0.0-20200908144142-dab0cbea06f4/go.mod h1:nukgQABAEopAHvB6j7cnP5zJ+/3aVcE7hCYqvIwAHyE=
Expand Down
1 change: 1 addition & 0 deletions provisioner/terraform/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ func ConvertState(modules []*tfjson.StateModule, rawGraph string, rawParameterNa
}
protoParam := &proto.RichParameter{
Name: param.Name,
DisplayName: param.DisplayName,
Description: param.Description,
Type: param.Type,
Mutable: param.Mutable,
Expand Down
Loading