Skip to content
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

Use the default value for a TopologyOption if omitted #3165

Merged
merged 2 commits into from
May 28, 2018
Merged
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
17 changes: 8 additions & 9 deletions app/api_topologies.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func (a byName) Less(i, j int) bool { return a[i].Name < a[j].Name }
// APITopologyOptionGroup describes a group of APITopologyOptions
type APITopologyOptionGroup struct {
ID string `json:"id"`
// Default value for the UI to adopt. NOT used as the default if the value is omitted, allowing "" as a distinct value.
// Default value for the option. Used if the value is omitted; not used if the value is ""
Default string `json:"defaultValue"`
Options []APITopologyOption `json:"options,omitempty"`
// SelectType describes how options can be picked. Currently defined values:
Expand All @@ -328,18 +328,14 @@ type APITopologyOptionGroup struct {

// Get the render filters to use for this option group, if any, or nil otherwise.
func (g APITopologyOptionGroup) filter(value string) render.FilterFunc {
selectType := g.SelectType
if selectType == "" {
selectType = "one"
}
var values []string
switch selectType {
case "one":
switch g.SelectType {
case "", "one":
values = []string{value}
case "union":
values = strings.Split(value, ",")
default:
log.Errorf("Invalid select type %s for option group %s, ignoring option", selectType, g.ID)
log.Errorf("Invalid select type %s for option group %s, ignoring option", g.SelectType, g.ID)
return nil
}
filters := []render.FilterFunc{}
Expand Down Expand Up @@ -522,7 +518,10 @@ func (r *Registry) RendererForTopology(topologyID string, values url.Values, rpt

var filters []render.FilterFunc
for _, group := range topology.Options {
value := values.Get(group.ID)
value := group.Default
if vs := values[group.ID]; len(vs) > 0 {
value = vs[0]
}
if filter := group.filter(value); filter != nil {
filters = append(filters, filter)
}
Expand Down