From c993fdad94fffaae6af4a0c31c679a760da2181e 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 + samples/cloudtower-admin.yaml | 72 +++++++++++++++++++++++++++++++++++ 5 files changed, 90 insertions(+), 7 deletions(-) create mode 100644 samples/cloudtower-admin.yaml 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 { diff --git a/samples/cloudtower-admin.yaml b/samples/cloudtower-admin.yaml new file mode 100644 index 0000000..e074b42 --- /dev/null +++ b/samples/cloudtower-admin.yaml @@ -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