Merge pull request #317 from trheyi/main

[add] syntactic sugar action.hide
This commit is contained in:
Max 2023-01-18 15:18:39 +08:00 committed by GitHub
commit e8e96bb4f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View file

@ -23,6 +23,31 @@ func (action *ActionDSL) UnmarshalJSON(data []byte) error {
return err
}
// Syntactic sugar { "hide": ["add", "edit", "view"] }
// ["add", "edit", "view"]
if action.Hide != nil {
// set default value
action.ShowWhenAdd = true // shown in add form
action.ShowWhenView = true // shown in view form
action.HideWhenEdit = false // shown in edit form
for _, kind := range action.Hide {
kind = strings.ToLower(kind)
switch kind {
case "add":
action.ShowWhenAdd = false
break
case "view":
action.ShowWhenView = false
break
case "edit":
action.HideWhenEdit = true
break
}
}
}
if action.Action == nil {
action.Action = ActionNodes{}
}

View file

@ -40,8 +40,10 @@ type ActionDSL struct {
Style string `json:"style,omitempty"`
Xpath string `json:"xpath,omitempty"`
DivideLine bool `json:"divideLine,omitempty"`
Hide []string `json:"hide,omitempty"` // Syntactic sugar ["add", "edit", "view"]
ShowWhenAdd bool `json:"showWhenAdd,omitempty"`
ShowWhenView bool `json:"showWhenView,omitempty"`
HideWhenEdit bool `json:"hideWhenEdit,omitempty"`
Props PropsDSL `json:"props,omitempty"`
Confirm *ConfirmActionDSL `json:"confirm,omitempty"`
Action ActionNodes `json:"action,omitempty"`