Skip to content

Commit

Permalink
Board: add BoardQueryStyle
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenraad Verheyden committed Oct 13, 2020
1 parent 11ad749 commit 2c61e72
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
17 changes: 17 additions & 0 deletions board.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,29 @@ func BoardStyles() []BoardStyle {
// BoardQuery represents a query that is part of a board.
type BoardQuery struct {
Caption string `json:"caption,omitempty"`
// Defaults to graph.
QueryStyle BoardQueryStyle `json:"query_style,omitempty"`
// This field is required.
Dataset string `json:"dataset"`
// This field is required.
Query QuerySpec `json:"query"`
}

// BoardQueryStyle determines how a query should be displayed on the board.
type BoardQueryStyle string

// Declaration of board query styles.
const (
BoardQueryStyleGraph BoardQueryStyle = "graph"
BoardQueryStyleTable BoardQueryStyle = "table"
BoardQueryStyleCombo BoardQueryStyle = "combo"
)

// BoardQueryStyles returns an exhaustive list of board query styles.
func BoardQueryStyles() []BoardQueryStyle {
return []BoardQueryStyle{BoardQueryStyleGraph, BoardQueryStyleTable, BoardQueryStyleCombo}
}

func (s *boards) List(ctx context.Context) ([]Board, error) {
var b []Board
err := s.client.performRequest(ctx, "GET", "/1/boards", nil, &b)
Expand Down
12 changes: 8 additions & 4 deletions board_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ func TestBoards(t *testing.T) {
Style: BoardStyleVisual,
Queries: []BoardQuery{
{
Caption: "A sample query",
Dataset: dataset,
Caption: "A sample query",
QueryStyle: BoardQueryStyleCombo,
Dataset: dataset,
Query: QuerySpec{
Calculations: []CalculationSpec{
{
Op: CalculationOpAvg,
Column: StringPtr("duration_ms"),
},
},
TimeRange: IntPtr(3600), // 1 hour
},
},
},
Expand Down Expand Up @@ -69,14 +71,16 @@ func TestBoards(t *testing.T) {

t.Run("Update", func(t *testing.T) {
b.Queries = append(b.Queries, BoardQuery{
Caption: "A second query",
Dataset: dataset,
Caption: "A second query",
QueryStyle: BoardQueryStyleGraph,
Dataset: dataset,
Query: QuerySpec{
Calculations: []CalculationSpec{
{
Op: CalculationOpCount,
},
},
TimeRange: IntPtr(7200), // 2 hours
},
})

Expand Down

0 comments on commit 2c61e72

Please sign in to comment.