Skip to content

Commit

Permalink
Merge pull request #96 from jorgerojas26/tree-input-filter
Browse files Browse the repository at this point in the history
feat: add input filter to tree
  • Loading branch information
jorgerojas26 authored Sep 4, 2024
2 parents 7e63af9 + 2635c56 commit ea2ea76
Show file tree
Hide file tree
Showing 6 changed files with 284 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ odbc+postgres://user:pass@localhost:port/dbname?option1=

- [ ] Support for NoSQL databases
- [ ] Columns and indexes creation through TUI
- [ ] Table tree input filter
- [x] Table tree input filter
- [ ] Custom keybindings
- [x] Show keybindings on a modal
- [x] Rewrite row `create`, `update` and `delete` logic
Expand Down
10 changes: 10 additions & 0 deletions app/Keymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func (c KeymapSystem) Resolve(event *tcell.EventKey) cmd.Command {
const (
HomeGroup = "home"
TreeGroup = "tree"
TreeFilterGroup = "treefilter"
TableGroup = "table"
EditorGroup = "editor"
ConnectionGroup = "connection"
Expand Down Expand Up @@ -73,6 +74,15 @@ var Keymaps = KeymapSystem{
Bind{Key: Key{Code: tcell.KeyDown}, Cmd: cmd.MoveDown, Description: "Go down"},
Bind{Key: Key{Char: 'k'}, Cmd: cmd.MoveUp, Description: "Go up"},
Bind{Key: Key{Code: tcell.KeyUp}, Cmd: cmd.MoveUp, Description: "Go up"},
Bind{Key: Key{Char: '/'}, Cmd: cmd.Search, Description: "Search"},
Bind{Key: Key{Char: 'n'}, Cmd: cmd.NextFoundNode, Description: "Go to next found node"},
Bind{Key: Key{Char: 'p'}, Cmd: cmd.PreviousFoundNode, Description: "Go to previous found node"},
Bind{Key: Key{Char: 'c'}, Cmd: cmd.TreeCollapseAll, Description: "Collapse all"},
Bind{Key: Key{Char: 'e'}, Cmd: cmd.ExpandAll, Description: "Expand all"},
},
TreeFilterGroup: {
Bind{Key: Key{Code: tcell.KeyEscape}, Cmd: cmd.UnfocusTreeFilter, Description: "Unfocus tree filter"},
Bind{Key: Key{Code: tcell.KeyEnter}, Cmd: cmd.CommitTreeFilter, Description: "Commit tree filter search"},
},
TableGroup: {
Bind{Key: Key{Char: '/'}, Cmd: cmd.Search, Description: "Search"},
Expand Down
18 changes: 18 additions & 0 deletions commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ const (
AppendNewRow
SortAsc
SortDesc
UnfocusTreeFilter
CommitTreeFilter
NextFoundNode
PreviousFoundNode
TreeCollapseAll
ExpandAll

// Connection
NewConnection
Expand Down Expand Up @@ -161,6 +167,18 @@ func (c Command) String() string {
return "ForeignKeysMenu"
case IndexesMenu:
return "IndexesMenu"
case UnfocusTreeFilter:
return "UnfocusTreeFilter"
case CommitTreeFilter:
return "CommitTreeFilter"
case NextFoundNode:
return "NextFoundNode"
case PreviousFoundNode:
return "PreviousFoundNode"
case TreeCollapseAll:
return "TreeCollapseAll"
case ExpandAll:
return "ExpandAll"
}
return "Unknown"
}
2 changes: 1 addition & 1 deletion components/ConnectionSelection.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (cs *ConnectionSelection) Connect(connection models.Connection) {

MainPages.SwitchToPage(connection.URL)
newHome.Tree.SetCurrentNode(newHome.Tree.GetRoot())
newHome.Tree.SetTitle(fmt.Sprintf("%s (%s)", connection.Name, strings.ToUpper(connection.Provider)))
newHome.Tree.Wrapper.SetTitle(fmt.Sprintf("%s (%s)", connection.Name, strings.ToUpper(connection.Provider)))
App.SetFocus(newHome.Tree)
App.Draw()
}
Expand Down
9 changes: 8 additions & 1 deletion components/Home.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func NewHomePage(connection models.Connection, dbdriver drivers.Driver) *Home {
go home.subscribeToTreeChanges()

leftWrapper.SetBorderColor(tview.Styles.InverseTextColor)
leftWrapper.AddItem(tree, 0, 1, true)
leftWrapper.AddItem(tree.Wrapper, 0, 1, true)

rightWrapper.SetBorderColor(tview.Styles.InverseTextColor)
rightWrapper.SetBorder(true)
Expand Down Expand Up @@ -113,6 +113,13 @@ func (home *Home) subscribeToTreeChanges() {
}

app.App.ForceDraw()
case "IsFiltering":
isFiltering := stateChange.Value.(bool)
if isFiltering {
home.SetInputCapture(nil)
} else {
home.SetInputCapture(home.homeInputCapture)
}
}
}
}
Expand Down
Loading

0 comments on commit ea2ea76

Please sign in to comment.