3
0

Fix RecordList field selection export

This commit is contained in:
Tomaž Jerman
2021-09-28 17:33:31 +02:00
committed by Denis Arh
parent 2936fda461
commit 74d7c6c7a2
2 changed files with 25 additions and 11 deletions

View File

@@ -262,19 +262,14 @@ func (c *composePageBlock) cleanupModuleFields(opt map[string]interface{}) {
retFF := make([]interface{}, 0, len(ff))
for _, rawF := range ff {
f, ok := rawF.(map[string]interface{})
if !ok {
switch c := rawF.(type) {
case string:
retFF = append(retFF, map[string]interface{}{"name": c})
case map[string]interface{}, map[string]string:
retFF = append(retFF, c)
default:
retFF = append(retFF, rawF)
continue
}
fn, has := f["name"]
if !has {
retFF = append(retFF, rawF)
continue
}
retFF = append(retFF, fn)
}
opt["fields"] = retFF

View File

@@ -2,6 +2,7 @@ package envoy
import (
"context"
"fmt"
"strconv"
"testing"
@@ -322,6 +323,10 @@ func TestStoreYaml_pageRefs(t *testing.T) {
Kind: "RecordList",
Options: map[string]interface{}{
"module": strconv.FormatUint(mod.ID, 10),
"fields": []map[string]interface{}{
{"name": "f1"},
{"name": "f2"},
},
},
},
{
@@ -329,6 +334,10 @@ func TestStoreYaml_pageRefs(t *testing.T) {
Kind: "RecordList",
Options: map[string]interface{}{
"moduleID": strconv.FormatUint(mod.ID, 10),
"fields": []map[string]interface{}{
{"name": "f1"},
{"name": "f2"},
},
},
},
},
@@ -363,10 +372,20 @@ func TestStoreYaml_pageRefs(t *testing.T) {
// provided as module
b := pg.Blocks[0]
req.Equal(strconv.FormatUint(mod.ID, 10), b.Options["moduleID"])
casted := b.Options["fields"].([]interface{})
for i, c := range casted {
cc := c.(map[string]interface{})
req.Equal(fmt.Sprintf("f%d", i+1), cc["name"].(string))
}
// provided as moduleID
b = pg.Blocks[1]
req.Equal(strconv.FormatUint(mod.ID, 10), b.Options["moduleID"])
casted = b.Options["fields"].([]interface{})
for i, c := range casted {
cc := c.(map[string]interface{})
req.Equal(fmt.Sprintf("f%d", i+1), cc["name"].(string))
}
},
},