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 c993fda
Show file tree
Hide file tree
Showing 5 changed files with 90 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
72 changes: 72 additions & 0 deletions samples/cloudtower-admin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# yaml-language-server: $schema=../cli.schema.json
name: CloudTower Admin
command:
name: ./cloudtower-admin
display: CloudTower Admin
subcommands:
- name: deploy
display: Deploy
- name: diagnose
display: diagnose
- name: logs
display: Logs
subcommands:
- name: k8s
args:
- name: Service
type: enum
required: true
options:
- agent-mesh-hub
- import-data
- observer
- openresty
- postgres
- prepare-static
- prisma
- prisma-worker
- rollback
- server
flags:
- name: f
display: Follow
type: boolean
- name: ps
display: Show Status
subcommands:
- name: host
args:
- name: Service
type: enum
required: true
options:
- containerd
- kubelet
flags:
- name: o
display: Output Format
type: enum
options:
- table
- json
- yaml
- name: k8s
args:
- name: Service
type: enum
required: true
options:
- agent-mesh-hub
- import-data
- observer
- openresty
- postgres
- prepare-static
- prisma
- prisma-worker
- rollback
- server
- name: upgrade
args:
- name: path-to-upgrade-bundle
type: string

0 comments on commit c993fda

Please sign in to comment.