Skip to content

Commit

Permalink
fix(*): trivial fix for unique keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiyo5hi committed Jul 26, 2023
1 parent 9a4bfc5 commit 35f166c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/ui/flat/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

type UpdateSubcommandParams[T string | ui.Path] struct {
Path T `json:"path"`
Path T `json:"myPath"`
Subcommand string `json:"subcommand"`
}

Expand Down
16 changes: 10 additions & 6 deletions pkg/ui/flat/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,25 +488,29 @@ 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 }}",
},
},
},
})
}

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)
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/ui/flat/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 2 additions & 0 deletions pkg/ui/props.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 35f166c

Please sign in to comment.