From 9e6d396a0e9fc13c4e6b0f9f030fc2db737147be Mon Sep 17 00:00:00 2001 From: Kelly Hofmann Date: Tue, 19 Mar 2024 11:34:22 -0700 Subject: [PATCH 1/3] add text input model to environments --- internal/setup/environments.go | 32 ++++++++++++++++++++++++++++++++ internal/setup/wizard.go | 21 ++++++++++++--------- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/internal/setup/environments.go b/internal/setup/environments.go index 02b24f2c..85b95a39 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,27 @@ func (p environmentModel) Init() tea.Cmd { func (m environmentModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmd tea.Cmd + // if we've selected the option to create a new project, delegate to the textInput model + if m.showInput { + m.textInput, cmd = m.textInput.Update(msg) + // catch the enter key here to update the projectModel when a final value is provided + 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 +125,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 +143,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/wizard.go b/internal/setup/wizard.go index 15238487..dfaeca76 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: From cc550e3bcd1f182454265ae4fdfe2ed4288a2f18 Mon Sep 17 00:00:00 2001 From: Kelly Hofmann Date: Tue, 19 Mar 2024 11:35:13 -0700 Subject: [PATCH 2/3] small copy changes --- internal/setup/projects.go | 5 ++--- internal/setup/sdk_build_instructions/js.md | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) 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 From 150301cf2e5d1ee1e4b7e6d59ef90a9cd2321d1a Mon Sep 17 00:00:00 2001 From: Kelly Hofmann Date: Tue, 19 Mar 2024 11:38:40 -0700 Subject: [PATCH 3/3] add text input model to flags --- internal/setup/environments.go | 2 -- internal/setup/flags.go | 30 ++++++++++++++++++++++++++++++ internal/setup/wizard.go | 9 ++++++--- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/internal/setup/environments.go b/internal/setup/environments.go index 85b95a39..0eb99e36 100644 --- a/internal/setup/environments.go +++ b/internal/setup/environments.go @@ -91,10 +91,8 @@ func (p environmentModel) Init() tea.Cmd { func (m environmentModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmd tea.Cmd - // if we've selected the option to create a new project, delegate to the textInput model if m.showInput { m.textInput, cmd = m.textInput.Update(msg) - // catch the enter key here to update the projectModel when a final value is provided switch msg := msg.(type) { case tea.KeyMsg: switch { 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/wizard.go b/internal/setup/wizard.go index dfaeca76..33ce179e 100644 --- a/internal/setup/wizard.go +++ b/internal/setup/wizard.go @@ -133,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