Skip to content

Commit

Permalink
fix: add cmdbar style to offset loading indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-grgt committed Feb 17, 2025
1 parent 24af2e2 commit 82fd17e
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ui/components/cmdbar/cmdbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"ktea/ui/components/statusbar"
)

const borderedPadding = 2
const BorderedPadding = 2

type CmdBar interface {
View(ktx *kontext.ProgramKtx, renderer *ui.Renderer) string
Expand Down
2 changes: 1 addition & 1 deletion ui/components/cmdbar/delete_cmdbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (s *DeleteCmdBar[any]) View(ktx *kontext.ProgramKtx, renderer *ui.Renderer)

s.deleteConfirm.WithTheme(huh.ThemeCharm())

return renderer.RenderWithStyle(s.deleteConfirm.View(), styles.CmdBarWithWidth(ktx.WindowWidth-borderedPadding))
return renderer.RenderWithStyle(s.deleteConfirm.View(), styles.CmdBarWithWidth(ktx.WindowWidth-BorderedPadding))
}

func (s *DeleteCmdBar[any]) IsFocussed() bool {
Expand Down
4 changes: 2 additions & 2 deletions ui/components/cmdbar/notifier_cmdbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func (n *NotifierCmdBar) View(ktx *kontext.ProgramKtx, renderer *ui.Renderer) st
return view
}
// subtract padding, because of the rounded border of the cmdbar
ktx.AvailableHeight -= borderedPadding
return styles.CmdBarWithWidth(ktx.WindowWidth - borderedPadding).Render(view)
ktx.AvailableHeight -= BorderedPadding
return styles.CmdBarWithWidth(ktx.WindowWidth - BorderedPadding).Render(view)
}

func (n *NotifierCmdBar) Update(msg tea.Msg) (bool, tea.Msg, tea.Cmd) {
Expand Down
2 changes: 1 addition & 1 deletion ui/components/cmdbar/search_cmdbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s *SearchCmdBar) Shortcuts() []statusbar.Shortcut {

func (s *SearchCmdBar) View(ktx *kontext.ProgramKtx, renderer *ui.Renderer) string {
if s.state != hidden {
style := styles.CmdBarWithWidth(ktx.WindowWidth - borderedPadding)
style := styles.CmdBarWithWidth(ktx.WindowWidth - BorderedPadding)
if s.state == searching {
style = style.BorderForeground(lipgloss.Color(styles.ColorFocusBorder))
} else {
Expand Down
16 changes: 12 additions & 4 deletions ui/pages/cgroups_topics_page/cgroups_parts_offsets_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"ktea/kontext"
"ktea/styles"
"ktea/ui"
"ktea/ui/components/cmdbar"
"ktea/ui/components/statusbar"
"ktea/ui/pages/nav"
"slices"
Expand Down Expand Up @@ -35,17 +36,24 @@ type Model struct {

func (m *Model) View(ktx *kontext.ProgramKtx, renderer *ui.Renderer) string {

if len(m.topicByPartOffset) == 0 {
if m.topicByPartOffset != nil && len(m.topicByPartOffset) == 0 {
return styles.
CenterText(ktx.WindowWidth, ktx.AvailableHeight).
Render("๐Ÿ‘€ No Committed Offsets Found")
}

halfWidth := int(float64(ktx.WindowWidth / 2))
cmdBarView := styles.CmdBarWithWidth(ktx.WindowWidth - cmdbar.BorderedPadding).Render(m.cmdBar.View(ktx, renderer))

cmdBarView := m.cmdBar.View(ktx, renderer)
if m.topicByPartOffset == nil {
return ui.JoinVertical(lg.Left,
cmdBarView,
lg.JoinHorizontal(
lg.Top,
"",
))
}

// TODO figure out where the 1 comes from
halfWidth := int(float64(ktx.WindowWidth / 2))
m.topicsTable.SetHeight(ktx.AvailableHeight - 1)
m.topicsTable.SetWidth(halfWidth - 2)
m.topicsTable.SetColumns([]table.Column{
Expand Down
12 changes: 12 additions & 0 deletions ui/pages/cgroups_topics_page/cgroups_parts_offsets_page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ import (

func TestCgroupPartsOffsetsPage(t *testing.T) {

t.Run("Show empty page and loading indicator when listing started", func(t *testing.T) {
model, _ := New(kadmin.NewMockKadmin(), "test-group")

model.Update(kadmin.OffsetListingStartedMsg{})
view := model.View(ui.NewTestKontext(), ui.TestRenderer)

assert.Equal(t,
`โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ โฃพ โณ Loading Offsets โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ`, view)
})

t.Run("List consumer groups", func(t *testing.T) {
model, _ := New(kadmin.NewMockKadmin(), "test-group")

Expand Down

0 comments on commit 82fd17e

Please sign in to comment.