From 9c805ea6ab9f90d8404c1e3916fca764224489db Mon Sep 17 00:00:00 2001 From: Koustav Date: Tue, 13 Aug 2024 14:01:02 +0530 Subject: [PATCH 1/9] update: On delete a saved filter user have to confirm their action --- pkg/model/savedFilters.go | 43 +++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/pkg/model/savedFilters.go b/pkg/model/savedFilters.go index 9660881..928ac80 100644 --- a/pkg/model/savedFilters.go +++ b/pkg/model/savedFilters.go @@ -20,10 +20,11 @@ import ( "fmt" "io" "net/http" - "pb/pkg/config" "strings" "time" + "pb/pkg/config" + "github.com/charmbracelet/bubbles/key" "github.com/charmbracelet/bubbles/list" tea "github.com/charmbracelet/bubbletea" @@ -33,9 +34,14 @@ import ( const ( applyFilterButton = "a" deleteFilterButton = "d" + confirmDelete = "y" + cancelDelete = "n" ) -var docStyle = lipgloss.NewStyle().Margin(1, 2) +var ( + docStyle = lipgloss.NewStyle().Margin(1, 2) + deleteFilterState bool +) // FilterDetails represents the structure of filter data type FilterDetails struct { @@ -52,11 +58,11 @@ type Item struct { } var ( - titleStyles = lipgloss.NewStyle().PaddingLeft(0).Bold(true).Foreground(lipgloss.Color("9")) - queryStyle = lipgloss.NewStyle().PaddingLeft(0).Foreground(lipgloss.Color("7")) - itemStyle = lipgloss.NewStyle().PaddingLeft(4).Foreground(lipgloss.Color("8")) - // selectedItemStyle = lipgloss.NewStyle().PaddingLeft(4).Foreground(lipgloss.Color("170")) + titleStyles = lipgloss.NewStyle().PaddingLeft(0).Bold(true).Foreground(lipgloss.Color("9")) + queryStyle = lipgloss.NewStyle().PaddingLeft(0).Foreground(lipgloss.Color("7")) + itemStyle = lipgloss.NewStyle().PaddingLeft(4).Foreground(lipgloss.Color("8")) selectedItemStyle = lipgloss.NewStyle().PaddingLeft(1).Foreground(lipgloss.AdaptiveColor{Light: "16", Dark: "226"}) + confirmModal = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.AdaptiveColor{Light: "16", Dark: "226"}) ) type itemDelegate struct{} @@ -90,6 +96,18 @@ func (d itemDelegate) Render(w io.Writer, m list.Model, index int, listItem list } func (d itemDelegate) ShortHelp() []key.Binding { + if deleteFilterState { + return []key.Binding{ + key.NewBinding( + key.WithKeys(confirmDelete), + key.WithHelp(confirmDelete, confirmModal.Render("confirm delete")), + ), + key.NewBinding( + key.WithKeys(cancelDelete), + key.WithHelp(cancelDelete, confirmModal.Render("cancel delete")), + ), + } + } return []key.Binding{ key.NewBinding( key.WithKeys(applyFilterButton), @@ -157,9 +175,18 @@ func (m modelFilter) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, tea.Quit } if msg.String() == "d" { + // selectedFilterDelete = m.list.SelectedItem().(Item) + deleteFilterState = true + return m, nil + + } + if msg.String() == "y" { selectedFilterDelete = m.list.SelectedItem().(Item) return m, tea.Quit - + } + if msg.String() == "n" { + deleteFilterState = false + return m, nil } case tea.WindowSizeMsg: h, v := docStyle.GetFrameSize() @@ -264,4 +291,4 @@ func FilterToApply() Item { // FilterToDelete returns the selected filter by user in the interactive list to delete func FilterToDelete() Item { return selectedFilterDelete -} +} \ No newline at end of file From 82102cdcddff05c751d0221267c7653e3639278e Mon Sep 17 00:00:00 2001 From: Koustav Date: Tue, 13 Aug 2024 14:04:07 +0530 Subject: [PATCH 2/9] update: On delete a saved filter user have to confirm their action --- pkg/model/savedFilters.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/model/savedFilters.go b/pkg/model/savedFilters.go index 928ac80..c5ac539 100644 --- a/pkg/model/savedFilters.go +++ b/pkg/model/savedFilters.go @@ -170,15 +170,20 @@ func (m modelFilter) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if msg.String() == "ctrl+c" { return m, tea.Quit } + if msg.String() == "q" { + return m, tea.Quit + } if msg.String() == "a" || msg.Type == tea.KeyEnter { selectedFilterApply = m.list.SelectedItem().(Item) return m, tea.Quit } if msg.String() == "d" { - // selectedFilterDelete = m.list.SelectedItem().(Item) deleteFilterState = true return m, nil - + } + if msg.String() != "d"{ + deleteFilterState = false + return m,nil } if msg.String() == "y" { selectedFilterDelete = m.list.SelectedItem().(Item) From 9b895258ea94a1e29a2df67e99d146bb6670e15a Mon Sep 17 00:00:00 2001 From: Koustav Date: Tue, 13 Aug 2024 14:08:18 +0530 Subject: [PATCH 3/9] go fumpt'ed andn go fmt'ed --- pkg/model/savedFilters.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/model/savedFilters.go b/pkg/model/savedFilters.go index c5ac539..b4ec4a0 100644 --- a/pkg/model/savedFilters.go +++ b/pkg/model/savedFilters.go @@ -181,9 +181,9 @@ func (m modelFilter) Update(msg tea.Msg) (tea.Model, tea.Cmd) { deleteFilterState = true return m, nil } - if msg.String() != "d"{ + if msg.String() != "d" { deleteFilterState = false - return m,nil + return m, nil } if msg.String() == "y" { selectedFilterDelete = m.list.SelectedItem().(Item) @@ -296,4 +296,4 @@ func FilterToApply() Item { // FilterToDelete returns the selected filter by user in the interactive list to delete func FilterToDelete() Item { return selectedFilterDelete -} \ No newline at end of file +} From ca7fdc510ea76f14edbab9b499779d9fd90135d6 Mon Sep 17 00:00:00 2001 From: Koustav Date: Tue, 13 Aug 2024 14:23:36 +0530 Subject: [PATCH 4/9] go fumpt'ed andn go fmt'ed --- pkg/model/savedFilters.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/model/savedFilters.go b/pkg/model/savedFilters.go index b4ec4a0..e7d9763 100644 --- a/pkg/model/savedFilters.go +++ b/pkg/model/savedFilters.go @@ -58,7 +58,8 @@ type Item struct { } var ( - titleStyles = lipgloss.NewStyle().PaddingLeft(0).Bold(true).Foreground(lipgloss.Color("9")) + titleStyles = lipgloss.NewStyle().PaddingLeft(0).Bold(true).Foreground(lipgloss.Color("9")) + queryStyle = lipgloss.NewStyle().PaddingLeft(0).Foreground(lipgloss.Color("7")) itemStyle = lipgloss.NewStyle().PaddingLeft(4).Foreground(lipgloss.Color("8")) selectedItemStyle = lipgloss.NewStyle().PaddingLeft(1).Foreground(lipgloss.AdaptiveColor{Light: "16", Dark: "226"}) From 0bf874535b29e66062466ebbac243a9bcf460de2 Mon Sep 17 00:00:00 2001 From: Koustav Date: Tue, 13 Aug 2024 14:59:17 +0530 Subject: [PATCH 5/9] proper state declaraion --- pkg/model/savedFilters.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/model/savedFilters.go b/pkg/model/savedFilters.go index e7d9763..0bebac8 100644 --- a/pkg/model/savedFilters.go +++ b/pkg/model/savedFilters.go @@ -40,7 +40,7 @@ const ( var ( docStyle = lipgloss.NewStyle().Margin(1, 2) - deleteFilterState bool + deleteFilterState = false ) // FilterDetails represents the structure of filter data From c77e7d2a65603c4ab630ee55f19cb649310dc29d Mon Sep 17 00:00:00 2001 From: Koustav Date: Tue, 13 Aug 2024 15:56:13 +0530 Subject: [PATCH 6/9] Fix: Issue where delete func was not properly called --- pkg/model/savedFilters.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/pkg/model/savedFilters.go b/pkg/model/savedFilters.go index 0bebac8..a7bed3e 100644 --- a/pkg/model/savedFilters.go +++ b/pkg/model/savedFilters.go @@ -40,7 +40,7 @@ const ( var ( docStyle = lipgloss.NewStyle().Margin(1, 2) - deleteFilterState = false + deleteFilterState bool = false ) // FilterDetails represents the structure of filter data @@ -58,8 +58,7 @@ type Item struct { } var ( - titleStyles = lipgloss.NewStyle().PaddingLeft(0).Bold(true).Foreground(lipgloss.Color("9")) - + titleStyles = lipgloss.NewStyle().PaddingLeft(0).Bold(true).Foreground(lipgloss.Color("9")) queryStyle = lipgloss.NewStyle().PaddingLeft(0).Foreground(lipgloss.Color("7")) itemStyle = lipgloss.NewStyle().PaddingLeft(4).Foreground(lipgloss.Color("8")) selectedItemStyle = lipgloss.NewStyle().PaddingLeft(1).Foreground(lipgloss.AdaptiveColor{Light: "16", Dark: "226"}) @@ -171,9 +170,6 @@ func (m modelFilter) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if msg.String() == "ctrl+c" { return m, tea.Quit } - if msg.String() == "q" { - return m, tea.Quit - } if msg.String() == "a" || msg.Type == tea.KeyEnter { selectedFilterApply = m.list.SelectedItem().(Item) return m, tea.Quit @@ -182,9 +178,8 @@ func (m modelFilter) Update(msg tea.Msg) (tea.Model, tea.Cmd) { deleteFilterState = true return m, nil } - if msg.String() != "d" { - deleteFilterState = false - return m, nil + if msg.String() != "d"{ + deleteFilterState = false; } if msg.String() == "y" { selectedFilterDelete = m.list.SelectedItem().(Item) From 5935677f514a79d994bf07561e7dc9fccb6a7c9a Mon Sep 17 00:00:00 2001 From: Koustav Date: Tue, 13 Aug 2024 18:02:57 +0530 Subject: [PATCH 7/9] Go fumpt'ed --- pkg/model/savedFilters.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/model/savedFilters.go b/pkg/model/savedFilters.go index a7bed3e..4dba2b4 100644 --- a/pkg/model/savedFilters.go +++ b/pkg/model/savedFilters.go @@ -39,7 +39,7 @@ const ( ) var ( - docStyle = lipgloss.NewStyle().Margin(1, 2) + docStyle = lipgloss.NewStyle().Margin(1, 2) deleteFilterState bool = false ) @@ -178,8 +178,8 @@ func (m modelFilter) Update(msg tea.Msg) (tea.Model, tea.Cmd) { deleteFilterState = true return m, nil } - if msg.String() != "d"{ - deleteFilterState = false; + if msg.String() != "d" { + deleteFilterState = false } if msg.String() == "y" { selectedFilterDelete = m.list.SelectedItem().(Item) From f957a9f7fa6d977b8269acb3b8fe72af6ddcab42 Mon Sep 17 00:00:00 2001 From: Koustav Date: Tue, 13 Aug 2024 18:05:41 +0530 Subject: [PATCH 8/9] Go fumpt'ed --- pkg/model/savedFilters.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/model/savedFilters.go b/pkg/model/savedFilters.go index 4dba2b4..8193aa2 100644 --- a/pkg/model/savedFilters.go +++ b/pkg/model/savedFilters.go @@ -20,11 +20,10 @@ import ( "fmt" "io" "net/http" + "pb/pkg/config" "strings" "time" - "pb/pkg/config" - "github.com/charmbracelet/bubbles/key" "github.com/charmbracelet/bubbles/list" tea "github.com/charmbracelet/bubbletea" @@ -40,7 +39,7 @@ const ( var ( docStyle = lipgloss.NewStyle().Margin(1, 2) - deleteFilterState bool = false + deleteFilterState = false ) // FilterDetails represents the structure of filter data From 1f7ae72e4ae0ea1027fcd517ad091c1d26ccd9a0 Mon Sep 17 00:00:00 2001 From: Koustav Date: Tue, 13 Aug 2024 18:08:00 +0530 Subject: [PATCH 9/9] Go fmt'ed --- pkg/model/savedFilters.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/model/savedFilters.go b/pkg/model/savedFilters.go index 8193aa2..5d2fd2b 100644 --- a/pkg/model/savedFilters.go +++ b/pkg/model/savedFilters.go @@ -38,7 +38,7 @@ const ( ) var ( - docStyle = lipgloss.NewStyle().Margin(1, 2) + docStyle = lipgloss.NewStyle().Margin(1, 2) deleteFilterState = false )