diff --git a/internal/setup/environments.go b/internal/setup/environments.go index 02b24f2c..0eb99e36 100644 --- a/internal/setup/environments.go +++ b/internal/setup/environments.go @@ -30,6 +30,8 @@ type environmentModel struct { err error list list.Model parentKey string + showInput bool + textInput tea.Model } var environments = map[string][]environment{ @@ -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) @@ -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): @@ -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() } diff --git a/internal/setup/flags.go b/internal/setup/flags.go index c5d2f175..8d2988d4 100644 --- a/internal/setup/flags.go +++ b/internal/setup/flags.go @@ -30,6 +30,8 @@ type flagModel struct { err error list list.Model parentKey string + showInput bool + textInput tea.Model } var flags = map[string][]flag{ @@ -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) @@ -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): @@ -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() } diff --git a/internal/setup/projects.go b/internal/setup/projects.go index 75b8f783..24548cdd 100644 --- a/internal/setup/projects.go +++ b/internal/setup/projects.go @@ -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 diff --git a/internal/setup/sdk_build_instructions/js.md b/internal/setup/sdk_build_instructions/js.md index 5b7eb4a5..7d71d08b 100644 --- a/internal/setup/sdk_build_instructions/js.md +++ b/internal/setup/sdk_build_instructions/js.md @@ -8,4 +8,4 @@ const flagKey = 'my-flag-key'; 2. Open `index.html` in your browser. -You should receive the message "Feature flag key '' is for this user". \ No newline at end of file +You should receive the message "Feature flag key 'my-flag-key' is for this user". \ No newline at end of file diff --git a/internal/setup/wizard.go b/internal/setup/wizard.go index 15238487..33ce179e 100644 --- a/internal/setup/wizard.go +++ b/internal/setup/wizard.go @@ -113,16 +113,19 @@ 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: @@ -130,13 +133,16 @@ func (m WizardModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { 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