Skip to content

Commit

Permalink
Merge pull request #43 from webzard-io/x6guo/dump-log
Browse files Browse the repository at this point in the history
feat(input): injected default values
  • Loading branch information
Yuyz0112 authored Aug 22, 2023
2 parents 47d5e21 + d2355bf commit 511f55a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 25 deletions.
67 changes: 42 additions & 25 deletions pkg/ui/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,17 @@ func (u BaseUI) stringComponent(o config.Option, p Path) (sunmao.BaseComponentBu
var comp sunmao.BaseComponentBuilder
vs := []Validator[string]{}

props := InputProperties[string]{
Size: "default",
Disabled: "{{ exec.state.isRunning }}",
}
if o.Default != nil {
props.DefaultValue = o.Default.(string)
}

comp = u.Arco.NewInput().
Id(p.OptionValueInputId(o.Name)).
Properties(StructToMap(InputProperties[string]{
Size: "default",
Disabled: "{{ exec.state.isRunning }}",
})).
Properties(StructToMap(props)).
Event(UpdateValueEvent("value", p, o))

switch o.Annotations.Format {
Expand All @@ -156,14 +161,18 @@ func (u BaseUI) InputType(p Path, o config.Option) sunmao.BaseComponentBuilder {
// TODO(xinxi.guo): typeComponent() will ultimately replace all these
switch o.Type {
case config.OptionTypeNumber:
props := NumberInputProperties[string]{
Size: "default",
Max: 99,
Step: 1,
Disabled: "{{ exec.state.isRunning }}",
}
if o.Default != nil {
props.DefaultValue = o.Default.(int)
}
return u.Arco.NewNumberInput().
Id(p.OptionValueInputId(o.Name)).
Properties(StructToMap(NumberInputProperties[string]{
Size: "default",
Max: 99,
Step: 1,
Disabled: "{{ exec.state.isRunning }}",
})).
Properties(StructToMap(props)).
Event(UpdateValueEvent("value", p, o))
case config.OptionTypeArray:
return u.C2U.NewArrayInput().
Expand All @@ -175,13 +184,17 @@ func (u BaseUI) InputType(p Path, o config.Option) sunmao.BaseComponentBuilder {
})).
Event(UpdateValueEvent("value", p, o))
case config.OptionTypeBoolean:
props := SwitchProperties[string]{
Type: "circle",
Size: "default",
Disabled: "{{ exec.state.isRunning }}",
}
if o.Default != nil {
props.DefaultChecked = o.Default.(bool)
}
return u.Arco.NewSwitch().
Id(p.OptionValueInputId(o.Name)).
Properties(StructToMap(SwitchProperties[string]{
Type: "circle",
Size: "default",
Disabled: "{{ exec.state.isRunning }}",
})).
Properties(StructToMap(props)).
Event(UpdateValueEvent("value", p, o))
case config.OptionTypeEnum:
options := []SelectOptionProperties{}
Expand All @@ -191,18 +204,22 @@ func (u BaseUI) InputType(p Path, o config.Option) sunmao.BaseComponentBuilder {
Value: o,
})
}
props := SelectProperties[string]{
Bordered: true,
UnmountOnExit: true,
Options: options,
Size: "default",
AutoAlignPopupWidth: true,
Position: "bottom",
MountToBody: true,
Disabled: "{{ exec.state.isRunning }}",
}
if o.Default != nil {
props.DefaultValue = o.Default.(string)
}
return u.Arco.NewSelect().
Id(p.OptionValueInputId(o.Name)).
Properties(StructToMap(SelectProperties[string]{
Bordered: true,
UnmountOnExit: true,
Options: options,
Size: "default",
AutoAlignPopupWidth: true,
Position: "bottom",
MountToBody: true,
Disabled: "{{ exec.state.isRunning }}",
})).
Properties(StructToMap(props)).
Event(UpdateValueEvent("value", p, o))
}

Expand Down
1 change: 1 addition & 0 deletions samples/curl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ command:
flags:
- name: L
type: boolean
default: true
- name: o
type: string
args:
Expand Down
2 changes: 2 additions & 0 deletions samples/ping.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ command:
flags:
- name: c
type: number
default: 2
args:
- name: host
type: string
required: true
default: 114.114.114.114

0 comments on commit 511f55a

Please sign in to comment.