Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(*): trivial fix for unique keys #40

Merged
merged 5 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM docker.io/library/node:lts AS client

WORKDIR /src
COPY ./ui .

RUN rm yarn.lock && yarn install && yarn build

FROM docker.io/library/golang:1.19 AS binary

WORKDIR /src
COPY . .
COPY --from=client /src/dist /src/ui/dist

RUN CGO_ENABLED=0 go build -o cli2ui cmd/main.go

FROM gcr.io/distroless/static-debian11:latest

COPY --from=binary /src/cli2ui /

ENTRYPOINT [ "/cli2ui" ]
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
28 changes: 17 additions & 11 deletions pkg/ui/flat/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package flat
import (
"CLI2UI/pkg/config"
"CLI2UI/pkg/ui"
"encoding/json"
"fmt"

"github.com/yuyz0112/sunmao-ui-go-binding/pkg/sunmao"
Expand Down Expand Up @@ -69,7 +70,7 @@ func (u UI) optionSection() sunmao.BaseComponentBuilder {
Children(map[string][]sunmao.BaseComponentBuilder{
"content": {
u.commandStack(Path{}, u.CLIs[0].Command),
u.checkbox(Path{}, u.CLIs[0].Command),
u.checkbox(u.CLIs[0].Command),
u.Arco.NewStack(),
u.buttons(),
},
Expand Down Expand Up @@ -173,7 +174,7 @@ func (u UI) dryRunButton() sunmao.BaseComponentBuilder {
})
}

func (u UI) checkbox(p Path, c config.Command) sunmao.BaseComponentBuilder {
func (u UI) checkbox(c config.Command) sunmao.BaseComponentBuilder {
container := u.Arco.NewStack().
Id("CheckboxWrapper").
Properties(ui.StructToMap(ui.StackProperties{
Expand All @@ -191,7 +192,7 @@ func (u UI) checkbox(p Path, c config.Command) sunmao.BaseComponentBuilder {
min-width: 8rem;
`).
Children(map[string][]sunmao.BaseComponentBuilder{
"content": {u.checkboxStack(p, c)},
"content": {u.checkboxStack(Path{}, c)},
})

return container
Expand All @@ -216,11 +217,12 @@ func (u UI) checkboxStack(p Path, c config.Command) *sunmao.StackComponentBuilde

for _, sc := range c.Subcommands {
path := p.Append(sc.Name)
ps, _ := json.Marshal(path)
items := u.checkboxStack(Path{path}, sc).
Slot(sunmao.Container{
ID: "CheckboxWrapper",
Slot: "content",
}, fmt.Sprintf("{{ path.state.some(o => o === \"%s\") }}", sc.Name))
}, fmt.Sprintf("{{ %s.every(v => path.state.includes(v)) }}", string(ps)))
cs = append(cs, items)
}

Expand Down Expand Up @@ -488,25 +490,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{}),
Selectable: true,
Key: path.menuItemKey(),
Children: menuItems(sc, []ui.TreeNodeProperties{}, path),
Subcommand: sc.Name,
Selectable: "{{ !exec.state.isRunning }}",
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)
}
4 changes: 3 additions & 1 deletion pkg/ui/props.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,10 @@ type TreeNodeProperties struct {
Title string `json:"title"`
Key string `json:"key"`
Children []TreeNodeProperties `json:"children"`
Selectable bool `json:"selectable"`
Selectable any `json:"selectable"`
Checkable bool `json:"checkable"`
Subcommand string `json:"subcommand"`
MyPath Path `json:"myPath"`
}

type TreeProperties struct {
Expand Down
88 changes: 88 additions & 0 deletions samples/cloudtower-admin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# yaml-language-server: $schema=../cli.schema.json
name: CloudTower Admin
command:
name: ./cloudtower-admin
display: CloudTower Admin
flags:
- name: v
display: Verbosity
type: enum
options:
- "0"
- "1"
- "2"
- "3"
- "4"
subcommands:
- name: deploy
display: Deploy
- name: diagnose
display: Diagnose
- name: logs
display: Logs
subcommands:
- name: k8s
display: 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
display: 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
display: 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
display: Upgrade
args:
- name: path
display: Path
description: Path to upgrade.tar.gz
type: string