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

feat: add input filter to tree #96

Merged
merged 2 commits into from
Sep 4, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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