fix(tui): render compact group dates
This commit is contained in:
parent
439ecf03f8
commit
3e4cd4e2bc
@ -2866,7 +2866,7 @@ func (m model) groupTableRows(columns []tableColumn) []tableRow {
|
||||
case "count":
|
||||
row = append(row, fmt.Sprintf("%d", group.Count))
|
||||
case "time":
|
||||
row = append(row, shortTimestamp(group.Latest))
|
||||
row = append(row, groupTimeForColumn(group.Latest, column.Width))
|
||||
case "age":
|
||||
row = append(row, ageFromTimestamp(group.Latest))
|
||||
case "scope":
|
||||
@ -3812,6 +3812,13 @@ func rowTimeForColumn(item Item, width int) string {
|
||||
return rowWhen(item)
|
||||
}
|
||||
|
||||
func groupTimeForColumn(value string, width int) string {
|
||||
if width <= 5 {
|
||||
return compactDateFromTimestamp(value)
|
||||
}
|
||||
return shortTimestamp(value)
|
||||
}
|
||||
|
||||
func rowAge(item Item) string {
|
||||
if t, ok := itemSortTime(item); ok {
|
||||
return compactAge(time.Since(t))
|
||||
|
||||
@ -269,11 +269,17 @@ func TestCompactWidthKeepsUsefulColumns(t *testing.T) {
|
||||
group := itemGroup{Kind: "channel", Count: 18, Latest: "2026-05-02T12:00:00Z", Title: "github-secure-session-4"}
|
||||
mediumGroupHeader := groupListHeader(46, sortDefault)
|
||||
mediumGroupLine := groupListLine(group, 46)
|
||||
mediumRows := newModel(Options{Items: []Item{
|
||||
Row{Kind: "message", Container: "github-secure-session-4", Title: "message", CreatedAt: "2026-05-02T12:00:00Z"}.ItemForLayout(LayoutChat),
|
||||
}}).groupTableRows(groupColumns(46, sortDefault))
|
||||
for _, want := range []string{"N", "TIME", "AGE", "GROUP", "05-02", "github-secure"} {
|
||||
if !strings.Contains(mediumGroupHeader+mediumGroupLine, want) {
|
||||
t.Fatalf("medium compact group columns missing %q:\n%s\n%s", want, mediumGroupHeader, mediumGroupLine)
|
||||
}
|
||||
}
|
||||
if len(mediumRows) == 0 || !strings.Contains(strings.Join(mediumRows[0], " "), "05-02") {
|
||||
t.Fatalf("medium group table row should use compact dates: %#v", mediumRows)
|
||||
}
|
||||
|
||||
groupHeader := groupListHeader(56, sortDefault)
|
||||
groupLine := groupListLine(group, 56)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user