From 3390eb79c8a6d612275488ed18e55b1224d58ccd Mon Sep 17 00:00:00 2001 From: hengyoush Date: Thu, 14 Nov 2024 23:01:25 +0800 Subject: [PATCH] fix(cli): cli stat command sort by bug --- agent/render/stat/stat.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/agent/render/stat/stat.go b/agent/render/stat/stat.go index 8c514a56..bd4f4f2c 100644 --- a/agent/render/stat/stat.go +++ b/agent/render/stat/stat.go @@ -258,7 +258,13 @@ func connstatPercentileSortFunc(c1, c2 *analysis.ConnStat, line float64, m commo } func (m *model) sortConnstats(connstats *[]*analysis.ConnStat) { metric := m.options.EnabledMetricTypeSet.GetFirstEnabledMetricType() - switch m.sortBy { + var sortBy rc.SortBy + if !m.options.Overview && m.sortBy >= 2 { + sortBy = m.sortBy + 1 + } else { + sortBy = m.sortBy + } + switch sortBy { case max: slices.SortFunc(*connstats, func(c1, c2 *analysis.ConnStat) int { if m.reverse { @@ -378,13 +384,12 @@ func (m *model) updateStatTable(msg tea.Msg) (tea.Model, tea.Cmd) { case "1", "2", "3", "4", "5", "6", "7", "8": i, err := strconv.Atoi(strings.TrimPrefix(msg.String(), "ctrl+")) curTable := m.curTable() - if i >= 2 && !m.options.Overview { - i++ - } if err == nil && (i >= int(none) && i < int(end)) && (i >= 0 && i < len(curTable.Columns())) { prevSortBy := m.sortBy + m.sortBy = rc.SortBy(i) + m.reverse = !m.reverse cols := curTable.Columns() if prevSortBy != none { @@ -392,7 +397,7 @@ func (m *model) updateStatTable(msg tea.Msg) (tea.Model, tea.Cmd) { col.Title = strings.TrimRight(col.Title, "↑") col.Title = strings.TrimRight(col.Title, "↓") } - col := &cols[m.sortBy] + col := &cols[i] if m.reverse { col.Title = col.Title + "↓" } else {