mirror of
https://github.com/coder/coder.git
synced 2025-07-09 11:45:56 +00:00
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>
This commit is contained in:
3
coderd/apidoc/docs.go
generated
3
coderd/apidoc/docs.go
generated
@ -8439,6 +8439,9 @@ const docTemplate = `{
|
||||
"description_plaintext": {
|
||||
"type": "string"
|
||||
},
|
||||
"display_name": {
|
||||
"type": "string"
|
||||
},
|
||||
"icon": {
|
||||
"type": "string"
|
||||
},
|
||||
|
3
coderd/apidoc/swagger.json
generated
3
coderd/apidoc/swagger.json
generated
@ -7595,6 +7595,9 @@
|
||||
"description_plaintext": {
|
||||
"type": "string"
|
||||
},
|
||||
"display_name": {
|
||||
"type": "string"
|
||||
},
|
||||
"icon": {
|
||||
"type": "string"
|
||||
},
|
||||
|
@ -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,
|
||||
|
3
coderd/database/dump.sql
generated
3
coderd/database/dump.sql
generated
@ -354,6 +354,7 @@ CREATE TABLE template_version_parameters (
|
||||
validation_monotonic text DEFAULT ''::text NOT NULL,
|
||||
required boolean DEFAULT true NOT NULL,
|
||||
legacy_variable_name text DEFAULT ''::text NOT NULL,
|
||||
display_name text DEFAULT ''::text NOT NULL,
|
||||
CONSTRAINT validation_monotonic_order CHECK ((validation_monotonic = ANY (ARRAY['increasing'::text, 'decreasing'::text, ''::text])))
|
||||
);
|
||||
|
||||
@ -385,6 +386,8 @@ COMMENT ON COLUMN template_version_parameters.required IS 'Is parameter required
|
||||
|
||||
COMMENT ON COLUMN template_version_parameters.legacy_variable_name IS 'Name of the legacy variable for migration purposes';
|
||||
|
||||
COMMENT ON COLUMN template_version_parameters.display_name IS 'Display name of the rich parameter';
|
||||
|
||||
CREATE TABLE template_version_variables (
|
||||
template_version_id uuid NOT NULL,
|
||||
name text NOT NULL,
|
||||
|
@ -0,0 +1 @@
|
||||
ALTER TABLE template_version_parameters DROP COLUMN display_name;
|
@ -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';
|
@ -1472,6 +1472,8 @@ type TemplateVersionParameter struct {
|
||||
Required bool `db:"required" json:"required"`
|
||||
// Name of the legacy variable for migration purposes
|
||||
LegacyVariableName string `db:"legacy_variable_name" json:"legacy_variable_name"`
|
||||
// Display name of the rich parameter
|
||||
DisplayName string `db:"display_name" json:"display_name"`
|
||||
}
|
||||
|
||||
type TemplateVersionVariable struct {
|
||||
|
@ -3677,7 +3677,7 @@ func (q *sqlQuerier) UpdateTemplateScheduleByID(ctx context.Context, arg UpdateT
|
||||
}
|
||||
|
||||
const getTemplateVersionParameters = `-- name: GetTemplateVersionParameters :many
|
||||
SELECT template_version_id, name, description, type, mutable, default_value, icon, options, validation_regex, validation_min, validation_max, validation_error, validation_monotonic, required, legacy_variable_name FROM template_version_parameters WHERE template_version_id = $1
|
||||
SELECT template_version_id, name, description, type, mutable, default_value, icon, options, validation_regex, validation_min, validation_max, validation_error, validation_monotonic, required, legacy_variable_name, display_name FROM template_version_parameters WHERE template_version_id = $1
|
||||
`
|
||||
|
||||
func (q *sqlQuerier) GetTemplateVersionParameters(ctx context.Context, templateVersionID uuid.UUID) ([]TemplateVersionParameter, error) {
|
||||
@ -3705,6 +3705,7 @@ func (q *sqlQuerier) GetTemplateVersionParameters(ctx context.Context, templateV
|
||||
&i.ValidationMonotonic,
|
||||
&i.Required,
|
||||
&i.LegacyVariableName,
|
||||
&i.DisplayName,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -3736,7 +3737,8 @@ INSERT INTO
|
||||
validation_error,
|
||||
validation_monotonic,
|
||||
required,
|
||||
legacy_variable_name
|
||||
legacy_variable_name,
|
||||
display_name
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@ -3754,8 +3756,9 @@ VALUES
|
||||
$12,
|
||||
$13,
|
||||
$14,
|
||||
$15
|
||||
) RETURNING template_version_id, name, description, type, mutable, default_value, icon, options, validation_regex, validation_min, validation_max, validation_error, validation_monotonic, required, legacy_variable_name
|
||||
$15,
|
||||
$16
|
||||
) RETURNING template_version_id, name, description, type, mutable, default_value, icon, options, validation_regex, validation_min, validation_max, validation_error, validation_monotonic, required, legacy_variable_name, display_name
|
||||
`
|
||||
|
||||
type InsertTemplateVersionParameterParams struct {
|
||||
@ -3774,6 +3777,7 @@ type InsertTemplateVersionParameterParams struct {
|
||||
ValidationMonotonic string `db:"validation_monotonic" json:"validation_monotonic"`
|
||||
Required bool `db:"required" json:"required"`
|
||||
LegacyVariableName string `db:"legacy_variable_name" json:"legacy_variable_name"`
|
||||
DisplayName string `db:"display_name" json:"display_name"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) InsertTemplateVersionParameter(ctx context.Context, arg InsertTemplateVersionParameterParams) (TemplateVersionParameter, error) {
|
||||
@ -3793,6 +3797,7 @@ func (q *sqlQuerier) InsertTemplateVersionParameter(ctx context.Context, arg Ins
|
||||
arg.ValidationMonotonic,
|
||||
arg.Required,
|
||||
arg.LegacyVariableName,
|
||||
arg.DisplayName,
|
||||
)
|
||||
var i TemplateVersionParameter
|
||||
err := row.Scan(
|
||||
@ -3811,6 +3816,7 @@ func (q *sqlQuerier) InsertTemplateVersionParameter(ctx context.Context, arg Ins
|
||||
&i.ValidationMonotonic,
|
||||
&i.Required,
|
||||
&i.LegacyVariableName,
|
||||
&i.DisplayName,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
@ -15,7 +15,8 @@ INSERT INTO
|
||||
validation_error,
|
||||
validation_monotonic,
|
||||
required,
|
||||
legacy_variable_name
|
||||
legacy_variable_name,
|
||||
display_name
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@ -33,7 +34,8 @@ VALUES
|
||||
$12,
|
||||
$13,
|
||||
$14,
|
||||
$15
|
||||
$15,
|
||||
$16
|
||||
) RETURNING *;
|
||||
|
||||
-- name: GetTemplateVersionParameters :many
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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"
|
||||
@ -1814,6 +1815,7 @@ func TestWorkspaceWithRichParameters(t *testing.T) {
|
||||
},
|
||||
{
|
||||
Name: secondParameterName,
|
||||
DisplayName: secondParameterDisplayName,
|
||||
Type: secondParameterType,
|
||||
Description: secondParameterDescription,
|
||||
ValidationMin: 1,
|
||||
@ -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)
|
||||
|
Reference in New Issue
Block a user