From 032566d9021777ac2e2e054e9869c0d41458800a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Jerman?= Date: Fri, 5 Nov 2021 08:57:05 +0100 Subject: [PATCH] Fix compose page YAML marshal for unconfigured page blocks --- pkg/envoy/resource/compose_page.go | 14 +++++++------- pkg/envoy/yaml/compose_page_marshal.go | 20 ++++++++++++++++---- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/pkg/envoy/resource/compose_page.go b/pkg/envoy/resource/compose_page.go index 900f23e48..e5ee2e57c 100644 --- a/pkg/envoy/resource/compose_page.go +++ b/pkg/envoy/resource/compose_page.go @@ -245,7 +245,7 @@ func (r *ComposePage) optString(opt map[string]interface{}, kk ...string) string func (r *ComposePage) pbRecordList(opt map[string]interface{}) (out *Ref) { id := r.optString(opt, "module", "moduleID") - if id == "" { + if id == "" || id == "0" { return } @@ -254,7 +254,7 @@ func (r *ComposePage) pbRecordList(opt map[string]interface{}) (out *Ref) { func (r *ComposePage) pbComment(opt map[string]interface{}) (out *Ref) { id := r.optString(opt, "module", "moduleID") - if id == "" { + if id == "" || id == "0" { return } @@ -263,7 +263,7 @@ func (r *ComposePage) pbComment(opt map[string]interface{}) (out *Ref) { func (r *ComposePage) pbAutomation(opt map[string]interface{}) (out *Ref) { id := r.optString(opt, "workflow", "workflowID") - if id == "" { + if id == "" || id == "0" { return } @@ -272,7 +272,7 @@ func (r *ComposePage) pbAutomation(opt map[string]interface{}) (out *Ref) { func (r *ComposePage) pbRecordOrganizer(opt map[string]interface{}) (out *Ref) { id := r.optString(opt, "module", "moduleID") - if id == "" { + if id == "" || id == "0" { return } @@ -281,7 +281,7 @@ func (r *ComposePage) pbRecordOrganizer(opt map[string]interface{}) (out *Ref) { func (r *ComposePage) pbChart(opt map[string]interface{}) (out *Ref) { id := r.optString(opt, "chart", "chartID") - if id == "" { + if id == "" || id == "0" { return } @@ -290,7 +290,7 @@ func (r *ComposePage) pbChart(opt map[string]interface{}) (out *Ref) { func (r *ComposePage) pbCalendar(opt map[string]interface{}) (out *Ref) { id := r.optString(opt, "module", "moduleID") - if id == "" { + if id == "" || id == "0" { return } @@ -299,7 +299,7 @@ func (r *ComposePage) pbCalendar(opt map[string]interface{}) (out *Ref) { func (r *ComposePage) pbMetric(opt map[string]interface{}) (out *Ref) { id := r.optString(opt, "module", "moduleID") - if id == "" { + if id == "" || id == "0" { return } diff --git a/pkg/envoy/yaml/compose_page_marshal.go b/pkg/envoy/yaml/compose_page_marshal.go index 804516f24..e538d4dbf 100644 --- a/pkg/envoy/yaml/compose_page_marshal.go +++ b/pkg/envoy/yaml/compose_page_marshal.go @@ -188,17 +188,26 @@ func (c *composePageBlock) MarshalYAML() (interface{}, error) { opt := c.res.Options switch c.res.Kind { case "RecordList": - opt["moduleID"] = c.refMod[0] + delete(opt, "moduleID") + if len(c.refMod) > 0 { + opt["moduleID"] = c.refMod[0] + } delete(opt, "module") break case "RecordOrganizer": - opt["moduleID"] = c.refMod[0] + delete(opt, "moduleID") + if len(c.refMod) > 0 { + opt["moduleID"] = c.refMod[0] + } delete(opt, "module") break case "Chart": - opt["chartID"] = c.refChart[0] + delete(opt, "chartID") + if len(c.refChart) > 0 { + opt["chartID"] = c.refChart[0] + } delete(opt, "chart") break @@ -237,7 +246,10 @@ func (c *composePageBlock) MarshalYAML() (interface{}, error) { break case "Comment": - opt["moduleID"] = c.refMod[0] + delete(opt, "moduleID") + if len(c.refMod) > 0 { + opt["moduleID"] = c.refMod[0] + } delete(opt, "module") break