From 2046d3c5533e0b3101da1c55177de73a20b567e5 Mon Sep 17 00:00:00 2001 From: Daniel Messias Date: Mon, 7 Nov 2022 15:48:49 +0000 Subject: [PATCH] Fix some table bounds issues --- ui/components/table/table.go | 9 +++++++++ ui/pages/s3/bucket.go | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ui/components/table/table.go b/ui/components/table/table.go index 732540c..8bad9d1 100644 --- a/ui/components/table/table.go +++ b/ui/components/table/table.go @@ -162,6 +162,9 @@ func (m *Model) GetCurrentItem() int { } func (m *Model) GetCurrentRow() Row { + if len(m.filteredRows) == 0 { + return nil + } return m.filteredRows[m.rowsViewport.GetCurrItem()] } @@ -170,6 +173,9 @@ func (m *Model) GetCurrentRowMarshalled() map[string]string { } func (m *Model) MarhsalRow(row Row) map[string]string { + if row == nil { + return nil + } rowMap := make(map[string]string) for i, col := range m.Columns { rowMap[col.Title] = row[i] @@ -293,6 +299,9 @@ func (m *Model) filterRows() { } m.rowsViewport.SetNumItems(len(m.filteredRows)) + if m.rowsViewport.GetCurrItem() >= len(m.filteredRows) && len(m.filteredRows) > 0 { + m.rowsViewport.LastItem() + } m.syncViewPortContent() } diff --git a/ui/pages/s3/bucket.go b/ui/pages/s3/bucket.go index 9946dd1..ab4ad37 100644 --- a/ui/pages/s3/bucket.go +++ b/ui/pages/s3/bucket.go @@ -125,7 +125,12 @@ func (m *BucketPageModel) Inspect(client *data.Client) tea.Cmd { } context := m.Context.(BucketPageContext) - key := table.GetCurrentRowMarshalled()["Key"] + row := table.GetCurrentRowMarshalled() + if row == nil { + return nil + } + key := row["Key"] + sanitizedPrefix := context.Prefix + key sanitizedPrefix = strings.Replace(sanitizedPrefix, fmt.Sprintf("%s ", icons.FILE), "", 1) sanitizedPrefix = strings.Replace(sanitizedPrefix, fmt.Sprintf("%s ", icons.FOLDER), "", 1)