Skip to content

Commit

Permalink
Fix some table bounds issues
Browse files Browse the repository at this point in the history
  • Loading branch information
danielcmessias committed Nov 7, 2022
1 parent 9d0e757 commit 2046d3c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions ui/components/table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
}

Expand All @@ -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]
Expand Down Expand Up @@ -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()
}

Expand Down
7 changes: 6 additions & 1 deletion ui/pages/s3/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2046d3c

Please sign in to comment.