Skip to content

Commit

Permalink
fix s3 sorting by file size bug
Browse files Browse the repository at this point in the history
  • Loading branch information
PratikJethe committed Sep 26, 2023
1 parent 8c405ea commit 441d39a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions internal/aws/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type EC2Resp struct {
}

type S3Object struct {
SizeInBytes int64
Name, ObjectType, LastModified, Size, StorageClass string
}

Expand Down
1 change: 1 addition & 0 deletions internal/dao/buck_obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func setFoldersAndFiles(folders []types.CommonPrefix, files []types.Object) []aw
Name: keyA[len(keyA)-1],
ObjectType: "File",
LastModified: IST.Format("Mon Jan _2 15:04:05 2006"),
SizeInBytes: fi.Size,
Size: humanize.Bytes(uint64(fi.Size)),
StorageClass: string(fi.StorageClass),
}
Expand Down
2 changes: 2 additions & 0 deletions internal/render/buck_obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func (obj BObj) Header() Header {
HeaderColumn{Name: "Last-Modified", SortIndicatorIdx: 5, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: true},
HeaderColumn{Name: "Size", SortIndicatorIdx: 0, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: false},
HeaderColumn{Name: "Storage-Class", SortIndicatorIdx: 8, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: true},
HeaderColumn{Name: "SizeInBytes", SortIndicatorIdx: 0, Align: tview.AlignLeft, Hide: true, Wide: false, MX: false, Time: false},
}
}

Expand All @@ -33,6 +34,7 @@ func (obj BObj) Render(o interface{}, ns string, row *Row) error {
s3Resp.LastModified,
s3Resp.Size,
s3Resp.StorageClass,
fmt.Sprint(s3Resp.SizeInBytes),
}
return nil
}
8 changes: 6 additions & 2 deletions internal/ui/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ func (t *Table) buildRow(r int, re, ore render.RowEvent, h render.Header) {
if col == 0 {
cell.SetReference(re.Row.ID)
}
t.SetCell(r, col, cell)
if !h[c].Hide {
t.SetCell(r, col, cell)
}
col++
}
}
Expand All @@ -147,7 +149,9 @@ func (t *Table) AddHeaderCell(col int, h render.HeaderColumn) {
c.SetAttributes(tcell.AttrBold)
c.SetExpansion(1)
c.SetAlign(h.Align)
t.SetCell(0, col, c)
if !h.Hide{
t.SetCell(0, col, c)
}
}

// ClearMarks clear out marked items.
Expand Down
2 changes: 1 addition & 1 deletion internal/view/buck_obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (obj *S3FileViewer) bindKeys(aa ui.KeyActions) {
aa.Add(ui.KeyActions{
ui.KeyShiftN: ui.NewKeyAction("Sort Name", obj.GetTable().SortColCmd("Name", true), true),
ui.KeyShiftM: ui.NewKeyAction("Sort Modification-Time", obj.GetTable().SortColCmd("Last-Modified", true), true),
ui.KeyShiftS: ui.NewKeyAction("Sort Size", obj.GetTable().SortColCmd("Size", true), true),
ui.KeyShiftS: ui.NewKeyAction("Sort Size", obj.GetTable().SortColCmd("SizeInBytes", true), true),
ui.KeyShiftC: ui.NewKeyAction("Sort Storage-Class", obj.GetTable().SortColCmd("Storage-Class", true), true),
tcell.KeyEscape: ui.NewKeyAction("Back", obj.App().PrevCmd, false),
tcell.KeyEnter: ui.NewKeyAction("View", obj.enterCmd, false),
Expand Down

0 comments on commit 441d39a

Please sign in to comment.