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

feat: add remaining text input models #36

Closed
Closed
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
30 changes: 30 additions & 0 deletions internal/setup/environments.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type environmentModel struct {
err error
list list.Model
parentKey string
showInput bool
textInput tea.Model
}

var environments = map[string][]environment{
Expand Down Expand Up @@ -89,6 +91,25 @@ func (p environmentModel) Init() tea.Cmd {

func (m environmentModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
if m.showInput {
m.textInput, cmd = m.textInput.Update(msg)
switch msg := msg.(type) {
case tea.KeyMsg:
switch {
case key.Matches(msg, keys.Enter):
iModel, ok := m.textInput.(inputModel)
if ok {
m.choice = iModel.textInput.Value()
m.showInput = false
}

environments[m.parentKey] = append(environments[m.parentKey], environment{Key: m.choice, Name: m.choice})
}
default:

}
return m, cmd
}
switch msg := msg.(type) {
case fetchResources:
envs, err := getEnvironments(m.parentKey)
Expand All @@ -102,6 +123,11 @@ func (m environmentModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case key.Matches(msg, keys.Enter):
i, ok := m.list.SelectedItem().(environment)
if ok {
if i.Key == CreateNewResourceKey {
iModel := newTextInputModel("desired-env-key", "Enter environment key")
m.textInput = iModel
m.showInput = true
}
m.choice = i.Key
}
case key.Matches(msg, keys.Quit):
Expand All @@ -115,6 +141,10 @@ func (m environmentModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

func (m environmentModel) View() string {
if m.showInput {
return m.textInput.View()
}

return "\n" + m.list.View()
}

Expand Down
30 changes: 30 additions & 0 deletions internal/setup/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type flagModel struct {
err error
list list.Model
parentKey string
showInput bool
textInput tea.Model
}

var flags = map[string][]flag{
Expand Down Expand Up @@ -113,6 +115,25 @@ func (p flagModel) Init() tea.Cmd {
// This method has drifted from the ProjectModel's version, but it should do something similar.
func (m flagModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
if m.showInput {
m.textInput, cmd = m.textInput.Update(msg)
switch msg := msg.(type) {
case tea.KeyMsg:
switch {
case key.Matches(msg, keys.Enter):
iModel, ok := m.textInput.(inputModel)
if ok {
m.choice = iModel.textInput.Value()
m.showInput = false
}

flags[m.parentKey] = append(flags[m.parentKey], flag{Key: m.choice, Name: m.choice})
}
default:

}
return m, cmd
}
switch msg := msg.(type) {
case fetchResources:
fs, err := getFlags(m.parentKey)
Expand All @@ -126,6 +147,11 @@ func (m flagModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case key.Matches(msg, keys.Enter):
i, ok := m.list.SelectedItem().(flag)
if ok {
if i.Key == CreateNewResourceKey {
iModel := newTextInputModel("desired-flag-key", "Enter flag key")
m.textInput = iModel
m.showInput = true
}
m.choice = i.Key
}
case key.Matches(msg, keys.Quit):
Expand All @@ -139,6 +165,10 @@ func (m flagModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

func (m flagModel) View() string {
if m.showInput {
return m.textInput.View()
}

return "\n" + m.list.View()
}

Expand Down
5 changes: 2 additions & 3 deletions internal/setup/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,11 @@ func (m projectModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
i, ok := m.list.SelectedItem().(project)
if ok {
if i.Key == CreateNewResourceKey {
iModel := newTextInputModel("desired-proj-key", "Enter project name")
iModel := newTextInputModel("desired-proj-key", "Enter project key")
m.textInput = iModel
m.showInput = true
} else {
m.choice = i.Key
}
m.choice = i.Key
}
case key.Matches(msg, keys.Quit):
return m, tea.Quit
Expand Down
2 changes: 1 addition & 1 deletion internal/setup/sdk_build_instructions/js.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const flagKey = 'my-flag-key';

2. Open `index.html` in your browser.

You should receive the message "Feature flag key '<flag key>' is <true/false> for this user".
You should receive the message "Feature flag key 'my-flag-key' is <true/false> for this user".
30 changes: 18 additions & 12 deletions internal/setup/wizard.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,30 +113,36 @@ func (m WizardModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
case environmentsStep:
envModel, _ := m.steps[environmentsStep].Update(msg)
p, ok := envModel.(environmentModel)
e, ok := envModel.(environmentModel)
if ok {
m.currEnvironmentKey = p.choice
// pre-load flags based on environment selected
fModel := m.steps[flagsStep]
f, ok := fModel.(flagModel)
if ok {
f.parentKey = m.currEnvironmentKey
m.steps[flagsStep], _ = f.Update(fetchResources{})
m.currStep += 1
m.currEnvironmentKey = e.choice
m.steps[environmentsStep] = e
if !e.showInput {
// pre-load flags based on environment selected
fModel := m.steps[flagsStep]
f, ok := fModel.(flagModel)
if ok {
f.parentKey = m.currEnvironmentKey
m.steps[flagsStep], _ = f.Update(fetchResources{})
m.currStep += 1
}
}
}
case flagsStep:
model, _ := m.steps[flagsStep].Update(msg)
f, ok := model.(flagModel)
if ok {
m.currFlagKey = f.choice
m.currStep += 1
m.steps[flagsStep] = f
if !f.showInput {
m.currStep += 1
}
}
case sdksStep:
model, _ := m.steps[sdksStep].Update(msg)
f, ok := model.(sdkModel)
s, ok := model.(sdkModel)
if ok {
m.currSdk = f.choice
m.currSdk = s.choice
m.currStep += 1
}
// add additional cases for additional steps
Expand Down
Loading