Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show available shortcuts in agent ui #3673

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
60 changes: 60 additions & 0 deletions agent/ui/dashboard/components/commands_panel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package components

import (
"fmt"
"runtime"
"strings"

"github.com/kubeshop/tracetest/agent/ui/dashboard/styles"
"github.com/rivo/tview"
)

type CommandsPanel struct {
*tview.Table
}

type Command struct {
Name string
Shortcut string
}

func (c Command) GetCommand() string {
cmd := c.Shortcut
ctrl := "Ctrl"
alt := "Alt"
if runtime.GOOS == "darwin" {
ctrl = "⌘"
alt = "Opt"
}

cmd = strings.ReplaceAll(cmd, "Ctrl", ctrl)
cmd = strings.ReplaceAll(cmd, "Alt", alt)

return cmd
}

func NewCommandsPanel(commands []Command) *CommandsPanel {
panel := &CommandsPanel{
Table: tview.NewTable(),
}
panel.SetBorderPadding(0, 2, 2, 0)
panel.SetBorder(true).SetTitle("Shortcuts")
defaultPadding := " "

maxItemsPerColumn := 1

for i, cmd := range commands {
padding := defaultPadding
row := i % maxItemsPerColumn
column := int(i / maxItemsPerColumn)

if column == 0 {
padding = ""
}

panel.SetCell(row, column*2, tview.NewTableCell(fmt.Sprintf("%s%s:", padding, cmd.Name)).SetStyle(styles.MetricNameStyle).SetAlign(tview.AlignLeft))
panel.SetCell(row, column*2+1, tview.NewTableCell(cmd.GetCommand()).SetStyle(styles.MetricValueStyle))
}

return panel
}
12 changes: 9 additions & 3 deletions agent/ui/dashboard/pages/test_runs_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ const maxTestRuns = 25
type TestRunPage struct {
*tview.Grid

header *components.Header
testRunList *components.TestRunList
header *components.Header
testRunList *components.TestRunList
commandsPanel *components.CommandsPanel

renderScheduler components.RenderScheduler
testRuns []models.TestRun
Expand All @@ -32,6 +33,10 @@ func NewTestRunPage(renderScheduler components.RenderScheduler, sensor sensors.S

p.header = components.NewHeader(renderScheduler, sensor)
p.testRunList = components.NewTestRunList(renderScheduler, sensor)
p.commandsPanel = components.NewCommandsPanel([]components.Command{
{Name: "Show details", Shortcut: "Enter"},
{Name: "Exit", Shortcut: "Esc"},
})

p.Grid.
// We gonna use 4 lines (it could be 2, but there's a limitation in tview that only allow
Expand All @@ -43,7 +48,8 @@ func NewTestRunPage(renderScheduler components.RenderScheduler, sensor sensors.S
// Header starts at (row,column) (0,0) and fills 1 row and 3 columns
AddItem(p.header, 0, 0, 1, 3, 0, 0, false).
// TestRunList starts at (1,0) and fills 2 rows and 3 columns
AddItem(p.testRunList, 1, 0, 2, 3, 0, 0, true)
AddItem(p.testRunList, 1, 0, 2, 3, 0, 0, true).
AddItem(p.commandsPanel, 3, 0, 1, 3, 0, 0, false)

sensor.On(events.NewTestRun, func(e sensors.Event) {
var testRun models.TestRun
Expand Down