Skip to content

Commit

Permalink
Fix startup error when no page content
Browse files Browse the repository at this point in the history
  • Loading branch information
robinovitch61 committed Jul 13, 2023
1 parent eab7ffd commit 09a66a4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
20 changes: 11 additions & 9 deletions internal/tui/components/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,18 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
m.getCurrentPageModel().SetLoading(false)

if m.currentPage.CanBeStart() && len(msg.AllPageRows) == 0 {
// oddly, nomad http api errors when one provides the wrong token,
// but returns empty results when one provides an empty token
m.getCurrentPageModel().SetHeader([]string{"Error"})
m.getCurrentPageModel().SetAllPageData([]page.Row{
{"", "No results. Is the cluster empty or was no nomad token provided?"},
{"", "Press q or ctrl+c to quit."},
})
m.getCurrentPageModel().SetViewportSelectionEnabled(false)
}

switch m.currentPage {
case nomad.JobsPage:
if m.currentPage == nomad.JobsPage && len(msg.AllPageRows) == 0 {
// oddly, nomad http api errors when one provides the wrong token, but returns empty results when one provides an empty token
m.getCurrentPageModel().SetAllPageData([]page.Row{
{"", "No job results. Is the cluster empty or no nomad token provided?"},
{"", "Press q or ctrl+c to quit."},
})
m.getCurrentPageModel().SetViewportSelectionEnabled(false)
}
case nomad.JobEventsPage, nomad.AllocEventsPage, nomad.AllEventsPage:
m.eventsStream = msg.EventsStream
cmds = append(cmds, nomad.ReadEventsStreamNextMessage(m.eventsStream, m.config.Event.JQQuery))
Expand Down
4 changes: 4 additions & 0 deletions internal/tui/nomad/pages.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ func (p Page) ShowsTasks() bool {
return false
}

func (p Page) CanBeStart() bool {
return p == JobsPage || p == AllTasksPage
}

func (p Page) doesUpdate() bool {
noUpdatePages := []Page{
LoglinePage, // doesn't load
Expand Down

0 comments on commit 09a66a4

Please sign in to comment.