Skip to content

Commit

Permalink
fix #1169 index out of range (#1170)
Browse files Browse the repository at this point in the history
  • Loading branch information
derailed authored Jun 29, 2021
1 parent 9b49819 commit 107c0ac
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
5 changes: 5 additions & 0 deletions internal/ui/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ func (t *Table) doUpdate(data render.TableData) {

if (t.sortCol.name == "" || custData.Header.IndexOf(t.sortCol.name, false) == -1) && len(custData.Header) > 0 && t.sortCol.name != "NONE" {
t.sortCol.name = custData.Header[0].Name
if t.sortCol.name == "NAMESPACE" && !client.IsAllNamespaces(data.Namespace) {
if idx := custData.Header.IndexOf("NAME", false); idx != -1 {
t.sortCol.name = custData.Header[idx].Name
}
}
}

t.Clear()
Expand Down
15 changes: 5 additions & 10 deletions internal/view/scale_extender.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,18 @@ func (s *ScaleExtender) showScaleDialog(path string) {
s.App().Content.ShowPage(scaleDialogKey)
}

func (s *ScaleExtender) valueOf(col string, index int) (string, error) {
data := s.GetTable().GetFilteredData()
colIdx := data.IndexOfHeader(col)
if colIdx < 0 {
func (s *ScaleExtender) valueOf(col string, rowIndex int) (string, error) {
colIdx, ok := s.GetTable().HeaderIndex(col)
if !ok {
return "", fmt.Errorf("no column index for %s", col)
}
if index > len(data.RowEvents) {
return "", fmt.Errorf("invalid row index %d", index)
}

return data.RowEvents[index].Row.Fields[colIdx], nil
return s.GetTable().GetSelectedCell(colIdx), nil
}

func (s *ScaleExtender) makeScaleForm(sel string) (*tview.Form, error) {
f := s.makeStyledForm()

replicas, err := s.valueOf("READY", s.GetTable().GetSelectedRowIndex())
replicas, err := s.valueOf("READY", s.GetTable().GetSelectedRowIndex()-1)
if err != nil {
return nil, err
}
Expand Down
9 changes: 9 additions & 0 deletions internal/view/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ func (t *Table) Init(ctx context.Context) (err error) {
return nil
}

func (t *Table) HeaderIndex(header string) (int, bool) {
for i := 0; i < t.GetColumnCount(); i++ {
if h := t.GetCell(0, i); h != nil && h.Text == header {
return i, true
}
}
return 0, false
}

// SendKey sends an keyboard event (testing only!).
func (t *Table) SendKey(evt *tcell.EventKey) {
t.app.Prompt().SendKey(evt)
Expand Down

0 comments on commit 107c0ac

Please sign in to comment.