Skip to content

Commit a7946fa

Browse files
committed
feat(ui): option to hide table sep, header, footer
1 parent fe6acd6 commit a7946fa

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

ui/components/dashboard/dashboard.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
3838
Filters: section.Config.Filters,
3939
Layout: config.PrsLayoutConfig{},
4040
}, time.Now(), true)
41-
prsSection.SetHeaderHidden(true)
41+
prsSection.Table.SetHeaderHidden(true)
42+
prsSection.Table.SetFooterHidden(true)
43+
prsSection.Table.SeparatorHidden = true
4244

4345
card := sectioncard.NewModel(m.ctx)
4446
card.Title = section.Config.Title

ui/components/listviewport/listviewport.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type Model struct {
2323
NumTotalItems int
2424
LastUpdated time.Time
2525
ItemTypeLabel string
26+
FooterHidden bool
2627
}
2728

2829
func NewModel(ctx context.ProgramContext, dimensions constants.Dimensions, lastUpdated time.Time, itemTypeLabel string, numItems, listItemHeight int) Model {
@@ -113,7 +114,7 @@ func (m *Model) SetDimensions(dimensions constants.Dimensions) {
113114

114115
func (m *Model) View() string {
115116
pagerContent := ""
116-
if m.NumTotalItems > 0 {
117+
if !m.FooterHidden && m.NumTotalItems > 0 {
117118
pagerContent = fmt.Sprintf(
118119
"%v %v • %v %v/%v • Fetched %v",
119120
constants.WaitingIcon,

ui/components/section/section.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@ func NewModel(
8282
return m
8383
}
8484

85-
func (m *Model) SetHeaderHidden(hidden bool) {
86-
m.Table.HeaderHidden = true
87-
}
88-
8985
func (m *Model) SetDimensions(width, height int) {
9086
m.Width = width
9187
m.Height = height

ui/components/table/table.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ import (
1111
)
1212

1313
type Model struct {
14-
ctx context.ProgramContext
15-
Columns []Column
16-
Rows []Row
17-
EmptyState *string
18-
dimensions constants.Dimensions
19-
rowsViewport listviewport.Model
20-
HeaderHidden bool
14+
ctx context.ProgramContext
15+
Columns []Column
16+
Rows []Row
17+
EmptyState *string
18+
dimensions constants.Dimensions
19+
rowsViewport listviewport.Model
20+
headerHidden bool
21+
SeparatorHidden bool
2122
}
2223

2324
type Column struct {
@@ -37,13 +38,12 @@ func NewModel(ctx context.ProgramContext, dimensions constants.Dimensions, lastU
3738
EmptyState: emptyState,
3839
dimensions: dimensions,
3940
rowsViewport: listviewport.NewModel(ctx, dimensions, lastUpdated, itemTypeLabel, len(rows), 2),
40-
HeaderHidden: false,
4141
}
4242
}
4343

4444
func (m Model) View() string {
4545
header := ""
46-
if !m.HeaderHidden {
46+
if !m.headerHidden {
4747
header = m.renderHeader()
4848
}
4949
body := m.renderBody()
@@ -59,6 +59,14 @@ func (m *Model) SetDimensions(dimensions constants.Dimensions) {
5959
})
6060
}
6161

62+
func (m *Model) SetHeaderHidden(hidden bool) {
63+
m.headerHidden = hidden
64+
}
65+
66+
func (m *Model) SetFooterHidden(hidden bool) {
67+
m.rowsViewport.FooterHidden = hidden
68+
}
69+
6270
func (m *Model) ResetCurrItem() {
6371
m.rowsViewport.ResetCurrItem()
6472
}
@@ -225,7 +233,11 @@ func (m *Model) renderRow(rowId int, headerColumns []string) string {
225233
headerColId++
226234
}
227235

228-
return m.ctx.Styles.Table.RowStyle.Copy().
236+
rowStyle := m.ctx.Styles.Table.RowStyle.Copy()
237+
if m.SeparatorHidden {
238+
rowStyle.BorderBottom(false)
239+
}
240+
return rowStyle.
229241
MaxWidth(m.dimensions.Width).
230242
Render(lipgloss.JoinHorizontal(lipgloss.Top, renderedColumns...))
231243

0 commit comments

Comments
 (0)