From 35f166c546ec042ecb12f37c2d3caf8d645bdba2 Mon Sep 17 00:00:00 2001 From: Kiyoshi Guo <44930252+Kiyo5hi@users.noreply.github.com> Date: Wed, 26 Jul 2023 19:14:04 +0800 Subject: [PATCH] fix(*): trivial fix for unique keys --- pkg/ui/flat/events.go | 2 +- pkg/ui/flat/page.go | 16 ++++++++++------ pkg/ui/flat/utils.go | 5 +++++ pkg/ui/props.go | 2 ++ 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/pkg/ui/flat/events.go b/pkg/ui/flat/events.go index b4d2c32..e9356d6 100644 --- a/pkg/ui/flat/events.go +++ b/pkg/ui/flat/events.go @@ -10,7 +10,7 @@ import ( ) type UpdateSubcommandParams[T string | ui.Path] struct { - Path T `json:"path"` + Path T `json:"myPath"` Subcommand string `json:"subcommand"` } diff --git a/pkg/ui/flat/page.go b/pkg/ui/flat/page.go index 100bb86..1a48973 100644 --- a/pkg/ui/flat/page.go +++ b/pkg/ui/flat/page.go @@ -488,8 +488,8 @@ func (u UI) commandMenu() sunmao.BaseComponentBuilder { Method: sunmao.EventMethod{ Name: "binding/v1/UpdateSubcommand", Parameters: UpdateSubcommandParams[string]{ - Path: "{{ SubcommandMenuTree.selectedNodes[0].path }}", - Subcommand: "{{ SubcommandMenuTree.selectedKeys[0] }}", + Path: "{{ SubcommandMenuTree.selectedNodes[0].myPath }}", + Subcommand: "{{ SubcommandMenuTree.selectedNodes[0].subcommand }}", }, }, }, @@ -497,16 +497,20 @@ func (u UI) commandMenu() sunmao.BaseComponentBuilder { } func (u UI) menuItems() []ui.TreeNodeProperties { - return menuItems(u.CLIs[0].Command, []ui.TreeNodeProperties{}) + p := Path{} + return menuItems(u.CLIs[0].Command, []ui.TreeNodeProperties{}, p) } -func menuItems(c config.Command, i []ui.TreeNodeProperties) []ui.TreeNodeProperties { +func menuItems(c config.Command, i []ui.TreeNodeProperties, p Path) []ui.TreeNodeProperties { for _, sc := range c.Subcommands { + path := Path{p.Append(sc.Name)} tnp := ui.TreeNodeProperties{ Title: sc.DisplayName(), - Key: sc.Name, - Children: menuItems(sc, []ui.TreeNodeProperties{}), + Key: path.menuItemKey(), + Children: menuItems(sc, []ui.TreeNodeProperties{}, path), + Subcommand: sc.Name, Selectable: true, + MyPath: path.Path, } i = append(i, tnp) } diff --git a/pkg/ui/flat/utils.go b/pkg/ui/flat/utils.go index 6997c0c..ab0a37c 100644 --- a/pkg/ui/flat/utils.go +++ b/pkg/ui/flat/utils.go @@ -2,8 +2,13 @@ package flat import ( "CLI2UI/pkg/ui" + "fmt" ) type Path struct { ui.Path } + +func (p Path) menuItemKey() string { + return fmt.Sprintf("MenuItem%s", p) +} diff --git a/pkg/ui/props.go b/pkg/ui/props.go index 4c3e766..c0cfcf0 100644 --- a/pkg/ui/props.go +++ b/pkg/ui/props.go @@ -196,6 +196,8 @@ type TreeNodeProperties struct { Children []TreeNodeProperties `json:"children"` Selectable bool `json:"selectable"` Checkable bool `json:"checkable"` + Subcommand string `json:"subcommand"` + MyPath Path `json:"myPath"` } type TreeProperties struct {