Skip to content

Commit

Permalink
fixed ESC key event to switch to prev page + cursor fix while switchi…
Browse files Browse the repository at this point in the history
…ng between pages (#66)

* fixed esc key functionality to switch to prev page directly

* implemented alerts high/low flags as part of TUI (#65)

* implemented alerts high/low flags as part of TUI

* removed flags

* fixed esc key functionality to switch to prev page directly

* footer text modification

* moved high/low navigation to trigerred alerts view
  • Loading branch information
Supreeth Basabattini authored Nov 2, 2021
1 parent 9155173 commit 5c8aebe
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 17 deletions.
11 changes: 6 additions & 5 deletions pkg/ui/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ const (
AllTeamsOncallPageTitle = "All Teams Oncall"

// Footer
FooterText = "[Q] Quit | [Esc] Go Back"
FooterTextStatus = "[H] High Alerts | [L] Low Alerts\n"
FooterTextAlerts = "[1] Resolved Alerts | [2] Trigerred Alerts | [3] Acknowledged Incidents | [4] Trigerred Incidents | " + FooterTextStatus + FooterText
FooterTextIncidents = "[ENTER] Select Incident | [CTRL+A] Acknowledge Incidents\n" + FooterText
FooterTextOncall = "[N] Your Next Oncall Schedule | [A] All Teams Oncall\n" + FooterText
FooterText = "[Q] Quit | [Esc] Go Back"
FooterTextStatus = "[H] High Alerts | [L] Low Alerts\n"
FooterTextAlerts = "[1] Resolved Alerts | [2] Trigerred Alerts | [3] Acknowledged Incidents | [4] Trigerred Incidents\n" + FooterText
FooterTextTrigerredAlerts = "[1] Resolved Alerts | [2] Trigerred Alerts | [3] Acknowledged Incidents | [4] Trigerred Incidents\n" + FooterTextStatus + FooterText
FooterTextIncidents = "[ENTER] Select Incident | [CTRL+A] Acknowledge Incidents\n" + FooterText
FooterTextOncall = "[N] Your Next Oncall Schedule | [A] All Teams Oncall\n" + FooterText

// Colors
TableTitleColor = tcell.ColorLightCyan
Expand Down
36 changes: 25 additions & 11 deletions pkg/ui/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,25 @@ func (tui *TUI) initKeyboard() {

if event.Key() == tcell.KeyEscape {

// Check if alerts command is executed
if tui.Pages.HasPage(AlertsPageTitle) {
tui.InitAlertsUI(pdcli.AllAlerts, AlertsTableTitle, AlertsPageTitle)
tui.Footer.SetText(FooterTextAlerts)
page, _ := tui.Pages.GetFrontPage()

tui.Pages.SwitchToPage(AlertsPageTitle)
tui.showDefaultSecondaryView()
if page == AlertDataPageTitle {
tui.Pages.SwitchToPage(tui.FrontPage)
tui.showDefaultSecondaryView()
} else if page == HighAlertsPageTitle || page == LowAlertsPageTitle {
tui.Pages.SwitchToPage(TrigerredAlertsPageTitle)
} else {
tui.InitAlertsUI(pdcli.AllAlerts, AlertsTableTitle, AlertsPageTitle)
tui.Footer.SetText(FooterTextAlerts)

tui.Pages.SwitchToPage(AlertsPageTitle)
tui.showDefaultSecondaryView()
}
}

// Check if oncall command is executed
if tui.Pages.HasPage(OncallPageTitle) {
tui.Pages.SwitchToPage(OncallPageTitle)
tui.Footer.SetText(FooterTextOncall)
Expand Down Expand Up @@ -76,18 +87,21 @@ func (tui *TUI) setupAlertsPageInput() {
tui.Pages.SwitchToPage(IncidentsPageTitle)
}

if event.Rune() == 'H' || event.Rune() == 'h' {
if title, _ := tui.Pages.GetFrontPage(); title == TrigerredAlertsPageTitle {

tui.SeedHighAlertsUI()
if event.Rune() == 'H' || event.Rune() == 'h' {

tui.Pages.SwitchToPage(HighAlertsPageTitle)
}
tui.SeedHighAlertsUI()

if event.Rune() == 'L' || event.Rune() == 'l' {
tui.Pages.SwitchToPage(HighAlertsPageTitle)
}

if event.Rune() == 'L' || event.Rune() == 'l' {

tui.SeedHLowAlertsUI()
tui.SeedHLowAlertsUI()

tui.Pages.SwitchToPage(LowAlertsPageTitle)
tui.Pages.SwitchToPage(LowAlertsPageTitle)
}
}

return event
Expand Down
10 changes: 9 additions & 1 deletion pkg/ui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type TUI struct {
Info *tview.TextView
Layout *tview.Flex
Footer *tview.TextView
FrontPage string

// Misc. UI elements
secondaryText string
Expand Down Expand Up @@ -94,6 +95,13 @@ func (tui *TUI) InitAlertsUI(alerts []pdcli.Alert, tableTitle string, pageTitle
tui.SetAlertsSecondaryData()

tui.Pages.AddPage(pageTitle, tui.Table, true, true)
tui.FrontPage = pageTitle

if pageTitle == TrigerredAlertsPageTitle {
tui.Footer.SetText(FooterTextTrigerredAlerts)
} else {
tui.Footer.SetText(FooterTextAlerts)
}
}

// InitIncidentsUI initializes TUI table component.
Expand Down Expand Up @@ -147,7 +155,7 @@ func (tui *TUI) Init() {
tui.Footer.
SetTextAlign(tview.AlignLeft).
SetTextColor(FooterTextColor).
SetBorderPadding(2, 2, 1, 1)
SetBorderPadding(1, 0, 1, 1)

tui.AlertMetadata.
SetScrollable(true).
Expand Down

0 comments on commit 5c8aebe

Please sign in to comment.