Merge pull request #13417 from influxdata/revert-view-id

Revert "remove view ID"
pull/13406/head
Jade McGough 2019-04-15 15:06:40 -07:00 committed by GitHub
commit 9414be11b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 45 additions and 22 deletions

View File

@ -304,6 +304,8 @@ func (c *Client) createCellView(ctx context.Context, tx *bolt.Tx, dashID, cellID
// If not view exists create the view // If not view exists create the view
view = &platform.View{} view = &platform.View{}
} }
// TODO: this is temporary until we can fully remove the view service.
view.ID = cellID
return c.putDashboardCellView(ctx, tx, dashID, cellID, view) return c.putDashboardCellView(ctx, tx, dashID, cellID, view)
} }

View File

@ -288,8 +288,9 @@ type View struct {
Properties ViewProperties Properties ViewProperties
} }
// ViewContents holds the non properties content of a View. // ViewContents is the id and name of a specific view.
type ViewContents struct { type ViewContents struct {
ID ID `json:"id,omitempty"`
Name string `json:"name"` Name string `json:"name"`
} }

View File

@ -6,6 +6,7 @@ import (
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
platform "github.com/influxdata/influxdb" platform "github.com/influxdata/influxdb"
platformtesting "github.com/influxdata/influxdb/testing"
) )
func TestView_MarshalJSON(t *testing.T) { func TestView_MarshalJSON(t *testing.T) {
@ -24,6 +25,7 @@ func TestView_MarshalJSON(t *testing.T) {
args: args{ args: args{
view: platform.View{ view: platform.View{
ViewContents: platform.ViewContents{ ViewContents: platform.ViewContents{
ID: platformtesting.MustIDBase16("f01dab1ef005ba11"),
Name: "hello", Name: "hello",
}, },
Properties: platform.XYViewProperties{ Properties: platform.XYViewProperties{
@ -34,6 +36,7 @@ func TestView_MarshalJSON(t *testing.T) {
wants: wants{ wants: wants{
json: ` json: `
{ {
"id": "f01dab1ef005ba11",
"name": "hello", "name": "hello",
"properties": { "properties": {
"shape": "chronograf-v2", "shape": "chronograf-v2",

View File

@ -266,7 +266,7 @@ func (r dashboardCellViewResponse) MarshalJSON() ([]byte, error) {
func newDashboardCellViewResponse(dashID, cellID platform.ID, v *platform.View) dashboardCellViewResponse { func newDashboardCellViewResponse(dashID, cellID platform.ID, v *platform.View) dashboardCellViewResponse {
return dashboardCellViewResponse{ return dashboardCellViewResponse{
Links: viewLinks{ Links: viewLinks{
Self: fmt.Sprintf("/api/v2/dashboards/%s/cells/%s/view", dashID, cellID), Self: fmt.Sprintf("/api/v2/dashboards/%s/cells/%s", dashID, cellID),
}, },
View: *v, View: *v,
} }

View File

@ -6717,6 +6717,9 @@ components:
properties: properties:
self: self:
type: string type: string
id:
readOnly: true
type: string
name: name:
type: string type: string
properties: properties:
@ -6746,6 +6749,9 @@ components:
h: h:
type: integer type: integer
format: int32 format: int32
viewID:
type: string
description: uses the view provided in the request
usingView: usingView:
type: string type: string
description: makes a copy of the provided view description: makes a copy of the provided view
@ -6789,6 +6795,9 @@ components:
h: h:
type: integer type: integer
format: int32 format: int32
viewID:
type: string
description: The reference to a view from the views API
Cells: Cells:
type: array type: array
items: items:

View File

@ -154,7 +154,8 @@ func (s *Service) PutDashboard(ctx context.Context, d *platform.Dashboard) error
// PutCellView puts the view for a cell. // PutCellView puts the view for a cell.
func (s *Service) PutCellView(ctx context.Context, cell *platform.Cell) error { func (s *Service) PutCellView(ctx context.Context, cell *platform.Cell) error {
v := &platform.View{} v := &platform.View{}
return s.PutView(ctx, cell.ID, v) v.ID = cell.ID
return s.PutView(ctx, v)
} }
// PutDashboardWithMeta sets a dashboard while updating the meta field of a dashboard. // PutDashboardWithMeta sets a dashboard while updating the meta field of a dashboard.
@ -249,7 +250,8 @@ func (s *Service) AddDashboardCell(ctx context.Context, id platform.ID, cell *pl
func (s *Service) createCellView(ctx context.Context, cell *platform.Cell) *platform.Error { func (s *Service) createCellView(ctx context.Context, cell *platform.Cell) *platform.Error {
// If not view exists create the view // If not view exists create the view
view := &platform.View{} view := &platform.View{}
if err := s.PutView(ctx, cell.ID, view); err != nil { view.ID = cell.ID
if err := s.PutView(ctx, view); err != nil {
return &platform.Error{ return &platform.Error{
Err: err, Err: err,
} }
@ -265,7 +267,8 @@ func (s *Service) PutDashboardCell(ctx context.Context, id platform.ID, cell *pl
return err return err
} }
view := &platform.View{} view := &platform.View{}
if err := s.PutView(ctx, cell.ID, view); err != nil { view.ID = cell.ID
if err := s.PutView(ctx, view); err != nil {
return err return err
} }
@ -433,7 +436,7 @@ func (s *Service) UpdateDashboardCellView(ctx context.Context, dashboardID, cell
} }
} }
if err := s.PutView(ctx, cellID, v); err != nil { if err := s.PutView(ctx, v); err != nil {
return nil, &platform.Error{ return nil, &platform.Error{
Err: err, Err: err,
Op: op, Op: op,
@ -471,12 +474,12 @@ func (s *Service) FindViewByID(ctx context.Context, id platform.ID) (*platform.V
return v, nil return v, nil
} }
// PutView sets view with the cell ID. // PutView sets view with the current ID.
func (s *Service) PutView(ctx context.Context, cellID platform.ID, v *platform.View) error { func (s *Service) PutView(ctx context.Context, c *platform.View) error {
if v.Properties == nil { if c.Properties == nil {
v.Properties = platform.EmptyViewProperties{} c.Properties = platform.EmptyViewProperties{}
} }
s.viewKV.Store(cellID.String(), v) s.viewKV.Store(c.ID.String(), c)
return nil return nil
} }

View File

@ -332,6 +332,8 @@ func (s *Service) createCellView(ctx context.Context, tx Tx, dashID, cellID infl
// If not view exists create the view // If not view exists create the view
view = &influxdb.View{} view = &influxdb.View{}
} }
// TODO: this is temporary until we can fully remove the view service.
view.ID = cellID
return s.putDashboardCellView(ctx, tx, dashID, cellID, view) return s.putDashboardCellView(ctx, tx, dashID, cellID, view)
} }

View File

@ -264,7 +264,7 @@ func AddDashboardCell(
Views: []*platform.View{ Views: []*platform.View{
{ {
ViewContents: platform.ViewContents{ ViewContents: platform.ViewContents{
Name: "view2", ID: MustIDBase16(dashTwoID),
}, },
}, },
}, },
@ -312,7 +312,7 @@ func AddDashboardCell(
Views: []*platform.View{ Views: []*platform.View{
{ {
ViewContents: platform.ViewContents{ ViewContents: platform.ViewContents{
Name: "view2", ID: MustIDBase16(dashTwoID),
}, },
}, },
}, },
@ -358,7 +358,7 @@ func AddDashboardCell(
Views: []*platform.View{ Views: []*platform.View{
{ {
ViewContents: platform.ViewContents{ ViewContents: platform.ViewContents{
Name: "view2", ID: MustIDBase16(dashTwoID),
}, },
}, },
}, },
@ -1258,7 +1258,7 @@ func RemoveDashboardCell(
Views: []*platform.View{ Views: []*platform.View{
{ {
ViewContents: platform.ViewContents{ ViewContents: platform.ViewContents{
Name: "view2", ID: MustIDBase16(dashTwoID),
}, },
}, },
}, },
@ -1546,12 +1546,12 @@ func ReplaceDashboardCells(
Views: []*platform.View{ Views: []*platform.View{
{ {
ViewContents: platform.ViewContents{ ViewContents: platform.ViewContents{
Name: "view2", ID: MustIDBase16(dashTwoID),
}, },
}, },
{ {
ViewContents: platform.ViewContents{ ViewContents: platform.ViewContents{
Name: "view1", ID: MustIDBase16(dashOneID),
}, },
}, },
}, },
@ -1619,7 +1619,7 @@ func ReplaceDashboardCells(
Views: []*platform.View{ Views: []*platform.View{
{ {
ViewContents: platform.ViewContents{ ViewContents: platform.ViewContents{
Name: "view2", ID: MustIDBase16(dashTwoID),
}, },
}, },
}, },
@ -1734,7 +1734,9 @@ func GetDashboardCellView(
}, },
wants: wants{ wants: wants{
view: &platform.View{ view: &platform.View{
ViewContents: platform.ViewContents{}, ViewContents: platform.ViewContents{
ID: 100,
},
Properties: platform.EmptyViewProperties{}, Properties: platform.EmptyViewProperties{},
}, },
}, },
@ -1831,6 +1833,7 @@ func UpdateDashboardCellView(
wants: wants{ wants: wants{
view: &platform.View{ view: &platform.View{
ViewContents: platform.ViewContents{ ViewContents: platform.ViewContents{
ID: 100,
Name: "hello", Name: "hello",
}, },
Properties: platform.EmptyViewProperties{}, Properties: platform.EmptyViewProperties{},
@ -1856,7 +1859,6 @@ func UpdateDashboardCellView(
args: args{ args: args{
dashboardID: 1, dashboardID: 1,
cellID: 100, cellID: 100,
name: "view100",
properties: platform.TableViewProperties{ properties: platform.TableViewProperties{
Type: "table", Type: "table",
TimeFormat: "rfc3339", TimeFormat: "rfc3339",
@ -1865,7 +1867,7 @@ func UpdateDashboardCellView(
wants: wants{ wants: wants{
view: &platform.View{ view: &platform.View{
ViewContents: platform.ViewContents{ ViewContents: platform.ViewContents{
Name: "view100", ID: 100,
}, },
Properties: platform.TableViewProperties{ Properties: platform.TableViewProperties{
Type: "table", Type: "table",
@ -1902,6 +1904,7 @@ func UpdateDashboardCellView(
wants: wants{ wants: wants{
view: &platform.View{ view: &platform.View{
ViewContents: platform.ViewContents{ ViewContents: platform.ViewContents{
ID: 100,
Name: "hello", Name: "hello",
}, },
Properties: platform.TableViewProperties{ Properties: platform.TableViewProperties{