Fix invalid references for progress page block
This commit is contained in:
@@ -181,6 +181,9 @@ func decodePageRefs(p *types.Page) (refs map[string]envoyx.Ref) {
|
||||
|
||||
case "Comment":
|
||||
refs = envoyx.MergeRefs(refs, getPageBlockCommentRefs(b, index))
|
||||
|
||||
case "Progress":
|
||||
refs = envoyx.MergeRefs(refs, getPageBlockProgressRefs(b, index))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/cortezaproject/corteza/server/compose/types"
|
||||
"github.com/cortezaproject/corteza/server/pkg/envoyx"
|
||||
"github.com/cortezaproject/corteza/server/pkg/y7s"
|
||||
"github.com/modern-go/reflect2"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
@@ -117,6 +118,9 @@ func (d *auxYamlDoc) unmarshalPageBlocksNode(r *types.Page, n *yaml.Node) (refs
|
||||
|
||||
case "Comment":
|
||||
refs = envoyx.MergeRefs(refs, getPageBlockCommentRefs(b, index))
|
||||
|
||||
case "Progress":
|
||||
refs = envoyx.MergeRefs(refs, getPageBlockProgressRefs(b, index))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,6 +207,49 @@ func getPageBlockCommentRefs(b types.PageBlock, index int) (refs map[string]envo
|
||||
return getPageBlockRecordListRefs(b, index)
|
||||
}
|
||||
|
||||
func getPageBlockProgressRefs(b types.PageBlock, index int) (refs map[string]envoyx.Ref) {
|
||||
refs = make(map[string]envoyx.Ref)
|
||||
var aux *envoyx.Ref
|
||||
|
||||
aux = getPageBlockProgressValueRefs(b.Options["minValue"])
|
||||
if aux != nil {
|
||||
refs[fmt.Sprintf("Blocks.%d.Options.minValue.ModuleID", index)] = *aux
|
||||
}
|
||||
|
||||
aux = getPageBlockProgressValueRefs(b.Options["maxValue"])
|
||||
if aux != nil {
|
||||
refs[fmt.Sprintf("Blocks.%d.Options.maxValue.ModuleID", index)] = *aux
|
||||
}
|
||||
|
||||
aux = getPageBlockProgressValueRefs(b.Options["value"])
|
||||
if aux != nil {
|
||||
refs[fmt.Sprintf("Blocks.%d.Options.value.ModuleID", index)] = *aux
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func getPageBlockProgressValueRefs(val any) (ref *envoyx.Ref) {
|
||||
if reflect2.IsNil(val) {
|
||||
return
|
||||
}
|
||||
|
||||
opt, ok := val.(map[string]interface{})
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
id := optString(opt, "module", "moduleID")
|
||||
if id == "" || id == "0" {
|
||||
return
|
||||
}
|
||||
|
||||
return &envoyx.Ref{
|
||||
ResourceType: types.ModuleResourceType,
|
||||
Identifiers: envoyx.MakeIdentifiers(id),
|
||||
}
|
||||
}
|
||||
|
||||
func getPageBlockRecordOrganizerRefs(b types.PageBlock, index int) (refs map[string]envoyx.Ref) {
|
||||
// Same difference
|
||||
return getPageBlockRecordListRefs(b, index)
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/cortezaproject/corteza/server/compose/types"
|
||||
"github.com/cortezaproject/corteza/server/pkg/envoyx"
|
||||
"github.com/cortezaproject/corteza/server/pkg/y7s"
|
||||
"github.com/modern-go/reflect2"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
@@ -225,11 +226,47 @@ func (e YamlEncoder) encodePageBlockC(ctx context.Context, p envoyx.EncodeParams
|
||||
b.Options["module"] = node.Identifiers.FriendlyIdentifier()
|
||||
delete(b.Options, "moduleID")
|
||||
break
|
||||
|
||||
case "Progress":
|
||||
err = e.encodeProgressPageblockVal("minValue", index, n, tt, &b)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = e.encodeProgressPageblockVal("maxValue", index, n, tt, &b)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = e.encodeProgressPageblockVal("value", index, n, tt, &b)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func (e YamlEncoder) encodeProgressPageblockVal(k string, index int, n *envoyx.Node, tt envoyx.Traverser, b *types.PageBlock) (err error) {
|
||||
if reflect2.IsNil(b.Options[k]) {
|
||||
return
|
||||
}
|
||||
|
||||
modRef := n.References[fmt.Sprintf("Blocks.%d.Options.%s.ModuleID", index, k)]
|
||||
node := tt.ParentForRef(n, modRef)
|
||||
if node == nil {
|
||||
err = fmt.Errorf("invalid module reference %v: module does not exist", modRef)
|
||||
return
|
||||
}
|
||||
|
||||
opt := b.Options[k].(map[string]any)
|
||||
opt["moduleID"] = node.Identifiers.FriendlyIdentifier()
|
||||
delete(opt, "moduleID")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (e YamlEncoder) cleanupPageblockRecordList(b types.PageBlock) (out types.PageBlock) {
|
||||
out = b
|
||||
rawFF, has := out.Options["fields"]
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/sql"
|
||||
"github.com/modern-go/reflect2"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/filter"
|
||||
"github.com/cortezaproject/corteza/server/pkg/locale"
|
||||
@@ -390,6 +391,16 @@ func (b *PageBlock) setValue(name string, pos uint, value any) (err error) {
|
||||
}
|
||||
|
||||
func (b *PageBlock) setOptionValue(path []string, pos uint, value any) (err error) {
|
||||
setProgressValue := func(k string) {
|
||||
v := make(map[string]any)
|
||||
if !reflect2.IsNil(b.Options[k]) {
|
||||
v = b.Options[k].(map[string]any)
|
||||
}
|
||||
|
||||
v["moduleID"] = cast.ToString(value)
|
||||
b.Options[k] = v
|
||||
}
|
||||
|
||||
switch path[0] {
|
||||
case "feeds":
|
||||
// Get the feed on the correct index in the correct type
|
||||
@@ -407,6 +418,15 @@ func (b *PageBlock) setOptionValue(path []string, pos uint, value any) (err erro
|
||||
|
||||
metric["moduleID"] = cast.ToString(value)
|
||||
|
||||
case "minValue":
|
||||
setProgressValue("minValue")
|
||||
|
||||
case "maxValue":
|
||||
setProgressValue("maxValue")
|
||||
|
||||
case "value":
|
||||
setProgressValue("value")
|
||||
|
||||
case "moduleID", "ModuleID":
|
||||
b.Options["moduleID"] = cast.ToString(value)
|
||||
|
||||
|
||||
@@ -234,7 +234,7 @@ func assertState(ctx context.Context, t *testing.T, s store.Storer, req *require
|
||||
pg1 := pages.FindByHandle("test_ns_1_page_1")
|
||||
req.NotNil(pg1)
|
||||
|
||||
req.Len(pg1.Blocks, 7)
|
||||
req.Len(pg1.Blocks, 8)
|
||||
// @todo test page block references
|
||||
// spew.Dump(pg1.Blocks)
|
||||
|
||||
|
||||
+5
@@ -78,6 +78,11 @@ namespace:
|
||||
kind: Comment
|
||||
options:
|
||||
module: test_ns_1_mod_1
|
||||
|
||||
- title: Test Namespace 1 Page 1 Block 8
|
||||
kind: Progress
|
||||
options:
|
||||
module: test_ns_1_mod_1
|
||||
pages:
|
||||
test_ns_1_record_page_1:
|
||||
title: Test Namespace 1 Record Page 1
|
||||
|
||||
Reference in New Issue
Block a user