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

Revert "remove view ID" #13417

Merged
merged 2 commits into from
Apr 15, 2019
Merged
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
2 changes: 2 additions & 0 deletions bolt/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ func (c *Client) createCellView(ctx context.Context, tx *bolt.Tx, dashID, cellID
// If not view exists create the 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)
}

Expand Down
3 changes: 2 additions & 1 deletion dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,9 @@ type View struct {
Properties ViewProperties
}

// ViewContents holds the non properties content of a View.
// ViewContents is the id and name of a specific view.
type ViewContents struct {
ID ID `json:"id,omitempty"`
Name string `json:"name"`
}

Expand Down
3 changes: 3 additions & 0 deletions dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/google/go-cmp/cmp"
platform "github.com/influxdata/influxdb"
platformtesting "github.com/influxdata/influxdb/testing"
)

func TestView_MarshalJSON(t *testing.T) {
Expand All @@ -24,6 +25,7 @@ func TestView_MarshalJSON(t *testing.T) {
args: args{
view: platform.View{
ViewContents: platform.ViewContents{
ID: platformtesting.MustIDBase16("f01dab1ef005ba11"),
Name: "hello",
},
Properties: platform.XYViewProperties{
Expand All @@ -34,6 +36,7 @@ func TestView_MarshalJSON(t *testing.T) {
wants: wants{
json: `
{
"id": "f01dab1ef005ba11",
"name": "hello",
"properties": {
"shape": "chronograf-v2",
Expand Down
2 changes: 1 addition & 1 deletion http/dashboard_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func (r dashboardCellViewResponse) MarshalJSON() ([]byte, error) {
func newDashboardCellViewResponse(dashID, cellID platform.ID, v *platform.View) dashboardCellViewResponse {
return dashboardCellViewResponse{
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,
}
Expand Down
9 changes: 9 additions & 0 deletions http/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6717,6 +6717,9 @@ components:
properties:
self:
type: string
id:
readOnly: true
type: string
name:
type: string
properties:
Expand Down Expand Up @@ -6746,6 +6749,9 @@ components:
h:
type: integer
format: int32
viewID:
type: string
description: uses the view provided in the request
usingView:
type: string
description: makes a copy of the provided view
Expand Down Expand Up @@ -6789,6 +6795,9 @@ components:
h:
type: integer
format: int32
viewID:
type: string
description: The reference to a view from the views API
Cells:
type: array
items:
Expand Down
21 changes: 12 additions & 9 deletions inmem/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ func (s *Service) PutDashboard(ctx context.Context, d *platform.Dashboard) error
// PutCellView puts the view for a cell.
func (s *Service) PutCellView(ctx context.Context, cell *platform.Cell) error {
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.
Expand Down Expand Up @@ -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 {
// If not view exists create the 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{
Err: err,
}
Expand All @@ -265,7 +267,8 @@ func (s *Service) PutDashboardCell(ctx context.Context, id platform.ID, cell *pl
return err
}
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
}

Expand Down Expand Up @@ -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{
Err: err,
Op: op,
Expand Down Expand Up @@ -471,12 +474,12 @@ func (s *Service) FindViewByID(ctx context.Context, id platform.ID) (*platform.V
return v, nil
}

// PutView sets view with the cell ID.
func (s *Service) PutView(ctx context.Context, cellID platform.ID, v *platform.View) error {
if v.Properties == nil {
v.Properties = platform.EmptyViewProperties{}
// PutView sets view with the current ID.
func (s *Service) PutView(ctx context.Context, c *platform.View) error {
if c.Properties == nil {
c.Properties = platform.EmptyViewProperties{}
}
s.viewKV.Store(cellID.String(), v)
s.viewKV.Store(c.ID.String(), c)
return nil
}

Expand Down
2 changes: 2 additions & 0 deletions kv/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ func (s *Service) createCellView(ctx context.Context, tx Tx, dashID, cellID infl
// If not view exists create the 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)
}

Expand Down
25 changes: 14 additions & 11 deletions testing/dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func AddDashboardCell(
Views: []*platform.View{
{
ViewContents: platform.ViewContents{
Name: "view2",
ID: MustIDBase16(dashTwoID),
},
},
},
Expand Down Expand Up @@ -312,7 +312,7 @@ func AddDashboardCell(
Views: []*platform.View{
{
ViewContents: platform.ViewContents{
Name: "view2",
ID: MustIDBase16(dashTwoID),
},
},
},
Expand Down Expand Up @@ -358,7 +358,7 @@ func AddDashboardCell(
Views: []*platform.View{
{
ViewContents: platform.ViewContents{
Name: "view2",
ID: MustIDBase16(dashTwoID),
},
},
},
Expand Down Expand Up @@ -1258,7 +1258,7 @@ func RemoveDashboardCell(
Views: []*platform.View{
{
ViewContents: platform.ViewContents{
Name: "view2",
ID: MustIDBase16(dashTwoID),
},
},
},
Expand Down Expand Up @@ -1546,12 +1546,12 @@ func ReplaceDashboardCells(
Views: []*platform.View{
{
ViewContents: platform.ViewContents{
Name: "view2",
ID: MustIDBase16(dashTwoID),
},
},
{
ViewContents: platform.ViewContents{
Name: "view1",
ID: MustIDBase16(dashOneID),
},
},
},
Expand Down Expand Up @@ -1619,7 +1619,7 @@ func ReplaceDashboardCells(
Views: []*platform.View{
{
ViewContents: platform.ViewContents{
Name: "view2",
ID: MustIDBase16(dashTwoID),
},
},
},
Expand Down Expand Up @@ -1734,8 +1734,10 @@ func GetDashboardCellView(
},
wants: wants{
view: &platform.View{
ViewContents: platform.ViewContents{},
Properties: platform.EmptyViewProperties{},
ViewContents: platform.ViewContents{
ID: 100,
},
Properties: platform.EmptyViewProperties{},
},
},
},
Expand Down Expand Up @@ -1831,6 +1833,7 @@ func UpdateDashboardCellView(
wants: wants{
view: &platform.View{
ViewContents: platform.ViewContents{
ID: 100,
Name: "hello",
},
Properties: platform.EmptyViewProperties{},
Expand All @@ -1856,7 +1859,6 @@ func UpdateDashboardCellView(
args: args{
dashboardID: 1,
cellID: 100,
name: "view100",
properties: platform.TableViewProperties{
Type: "table",
TimeFormat: "rfc3339",
Expand All @@ -1865,7 +1867,7 @@ func UpdateDashboardCellView(
wants: wants{
view: &platform.View{
ViewContents: platform.ViewContents{
Name: "view100",
ID: 100,
},
Properties: platform.TableViewProperties{
Type: "table",
Expand Down Expand Up @@ -1902,6 +1904,7 @@ func UpdateDashboardCellView(
wants: wants{
view: &platform.View{
ViewContents: platform.ViewContents{
ID: 100,
Name: "hello",
},
Properties: platform.TableViewProperties{
Expand Down