From 7da7183a37e069cadd8a6e9b61a640c7a746570b Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 9 May 2018 19:07:38 +0000 Subject: [PATCH 1/2] Refactor: simplify default type of option --- app/api_topologies.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/app/api_topologies.go b/app/api_topologies.go index 5618a6d9d..047341a5d 100644 --- a/app/api_topologies.go +++ b/app/api_topologies.go @@ -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{} From a64db66010df2223bd3568571f64ba4fe9b62f87 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 9 May 2018 19:21:03 +0000 Subject: [PATCH 2/2] Use the default value for an APITopologyOption if omitted --- app/api_topologies.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/api_topologies.go b/app/api_topologies.go index 047341a5d..1d1daa25b 100644 --- a/app/api_topologies.go +++ b/app/api_topologies.go @@ -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: @@ -518,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) }