Skip to content

Commit

Permalink
[add] syntactic sugar action.hide
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Jan 18, 2023
1 parent d489feb commit b81eb75
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
25 changes: 25 additions & 0 deletions widgets/component/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
Expand Down
2 changes: 2 additions & 0 deletions widgets/component/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit b81eb75

Please sign in to comment.