diff --git a/bolt/dashboard.go b/bolt/dashboard.go index 7250c7f978..3af3d2bc24 100644 --- a/bolt/dashboard.go +++ b/bolt/dashboard.go @@ -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) } diff --git a/dashboard.go b/dashboard.go index 5f66c96de1..073da1bb87 100644 --- a/dashboard.go +++ b/dashboard.go @@ -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"` } diff --git a/dashboard_test.go b/dashboard_test.go index 3c3c4fc941..c96c0ec04d 100644 --- a/dashboard_test.go +++ b/dashboard_test.go @@ -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) { @@ -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{ @@ -34,6 +36,7 @@ func TestView_MarshalJSON(t *testing.T) { wants: wants{ json: ` { + "id": "f01dab1ef005ba11", "name": "hello", "properties": { "shape": "chronograf-v2", diff --git a/http/dashboard_service.go b/http/dashboard_service.go index 33a367c993..f3a1746f4f 100644 --- a/http/dashboard_service.go +++ b/http/dashboard_service.go @@ -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, } diff --git a/http/swagger.yml b/http/swagger.yml index 18f4f35c7f..9780ab167e 100644 --- a/http/swagger.yml +++ b/http/swagger.yml @@ -6717,6 +6717,9 @@ components: properties: self: type: string + id: + readOnly: true + type: string name: type: string properties: @@ -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 @@ -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: diff --git a/inmem/dashboard.go b/inmem/dashboard.go index 9b60fbac2a..8ec93e8458 100644 --- a/inmem/dashboard.go +++ b/inmem/dashboard.go @@ -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. @@ -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, } @@ -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 } @@ -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, @@ -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 } diff --git a/kv/dashboard.go b/kv/dashboard.go index 5defd401e5..8c04636a69 100644 --- a/kv/dashboard.go +++ b/kv/dashboard.go @@ -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) } diff --git a/testing/dashboards.go b/testing/dashboards.go index 11819539ab..c3efe3e4e8 100644 --- a/testing/dashboards.go +++ b/testing/dashboards.go @@ -264,7 +264,7 @@ func AddDashboardCell( Views: []*platform.View{ { ViewContents: platform.ViewContents{ - Name: "view2", + ID: MustIDBase16(dashTwoID), }, }, }, @@ -312,7 +312,7 @@ func AddDashboardCell( Views: []*platform.View{ { ViewContents: platform.ViewContents{ - Name: "view2", + ID: MustIDBase16(dashTwoID), }, }, }, @@ -358,7 +358,7 @@ func AddDashboardCell( Views: []*platform.View{ { ViewContents: platform.ViewContents{ - Name: "view2", + ID: MustIDBase16(dashTwoID), }, }, }, @@ -1258,7 +1258,7 @@ func RemoveDashboardCell( Views: []*platform.View{ { ViewContents: platform.ViewContents{ - Name: "view2", + ID: MustIDBase16(dashTwoID), }, }, }, @@ -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), }, }, }, @@ -1619,7 +1619,7 @@ func ReplaceDashboardCells( Views: []*platform.View{ { ViewContents: platform.ViewContents{ - Name: "view2", + ID: MustIDBase16(dashTwoID), }, }, }, @@ -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{}, }, }, }, @@ -1831,6 +1833,7 @@ func UpdateDashboardCellView( wants: wants{ view: &platform.View{ ViewContents: platform.ViewContents{ + ID: 100, Name: "hello", }, Properties: platform.EmptyViewProperties{}, @@ -1856,7 +1859,6 @@ func UpdateDashboardCellView( args: args{ dashboardID: 1, cellID: 100, - name: "view100", properties: platform.TableViewProperties{ Type: "table", TimeFormat: "rfc3339", @@ -1865,7 +1867,7 @@ func UpdateDashboardCellView( wants: wants{ view: &platform.View{ ViewContents: platform.ViewContents{ - Name: "view100", + ID: 100, }, Properties: platform.TableViewProperties{ Type: "table", @@ -1902,6 +1904,7 @@ func UpdateDashboardCellView( wants: wants{ view: &platform.View{ ViewContents: platform.ViewContents{ + ID: 100, Name: "hello", }, Properties: platform.TableViewProperties{