-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OSD-8796: porting alerts to tview TUI (#54)
* ported alerts to tview TUI * incident ack toggle added
- Loading branch information
Supreeth Basabattini
authored
Oct 26, 2021
1 parent
a16d618
commit 1bc9af8
Showing
11 changed files
with
609 additions
and
437 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package ui | ||
|
||
import ( | ||
"github.com/gdamore/tcell/v2" | ||
"github.com/openshift/pagerduty-short-circuiter/pkg/pdcli" | ||
) | ||
|
||
// SetAlertsTableEvents is the event handler for the alerts table. | ||
// It handles the program flow when a table selection is made. | ||
func (tui *TUI) SetAlertsTableEvents(alerts []pdcli.Alert) { | ||
tui.Table.SetSelectedFunc(func(row int, column int) { | ||
alertID := tui.Table.GetCell(row, 1).Text | ||
|
||
for _, alert := range alerts { | ||
if alertID == alert.AlertID { | ||
alertData := pdcli.ParseAlertMetaData(alert) | ||
tui.AlertMetadata.SetText(alertData) | ||
tui.ClusterID = alert.ClusterID | ||
} | ||
} | ||
|
||
tui.Pages.AddAndSwitchToPage(AlertDataPageTitle, tui.AlertMetadata, true) | ||
tui.promptSecondaryView("Press 'Y' to proceed with cluster login") | ||
}) | ||
|
||
} | ||
|
||
// SetIncidentsTableEvents is the event handler for the incidents table in ack mode. | ||
// It handles the program flow when a table selection is made. | ||
func (tui *TUI) SetIncidentsTableEvents() { | ||
tui.SelectedIncidents = make(map[string]string) | ||
var text bool | ||
tui.IncidentsTable.SetSelectedFunc(func(row, column int) { | ||
|
||
incidentID := tui.IncidentsTable.GetCell(row, 0).Text | ||
|
||
text = !text | ||
|
||
if _, ok := tui.SelectedIncidents[incidentID]; !ok || tui.SelectedIncidents[incidentID] == "" { | ||
tui.IncidentsTable.GetCell(row, 0).SetTextColor(tcell.ColorLimeGreen) | ||
tui.SelectedIncidents[incidentID] = incidentID | ||
} else { | ||
tui.IncidentsTable.GetCell(row, 0).SetTextColor(tcell.ColorWhite) | ||
tui.SelectedIncidents[incidentID] = "" | ||
} | ||
}) | ||
} | ||
|
||
// acknowledgeSelectedIncidents acknowledges the selected incidents. | ||
// All the incidents that have been acknowledged are printed to the secondary view. | ||
func (tui *TUI) ackowledgeSelectedIncidents() { | ||
ackIncidents, err := pdcli.AcknowledgeIncidents(tui.Client, tui.AckIncidents) | ||
|
||
if err != nil { | ||
tui.showError(err.Error()) | ||
return | ||
} | ||
|
||
text := "The following incidents have been acknowledged:\n" | ||
|
||
for _, v := range ackIncidents { | ||
text = text + v.ID + " - " + v.Title + "\n" | ||
} | ||
|
||
tui.showSecondaryView(text) | ||
} |
Oops, something went wrong.