Skip to content

Commit

Permalink
[fix] esc clears filter on single log page
Browse files Browse the repository at this point in the history
  • Loading branch information
robinovitch61 committed Dec 30, 2024
1 parent 3320623 commit 6144e86
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
10 changes: 7 additions & 3 deletions internal/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,10 @@ func (m Model) handleKeyMsg(msg tea.KeyMsg) (Model, tea.Cmd) {
return m, tea.Batch(cmds...)
}

// store whether a filter is currently applied - helps make decisions later like whether to go back
// from single log page to logs page or just clear the filter upon user pressing ESC
hasAppliedFilter := m.pages[m.focusedPageType].HasAppliedFilter()

// update current page with key msg
m.pages[m.focusedPageType], cmd = m.pages[m.focusedPageType].Update(msg)
cmds = append(cmds, cmd)
Expand Down Expand Up @@ -498,7 +502,7 @@ func (m Model) handleKeyMsg(msg tea.KeyMsg) (Model, tea.Cmd) {

// single log page specific actions
if m.focusedPageType == page.SingleLogPageType {
m, cmd = m.handleSingleLogPageKeyMsg(msg)
m, cmd = m.handleSingleLogPageKeyMsg(msg, hasAppliedFilter)
cmds = append(cmds, cmd)
return m, tea.Batch(cmds...)
}
Expand Down Expand Up @@ -633,13 +637,13 @@ func (m Model) handleLogsPageKeyMsg(msg tea.KeyMsg) (Model, tea.Cmd) {
return m, nil
}

func (m Model) handleSingleLogPageKeyMsg(msg tea.KeyMsg) (Model, tea.Cmd) {
func (m Model) handleSingleLogPageKeyMsg(msg tea.KeyMsg, hasAppliedFilter bool) (Model, tea.Cmd) {
// handle clear
var cmd tea.Cmd
var cmds []tea.Cmd
isClear := key.Matches(msg, m.keyMap.Clear)
notHighjackingInput := !m.pages[m.focusedPageType].HighjackingInput()
noAppliedFilter := !m.pages[m.focusedPageType].(page.SingleLogPage).HasAppliedFilter()
noAppliedFilter := !hasAppliedFilter
if isClear && notHighjackingInput && noAppliedFilter {
m, cmd = m.changeFocusedPage(page.LogsPageType)
cmds = append(cmds, cmd)
Expand Down
4 changes: 4 additions & 0 deletions internal/page/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ func (p EntityPage) ContentForFile() []string {
return content
}

func (p EntityPage) HasAppliedFilter() bool {
return p.filterableViewport.Filter.Value() != ""
}

func (p EntityPage) ToggleShowContext() GenericPage {
p.filterableViewport.ToggleShowContext()
return p
Expand Down
8 changes: 4 additions & 4 deletions internal/page/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func (p SingleLogPage) ToggleShowContext() GenericPage {
return p
}

func (p SingleLogPage) HasAppliedFilter() bool {
return p.filterableViewport.Filter.Value() != ""
}

func (p SingleLogPage) ContentForClipboard() []string {
// don't include asci escape chars in header when copying single log to clipboard
header, content := veryNicelyFormatThisLog(p.log, false)
Expand Down Expand Up @@ -132,10 +136,6 @@ func (p SingleLogPage) WithLog(log model.PageLog) SingleLogPage {
return p
}

func (p SingleLogPage) HasAppliedFilter() bool {
return p.filterableViewport.Filter.Value() != ""
}

func veryNicelyFormatThisLog(log model.PageLog, styleHeader bool) (string, []string) {
header := fmt.Sprintf("%s | %s", log.Timestamps.Full, log.RenderName(log.ContainerNames.Full, styleHeader))
return header, formatJSON(log.Log.Content)
Expand Down
4 changes: 4 additions & 0 deletions internal/page/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ func (p LogsPage) ContentForFile() []string {
return content
}

func (p LogsPage) HasAppliedFilter() bool {
return p.filterableViewport.Filter.Value() != ""
}

func (p LogsPage) ToggleShowContext() GenericPage {
p.filterableViewport.ToggleShowContext()
return p
Expand Down
1 change: 1 addition & 0 deletions internal/page/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type GenericPage interface {
View() string
ContentForFile() []string
ToggleShowContext() GenericPage
HasAppliedFilter() bool
HighjackingInput() bool
WithDimensions(width, height int) GenericPage
WithFocus() GenericPage
Expand Down

0 comments on commit 6144e86

Please sign in to comment.