Skip to content

Commit

Permalink
Merge pull request jorgerojas26#130 from svanharmelen/feat/order-tree
Browse files Browse the repository at this point in the history
Make the items in the tree alphabetically ordered
  • Loading branch information
jorgerojas26 authored and Mariusz Kuchta committed Nov 25, 2024
2 parents 95635d4 + c98de17 commit 0bc5564
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion components/Tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package components

import (
"fmt"
"maps"
"slices"
"sort"
"strings"

"github.com/gdamore/tcell/v2"
Expand Down Expand Up @@ -291,7 +294,16 @@ func NewTree(dbName string, dbdriver drivers.Driver) *Tree {
func (tree *Tree) databasesToNodes(children map[string][]string, node *tview.TreeNode, defaultExpanded bool) {
node.ClearChildren()

for key, values := range children {
// Sort the keys and use them to loop over the
// children so they are always in the same order.
sortedKeys := slices.Sorted(maps.Keys(children))

for _, key := range sortedKeys {
values := children[key]

// Sort the values.
sort.Strings(values)

var rootNode *tview.TreeNode

nodeReference := node.GetReference().(string)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/jorgerojas26/lazysql

go 1.20
go 1.23

require (
github.com/DATA-DOG/go-sqlmock v1.5.2
Expand Down

0 comments on commit 0bc5564

Please sign in to comment.