Skip to content

Commit

Permalink
make selectable the trace details view
Browse files Browse the repository at this point in the history
  • Loading branch information
ymtdzzz committed Mar 31, 2024
1 parent 1092198 commit 40fe620
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
24 changes: 20 additions & 4 deletions tuiexporter/internal/tui/component/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ func (p *TUIPages) createTracePage(store *telemetry.Store) *tview.Flex {
page := tview.NewFlex().SetDirection(tview.FlexColumn)

details := tview.NewFlex().SetDirection(tview.FlexRow)
details.SetTitle("Details").SetBorder(true)
details.SetTitle("Details (d)").SetBorder(true)

tableContainer := tview.NewFlex().SetDirection(tview.FlexRow)
tableContainer.SetTitle("Traces").SetBorder(true)
tableContainer.SetTitle("Traces (t)").SetBorder(true)
table := tview.NewTable().
SetBorders(false).
SetSelectable(true, false).
Expand All @@ -91,7 +91,7 @@ func (p *TUIPages) createTracePage(store *telemetry.Store) *tview.Flex {
input := ""
inputConfirmed := ""
search := tview.NewInputField().
SetLabel("Service Name: ").
SetLabel("Service Name (/): ").
SetFieldWidth(20)
search.SetChangedFunc(func(text string) {
// remove the suffix '/' from input because it is passed from SetInputCapture()
Expand All @@ -114,7 +114,7 @@ func (p *TUIPages) createTracePage(store *telemetry.Store) *tview.Flex {

table.SetSelectionChangedFunc(func(row, _ int) {
details.Clear()
details.AddItem(GetTraceInfoTree(store.GetFilteredServiceSpansByIdx(row)), 0, 1, false)
details.AddItem(getTraceInfoTree(store.GetFilteredServiceSpansByIdx(row)), 0, 1, true)
log.Printf("selected row: %d", row)
})
tableContainer.
Expand All @@ -126,12 +126,28 @@ func (p *TUIPages) createTracePage(store *telemetry.Store) *tview.Flex {
if !search.HasFocus() {
p.setFocusFn(search)
}
return nil
}

return event
})

page.AddItem(tableContainer, 0, 6, true).AddItem(details, 0, 4, false)
page.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
switch event.Rune() {
case 'd':
if !search.HasFocus() {
p.setFocusFn(details)
}
// don't return nil here, because we want to pass the event to the search input
case 't':
if !search.HasFocus() {
p.setFocusFn(table)
}
// don't return nil here, because we want to pass the event to the search input
}
return event
})
page = attatchCommandList(page, KeyMaps{
*tcell.NewEventKey(tcell.KeyCtrlL, ' ', tcell.ModNone): "Toggle Log",
*tcell.NewEventKey(tcell.KeyRune, '/', tcell.ModNone): "Search traces",
Expand Down
6 changes: 5 additions & 1 deletion tuiexporter/internal/tui/component/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func getCellFromSpan(span *telemetry.SpanData, column int) *tview.TableCell {
return tview.NewTableCell(text)
}

func GetTraceInfoTree(spans []*telemetry.SpanData) *tview.TreeView {
func getTraceInfoTree(spans []*telemetry.SpanData) *tview.TreeView {
if len(spans) == 0 {
return nil
}
Expand Down Expand Up @@ -111,6 +111,10 @@ func GetTraceInfoTree(spans []*telemetry.SpanData) *tview.TreeView {

root.AddChild(resource)

tree.SetSelectedFunc(func(node *tview.TreeNode) {
node.SetExpanded(!node.IsExpanded())
})

return tree
}

Expand Down
4 changes: 2 additions & 2 deletions tuiexporter/internal/tui/component/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func TestGetTraceInfoTree(t *testing.T) {
screen.Init()
screen.SetSize(sw, sh)

gottree := GetTraceInfoTree(spans)
gottree := getTraceInfoTree(spans)
gottree.SetRect(0, 0, sw, sh)
gottree.Draw(screen)
screen.Sync()
Expand Down Expand Up @@ -181,5 +181,5 @@ func TestGetTraceInfoTree(t *testing.T) {
}

func TestGetTraceInfoTreeNoSpans(t *testing.T) {
assert.Nil(t, GetTraceInfoTree(nil))
assert.Nil(t, getTraceInfoTree(nil))
}

0 comments on commit 40fe620

Please sign in to comment.