Feat/filter view type (#1781)
* update swagger * WIP filter views on type * add GetType to view interfacepull/10616/head
parent
4d7a675316
commit
2a615712a6
20
bolt/view.go
20
bolt/view.go
|
@ -3,6 +3,7 @@ package bolt
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"sync"
|
||||
|
||||
bolt "github.com/coreos/bbolt"
|
||||
"github.com/influxdata/platform"
|
||||
|
@ -108,14 +109,25 @@ func (c *Client) FindView(ctx context.Context, filter platform.ViewFilter) (*pla
|
|||
return d, nil
|
||||
}
|
||||
|
||||
func filterViewsFn(filter platform.ViewFilter) func(d *platform.View) bool {
|
||||
func filterViewsFn(filter platform.ViewFilter) func(v *platform.View) bool {
|
||||
if filter.ID != nil {
|
||||
return func(d *platform.View) bool {
|
||||
return d.ID == *filter.ID
|
||||
return func(v *platform.View) bool {
|
||||
return v.ID == *filter.ID
|
||||
}
|
||||
}
|
||||
|
||||
return func(d *platform.View) bool { return true }
|
||||
if len(filter.Types) > 0 {
|
||||
var sm sync.Map
|
||||
for _, t := range filter.Types {
|
||||
sm.Store(t, true)
|
||||
}
|
||||
return func(v *platform.View) bool {
|
||||
_, ok := sm.Load(v.Properties.GetType())
|
||||
return ok
|
||||
}
|
||||
}
|
||||
|
||||
return func(v *platform.View) bool { return true }
|
||||
}
|
||||
|
||||
// FindViews retrives all views that match an arbitrary view filter.
|
||||
|
|
|
@ -865,6 +865,19 @@ paths:
|
|||
required: true
|
||||
schema:
|
||||
type: string
|
||||
- in: query
|
||||
name: type
|
||||
description: filters results to a specified type. Can be used multiple times in a request, to filter to multiple types.
|
||||
schema:
|
||||
type: string
|
||||
enum:
|
||||
- "xy"
|
||||
- "single-stat"
|
||||
- "gauge"
|
||||
- "table"
|
||||
- "markdown"
|
||||
- "log-viewer"
|
||||
- "line-plus-single-stat"
|
||||
responses:
|
||||
'200':
|
||||
description: all views
|
||||
|
|
|
@ -91,8 +91,10 @@ func newViewResponse(c *platform.View) viewResponse {
|
|||
// handleGetViews returns all views within the store.
|
||||
func (h *ViewHandler) handleGetViews(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
// TODO(desa): support filtering via query params
|
||||
views, _, err := h.ViewService.FindViews(ctx, platform.ViewFilter{})
|
||||
|
||||
req := decodeGetViewsRequest(ctx, r)
|
||||
|
||||
views, _, err := h.ViewService.FindViews(ctx, req.filter)
|
||||
if err != nil {
|
||||
EncodeError(ctx, errors.InternalErrorf("Error loading views: %v", err), w)
|
||||
return
|
||||
|
@ -104,6 +106,20 @@ func (h *ViewHandler) handleGetViews(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
type getViewsRequest struct {
|
||||
filter platform.ViewFilter
|
||||
}
|
||||
|
||||
func decodeGetViewsRequest(ctx context.Context, r *http.Request) *getViewsRequest {
|
||||
qp := r.URL.Query()
|
||||
|
||||
return &getViewsRequest{
|
||||
filter: platform.ViewFilter{
|
||||
Types: qp["type"],
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type getViewsLinks struct {
|
||||
Self string `json:"self"`
|
||||
}
|
||||
|
|
14
view.go
14
view.go
|
@ -52,7 +52,8 @@ type ViewContentsUpdate struct {
|
|||
|
||||
// ViewFilter represents a set of filter that restrict the returned results.
|
||||
type ViewFilter struct {
|
||||
ID *ID
|
||||
ID *ID
|
||||
Types []string
|
||||
}
|
||||
|
||||
// View holds positional and visual information for a View.
|
||||
|
@ -70,6 +71,7 @@ type ViewContents struct {
|
|||
// ViewProperties is used to mark other structures as conforming to a View.
|
||||
type ViewProperties interface {
|
||||
viewProperties()
|
||||
GetType() string
|
||||
}
|
||||
|
||||
// EmptyViewProperties is visualization that has no values
|
||||
|
@ -77,6 +79,8 @@ type EmptyViewProperties struct{}
|
|||
|
||||
func (v EmptyViewProperties) viewProperties() {}
|
||||
|
||||
func (v EmptyViewProperties) GetType() string { return "" }
|
||||
|
||||
// UnmarshalViewPropertiesJSON unmarshals JSON bytes into a ViewProperties.
|
||||
func UnmarshalViewPropertiesJSON(b []byte) (ViewProperties, error) {
|
||||
var v struct {
|
||||
|
@ -389,6 +393,14 @@ func (TableViewProperties) viewProperties() {}
|
|||
func (MarkdownViewProperties) viewProperties() {}
|
||||
func (LogViewProperties) viewProperties() {}
|
||||
|
||||
func (v XYViewProperties) GetType() string { return v.Type }
|
||||
func (v LinePlusSingleStatProperties) GetType() string { return v.Type }
|
||||
func (v SingleStatViewProperties) GetType() string { return v.Type }
|
||||
func (v GaugeViewProperties) GetType() string { return v.Type }
|
||||
func (v TableViewProperties) GetType() string { return v.Type }
|
||||
func (v MarkdownViewProperties) GetType() string { return v.Type }
|
||||
func (v LogViewProperties) GetType() string { return v.Type }
|
||||
|
||||
/////////////////////////////
|
||||
// Old Chronograf Types
|
||||
/////////////////////////////
|
||||
|
|
Loading…
Reference in New Issue