From cff6c62f6a5b90074f0a3b91737d53a803e1cd76 Mon Sep 17 00:00:00 2001 From: Engin Date: Wed, 13 Mar 2024 22:03:11 +0300 Subject: [PATCH 1/2] Improve the logic --- .../terminal/handler/ghtrigger/ghtrigger.go | 111 +++++++++--------- 1 file changed, 56 insertions(+), 55 deletions(-) diff --git a/internal/terminal/handler/ghtrigger/ghtrigger.go b/internal/terminal/handler/ghtrigger/ghtrigger.go index f170f3b..3bc31e3 100644 --- a/internal/terminal/handler/ghtrigger/ghtrigger.go +++ b/internal/terminal/handler/ghtrigger/ghtrigger.go @@ -199,6 +199,10 @@ func (m *ModelGithubTrigger) switchBetweenInputAndTable() { } func (m *ModelGithubTrigger) inputController(ctx context.Context) { + if m.workflowContent == nil { + return + } + if len(m.tableTrigger.Rows()) > 0 { var selectedRow = m.tableTrigger.SelectedRow() if len(selectedRow) == 0 { @@ -248,14 +252,33 @@ func (m *ModelGithubTrigger) inputController(ctx context.Context) { } } - if m.workflowContent != nil { - for i, choice := range m.workflowContent.Choices { + for i, choice := range m.workflowContent.Choices { + var selectedRow = m.tableTrigger.SelectedRow() + if len(selectedRow) == 0 { + return + } + if fmt.Sprintf("%d", choice.ID) == selectedRow[0] { + m.workflowContent.Choices[i].SetValue(m.optionValues[m.optionCursor]) + + rows := m.tableTrigger.Rows() + for i, row := range rows { + if row[0] == selectedRow[0] { + rows[i][4] = m.optionValues[m.optionCursor] + } + } + + m.tableTrigger.SetRows(rows) + } + } + + if m.workflowContent.Boolean != nil { + for i, boolean := range m.workflowContent.Boolean { var selectedRow = m.tableTrigger.SelectedRow() if len(selectedRow) == 0 { return } - if fmt.Sprintf("%d", choice.ID) == selectedRow[0] { - m.workflowContent.Choices[i].SetValue(m.optionValues[m.optionCursor]) + if fmt.Sprintf("%d", boolean.ID) == selectedRow[0] { + m.workflowContent.Boolean[i].SetValue(m.optionValues[m.optionCursor]) rows := m.tableTrigger.Rows() for i, row := range rows { @@ -267,69 +290,47 @@ func (m *ModelGithubTrigger) inputController(ctx context.Context) { m.tableTrigger.SetRows(rows) } } + } - if m.workflowContent.Boolean != nil { - for i, boolean := range m.workflowContent.Boolean { - var selectedRow = m.tableTrigger.SelectedRow() - if len(selectedRow) == 0 { - return - } - if fmt.Sprintf("%d", boolean.ID) == selectedRow[0] { - m.workflowContent.Boolean[i].SetValue(m.optionValues[m.optionCursor]) - - rows := m.tableTrigger.Rows() - for i, row := range rows { - if row[0] == selectedRow[0] { - rows[i][4] = m.optionValues[m.optionCursor] - } - } - - m.tableTrigger.SetRows(rows) - } - } + if m.textInput.Focused() { + if strings.HasPrefix(m.textInput.Value(), " ") { + m.textInput.SetValue("") } - if m.textInput.Focused() { - if strings.HasPrefix(m.textInput.Value(), " ") { - m.textInput.SetValue("") - } + var selectedRow = m.tableTrigger.SelectedRow() + if len(selectedRow) == 0 { + return + } + for i, input := range m.workflowContent.Inputs { + if fmt.Sprintf("%d", input.ID) == selectedRow[0] { + m.textInput.Placeholder = input.Default + m.workflowContent.Inputs[i].SetValue(m.textInput.Value()) - var selectedRow = m.tableTrigger.SelectedRow() - if len(selectedRow) == 0 { - return - } - for i, input := range m.workflowContent.Inputs { - if fmt.Sprintf("%d", input.ID) == selectedRow[0] { - m.textInput.Placeholder = input.Default - m.workflowContent.Inputs[i].SetValue(m.textInput.Value()) - - rows := m.tableTrigger.Rows() - for i, row := range rows { - if row[0] == selectedRow[0] { - rows[i][4] = m.textInput.Value() - } + rows := m.tableTrigger.Rows() + for i, row := range rows { + if row[0] == selectedRow[0] { + rows[i][4] = m.textInput.Value() } - - m.tableTrigger.SetRows(rows) } + + m.tableTrigger.SetRows(rows) } + } - for i, keyVal := range m.workflowContent.KeyVals { - if fmt.Sprintf("%d", keyVal.ID) == selectedRow[0] { - m.textInput.Placeholder = keyVal.Default - m.workflowContent.KeyVals[i].SetValue(m.textInput.Value()) + for i, keyVal := range m.workflowContent.KeyVals { + if fmt.Sprintf("%d", keyVal.ID) == selectedRow[0] { + m.textInput.Placeholder = keyVal.Default + m.workflowContent.KeyVals[i].SetValue(m.textInput.Value()) - rows := m.tableTrigger.Rows() - for i, row := range rows { - if row[0] == selectedRow[0] { - rows[i][4] = m.textInput.Value() - } + rows := m.tableTrigger.Rows() + for i, row := range rows { + if row[0] == selectedRow[0] { + rows[i][4] = m.textInput.Value() } - - m.tableTrigger.SetRows(rows) } - } + m.tableTrigger.SetRows(rows) + } } } } From 52fde5c3e8df295032e7658b6909825f3d31178d Mon Sep 17 00:00:00 2001 From: Engin Date: Wed, 13 Mar 2024 22:25:56 +0300 Subject: [PATCH 2/2] Improve the consistency --- .../terminal/handler/ghtrigger/ghtrigger.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/internal/terminal/handler/ghtrigger/ghtrigger.go b/internal/terminal/handler/ghtrigger/ghtrigger.go index 3bc31e3..ccc9e1c 100644 --- a/internal/terminal/handler/ghtrigger/ghtrigger.go +++ b/internal/terminal/handler/ghtrigger/ghtrigger.go @@ -198,7 +198,7 @@ func (m *ModelGithubTrigger) switchBetweenInputAndTable() { m.textInput.SetCursor(len(m.textInput.Value())) } -func (m *ModelGithubTrigger) inputController(ctx context.Context) { +func (m *ModelGithubTrigger) inputController(_ context.Context) { if m.workflowContent == nil { return } @@ -254,13 +254,14 @@ func (m *ModelGithubTrigger) inputController(ctx context.Context) { for i, choice := range m.workflowContent.Choices { var selectedRow = m.tableTrigger.SelectedRow() - if len(selectedRow) == 0 { + var rows = m.tableTrigger.Rows() + + if len(selectedRow) == 0 || len(rows) == 0 { return } if fmt.Sprintf("%d", choice.ID) == selectedRow[0] { m.workflowContent.Choices[i].SetValue(m.optionValues[m.optionCursor]) - rows := m.tableTrigger.Rows() for i, row := range rows { if row[0] == selectedRow[0] { rows[i][4] = m.optionValues[m.optionCursor] @@ -274,13 +275,13 @@ func (m *ModelGithubTrigger) inputController(ctx context.Context) { if m.workflowContent.Boolean != nil { for i, boolean := range m.workflowContent.Boolean { var selectedRow = m.tableTrigger.SelectedRow() - if len(selectedRow) == 0 { + var rows = m.tableTrigger.Rows() + if len(selectedRow) == 0 || len(rows) == 0 { return } if fmt.Sprintf("%d", boolean.ID) == selectedRow[0] { m.workflowContent.Boolean[i].SetValue(m.optionValues[m.optionCursor]) - rows := m.tableTrigger.Rows() for i, row := range rows { if row[0] == selectedRow[0] { rows[i][4] = m.optionValues[m.optionCursor] @@ -298,15 +299,16 @@ func (m *ModelGithubTrigger) inputController(ctx context.Context) { } var selectedRow = m.tableTrigger.SelectedRow() - if len(selectedRow) == 0 { + var rows = m.tableTrigger.Rows() + if len(selectedRow) == 0 || len(rows) == 0 { return } + for i, input := range m.workflowContent.Inputs { if fmt.Sprintf("%d", input.ID) == selectedRow[0] { m.textInput.Placeholder = input.Default m.workflowContent.Inputs[i].SetValue(m.textInput.Value()) - rows := m.tableTrigger.Rows() for i, row := range rows { if row[0] == selectedRow[0] { rows[i][4] = m.textInput.Value() @@ -322,7 +324,6 @@ func (m *ModelGithubTrigger) inputController(ctx context.Context) { m.textInput.Placeholder = keyVal.Default m.workflowContent.KeyVals[i].SetValue(m.textInput.Value()) - rows := m.tableTrigger.Rows() for i, row := range rows { if row[0] == selectedRow[0] { rows[i][4] = m.textInput.Value()