From b81eb750a3c1f27bc2da045eadb2b7d0f556e7ba Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 18 Jan 2023 15:09:59 +0800 Subject: [PATCH] [add] syntactic sugar action.hide --- widgets/component/action.go | 25 +++++++++++++++++++++++++ widgets/component/types.go | 2 ++ 2 files changed, 27 insertions(+) diff --git a/widgets/component/action.go b/widgets/component/action.go index da492f2180..b720c7aa67 100644 --- a/widgets/component/action.go +++ b/widgets/component/action.go @@ -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{} } diff --git a/widgets/component/types.go b/widgets/component/types.go index 88d062bd50..44939107da 100644 --- a/widgets/component/types.go +++ b/widgets/component/types.go @@ -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"`