Skip to content

feat: add "display_order" column to coder_parameter to keep parameters sorted in UI #8227

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 25 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Correct order
  • Loading branch information
mtojek committed Jun 30, 2023
commit 1e54acedb628e09bb06b17e84c76e159a223adf5
16 changes: 8 additions & 8 deletions provisioner/terraform/provision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,29 +408,29 @@ func TestProvision(t *testing.T) {
},
Request: &proto.Provision_Plan{
RichParameterValues: []*proto.RichParameterValue{
{
Name: "Sample",
Value: "foofoo",
},
{
Name: "Example",
Value: "foobaz",
},
{
Name: "Sample",
Value: "foofoo",
},
},
},
Response: &proto.Provision_Response{
Type: &proto.Provision_Response_Complete{
Complete: &proto.Provision_Complete{
Parameters: []*proto.RichParameter{
{
Name: "Sample",
Name: "Example",
Type: "string",
DefaultValue: "foobaz",
DefaultValue: "foobar",
},
{
Name: "Example",
Name: "Sample",
Type: "string",
DefaultValue: "foobar",
DefaultValue: "foobaz",
},
},
Resources: []*proto.Resource{{
Expand Down
42 changes: 0 additions & 42 deletions provisioner/terraform/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package terraform

import (
"fmt"
"sort"
"strings"

"github.com/awalterschulze/gographviz"
Expand Down Expand Up @@ -719,44 +718,3 @@ func findResourcesInGraph(graph *gographviz.Graph, tfResourcesByLabel map[string

return graphResources
}

func orderedRichParametersResources(tfResourcesRichParameters []*tfjson.StateResource, orderedNames []string) []*tfjson.StateResource {
if len(orderedNames) == 0 {
return tfResourcesRichParameters
}

var ordered []*tfjson.StateResource
for _, name := range orderedNames {
for _, resource := range tfResourcesRichParameters {
if resource.Name == name {
ordered = append(ordered, resource)
}
}
}

// Edge case: a parameter is present in an external module (Git repository, static files, etc.),
// which can't be easily parsed to check the parameter order.
// Those parameters will be prepended to the "ordered" list.
var external []*tfjson.StateResource
for _, resource := range tfResourcesRichParameters {
isExternal := true
for _, o := range ordered {
if resource.Name == o.Name {
isExternal = false
break
}
}
if isExternal {
external = append(external, resource)
}
}

if len(external) > 0 {
sort.Slice(external, func(i, j int) bool {
return external[i].Name < external[j].Name
})

ordered = append(external, ordered...)
}
return ordered
}
62 changes: 31 additions & 31 deletions provisioner/terraform/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,17 @@ func TestConvertResources(t *testing.T) {
}},
Required: true,
}, {
Name: "Sample",
Type: "string",
Description: "blah blah",
DefaultValue: "ok",
Name: "number_example",
Type: "number",
DefaultValue: "4",
ValidationMin: nil,
ValidationMax: nil,
}, {
Name: "number_example_max_zero",
Type: "number",
DefaultValue: "-2",
ValidationMin: terraform.PtrInt32(-3),
ValidationMax: terraform.PtrInt32(0),
}, {
Name: "number_example_min_max",
Type: "number",
Expand All @@ -370,17 +377,10 @@ func TestConvertResources(t *testing.T) {
ValidationMin: terraform.PtrInt32(0),
ValidationMax: terraform.PtrInt32(6),
}, {
Name: "number_example_max_zero",
Type: "number",
DefaultValue: "-2",
ValidationMin: terraform.PtrInt32(-3),
ValidationMax: terraform.PtrInt32(0),
}, {
Name: "number_example",
Type: "number",
DefaultValue: "4",
ValidationMin: nil,
ValidationMax: nil,
Name: "Sample",
Type: "string",
Description: "blah blah",
DefaultValue: "ok",
}},
},
"rich-parameters-validation": {
Expand All @@ -399,22 +399,10 @@ func TestConvertResources(t *testing.T) {
}},
}},
parameters: []*proto.RichParameter{{
Name: "number_example_min_max",
Type: "number",
DefaultValue: "4",
ValidationMin: terraform.PtrInt32(3),
ValidationMax: terraform.PtrInt32(6),
}, {
Name: "number_example_min",
Type: "number",
DefaultValue: "4",
ValidationMin: terraform.PtrInt32(3),
ValidationMax: nil,
}, {
Name: "number_example_min_zero",
Name: "number_example",
Type: "number",
DefaultValue: "4",
ValidationMin: terraform.PtrInt32(0),
ValidationMin: nil,
ValidationMax: nil,
}, {
Name: "number_example_max",
Expand All @@ -429,10 +417,22 @@ func TestConvertResources(t *testing.T) {
ValidationMin: nil,
ValidationMax: terraform.PtrInt32(0),
}, {
Name: "number_example",
Name: "number_example_min",
Type: "number",
DefaultValue: "4",
ValidationMin: nil,
ValidationMin: terraform.PtrInt32(3),
ValidationMax: nil,
}, {
Name: "number_example_min_max",
Type: "number",
DefaultValue: "4",
ValidationMin: terraform.PtrInt32(3),
ValidationMax: terraform.PtrInt32(6),
}, {
Name: "number_example_min_zero",
Type: "number",
DefaultValue: "4",
ValidationMin: terraform.PtrInt32(0),
ValidationMax: nil,
}},
},
Expand Down
2 changes: 1 addition & 1 deletion provisioner/terraform/testdata/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")"

for d in */; do
for d in rich-parameters-validation/; do
pushd "$d"
name=$(basename "$(pwd)")

Expand Down