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

Filter/list #50

Closed
wants to merge 21 commits into from
Closed
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
3 changes: 2 additions & 1 deletion cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import (
"io"
"net/http"
"net/url"
"pb/pkg/config"
"time"

"pb/pkg/config"
)

type HTTPClient struct {
Expand Down
9 changes: 8 additions & 1 deletion cmd/filterList.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ package cmd
import (
"fmt"
"os"
"pb/pkg/model"
"strings"
"time"

"pb/pkg/model"

"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -53,6 +54,9 @@ var FilterList = &cobra.Command{

// Delete a saved filter from the list of filter
func deleteFilter(client *HTTPClient, filterID string) {
if filterID == "" {
return
}
deleteURL := `filters/filter/` + filterID
req, err := client.NewRequest("DELETE", deleteURL, nil)
if err != nil {
Expand All @@ -72,6 +76,9 @@ func deleteFilter(client *HTTPClient, filterID string) {

// Convert a filter to executable pb query
func filterToPbQuery(query string, start string, end string) {
if query == "" {
return
}
var timeStamps string
if start == "" || end == "" {
timeStamps = ``
Expand Down
1 change: 1 addition & 0 deletions cmd/pre.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package cmd
import (
"errors"
"os"

"pb/pkg/config"

"github.com/spf13/cobra"
Expand Down
1 change: 1 addition & 0 deletions cmd/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"net/url"
"os"

"pb/pkg/config"
"pb/pkg/model/credential"
"pb/pkg/model/defaultprofile"
Expand Down
6 changes: 5 additions & 1 deletion cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import (
"fmt"
"io"
"os"
"pb/pkg/config"
"strings"
"time"

"pb/pkg/config"

// "pb/pkg/model"

//! This dependency is required by the interactive flag Do not remove
Expand All @@ -44,11 +45,14 @@ var (
saveFilterFlag = "save-as"
saveFilterShort = "s"
// save filter with time flags
// save filter with time flags
saveFilterTimeFlag = "with-time"
saveFilterTimeShort = "w"

// interactiveFlag = "interactive"
// interactiveFlagShort = "i"
// interactiveFlag = "interactive"
// interactiveFlagShort = "i"
)

var query = &cobra.Command{
Expand Down
3 changes: 2 additions & 1 deletion cmd/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import (
"fmt"
"io"
"os"
"pb/pkg/model/role"
"strings"
"sync"

"pb/pkg/model/role"

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/spf13/cobra"
Expand Down
1 change: 1 addition & 0 deletions cmd/tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"

"pb/pkg/config"

"github.com/apache/arrow/go/v13/arrow/array"
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"errors"
"os"

"pb/cmd"
"pb/pkg/config"

Expand Down
5 changes: 3 additions & 2 deletions pkg/model/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ import (
"math"
"net/http"
"os"
"pb/pkg/config"
"pb/pkg/iterator"
"strings"
"sync"
"time"

"pb/pkg/config"
"pb/pkg/iterator"

"github.com/charmbracelet/bubbles/help"
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/textarea"
Expand Down
41 changes: 34 additions & 7 deletions pkg/model/savedFilters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand All @@ -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{}
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion pkg/model/timeinput.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ package model

import (
"fmt"
"pb/pkg/model/datetime"
"time"

"pb/pkg/model/datetime"

"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
Expand Down
Loading