Fix config import (broken automation buttons)
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
@@ -214,7 +215,7 @@ func (pImp *Page) castBlocks(page *types.Page, def interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
page.Blocks = append(page.Blocks, block)
|
||||
page.Blocks = append(page.Blocks, pImp.sanitizeBlock(block))
|
||||
return
|
||||
})
|
||||
}
|
||||
@@ -246,6 +247,31 @@ func (pImp *Page) castBlockStyle(page *types.Page, n int, def interface{}) (s ty
|
||||
})
|
||||
}
|
||||
|
||||
func (pImp *Page) sanitizeBlock(b types.PageBlock) types.PageBlock {
|
||||
switch strings.ToLower(b.Kind) {
|
||||
case "automation":
|
||||
return pImp.sanitizeAutomationBlock(b)
|
||||
}
|
||||
|
||||
return b
|
||||
}
|
||||
|
||||
func (pImp *Page) sanitizeAutomationBlock(b types.PageBlock) types.PageBlock {
|
||||
b.Options["sealed"] = deinterfacer.ToBool(b.Options["sealed"], false)
|
||||
|
||||
bb := deinterfacer.ToSliceOfStringToInterfaceMap(b.Options["buttons"])
|
||||
|
||||
for b := range bb {
|
||||
bb[b]["enabled"] = deinterfacer.ToBool(bb[b]["enabled"], true)
|
||||
bb[b]["variant"] = deinterfacer.ToString(bb[b]["variant"], "primary")
|
||||
bb[b]["resourceType"] = deinterfacer.ToString(bb[b]["resourceType"], "compose:record")
|
||||
}
|
||||
|
||||
b.Options["buttons"] = bb
|
||||
|
||||
return b
|
||||
}
|
||||
|
||||
// Get existing pages
|
||||
func (pImp *Page) Get(handle string) (*types.Page, error) {
|
||||
handle = importer.NormalizeHandle(handle)
|
||||
|
||||
@@ -38,6 +38,31 @@ func TestPageImport_CastSet(t *testing.T) {
|
||||
Kind: "TheTestingKind",
|
||||
XYWH: [4]int{11, 12, 13, 14},
|
||||
},
|
||||
{
|
||||
Title: "Automation",
|
||||
Options: map[string]interface{}{
|
||||
"sealed": false,
|
||||
"buttons": []map[string]interface{}{
|
||||
{
|
||||
"label": "Lead-2-Account",
|
||||
"script": "ToAccount.js:default",
|
||||
"variant": "secondary",
|
||||
"resourceType": "compose:record",
|
||||
"enabled": false,
|
||||
},
|
||||
{
|
||||
"label": "Defaults",
|
||||
"script": "Defaults.js:default",
|
||||
"variant": "primary",
|
||||
"resourceType": "compose:record",
|
||||
"enabled": true,
|
||||
},
|
||||
},
|
||||
},
|
||||
Style: types.PageBlockStyle{},
|
||||
Kind: "Automation",
|
||||
XYWH: [4]int{21, 22, 23, 24},
|
||||
},
|
||||
})
|
||||
|
||||
sub2 := page.set.FindByHandle("sub2")
|
||||
|
||||
+11
@@ -12,6 +12,17 @@ pages:
|
||||
- title: B2
|
||||
xywh: [ 11, 12, 13, 14 ]
|
||||
kind: TheTestingKind
|
||||
- title: Automation
|
||||
xywh: [ 21, 22, 23, 24 ]
|
||||
kind: Automation
|
||||
options:
|
||||
buttons:
|
||||
- label: Lead-2-Account
|
||||
script: ToAccount.js:default
|
||||
variant: secondary
|
||||
enabled: false
|
||||
- label: Defaults
|
||||
script: Defaults.js:default
|
||||
- handle: sub2
|
||||
title: Sub page 2
|
||||
pages:
|
||||
|
||||
Reference in New Issue
Block a user