Skip to content

Commit

Permalink
Merge pull request #765 from trheyi/main
Browse files Browse the repository at this point in the history
Add default value for Upload API if not provided in props
  • Loading branch information
trheyi authored Oct 24, 2024
2 parents d08d60a + c7b83a1 commit 2a070f6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions widgets/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 12 additions & 0 deletions widgets/component/props.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down

0 comments on commit 2a070f6

Please sign in to comment.