From c7b83a161c6c64b4813a99a872cc8df744979bd3 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 24 Oct 2024 20:36:51 +0800 Subject: [PATCH] Add default value for Upload API if not provided in props --- widgets/component/component.go | 5 +++++ widgets/component/props.go | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/widgets/component/component.go b/widgets/component/component.go index 4d0a36f0..d7b4548e 100644 --- a/widgets/component/component.go +++ b/widgets/component/component.go @@ -28,6 +28,11 @@ func (dsl DSL) Map() map[string]interface{} { "props": map[string]interface{}(dsl.Props), } + // Add Default Value for Upload api + if dsl.Type == "Upload" && dsl.Props != nil && !dsl.Props.Has("api") { + res["props"].(map[string]interface{})["$api"] = map[string]interface{}{"process": "fs.data.Upload"} + } + if dsl.HideLabel { res["hideLabel"] = true } diff --git a/widgets/component/props.go b/widgets/component/props.go index bd68e9fe..50628413 100644 --- a/widgets/component/props.go +++ b/widgets/component/props.go @@ -179,6 +179,18 @@ func (p PropsDSL) parseCloudProps(xpath string, component string, props map[stri return res, nil } +// Has check if the prop exists in the props +func (p PropsDSL) Has(name string) bool { + _, has := p[name] + if has { + return has + } + + // check if the prop is a cloud prop + _, has = p[fmt.Sprintf("$%s", name)] + return has +} + // Parse parse cloud props func (cProp *CloudPropsDSL) Parse(v interface{}) error {