Chore: Remove dashboards from models pkg (#61578)
* Copy dashboard models to dashboard pkg * Use some models from current pkg instead of models * Adjust api pkg * Adjust pkg services * Fix lint * Chore: Remove dashboards models * Remove dashboards from models pkg * Fix lint in tests * Fix lint in tests 2 * Fix for import in auth * Remove newline * Revert unused fix
This commit is contained in:
@@ -3,7 +3,7 @@ package plugindashboards
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
)
|
||||
|
||||
// PluginDashboard plugin dashboard model..
|
||||
@@ -43,7 +43,7 @@ type LoadPluginDashboardRequest struct {
|
||||
|
||||
// LoadPluginDashboardResponse response object for loading a plugin dashboard.
|
||||
type LoadPluginDashboardResponse struct {
|
||||
Dashboard *models.Dashboard
|
||||
Dashboard *dashboards.Dashboard
|
||||
}
|
||||
|
||||
// Service interface for listing plugin dashboards.
|
||||
|
||||
@@ -143,14 +143,14 @@ func (du *DashboardUpdater) handlePluginStateChanged(ctx context.Context, event
|
||||
|
||||
du.syncPluginDashboards(ctx, p, event.OrgId)
|
||||
} else {
|
||||
query := models.GetDashboardsByPluginIdQuery{PluginId: event.PluginId, OrgId: event.OrgId}
|
||||
query := dashboards.GetDashboardsByPluginIDQuery{PluginID: event.PluginId, OrgID: event.OrgId}
|
||||
if err := du.dashboardPluginService.GetDashboardsByPluginID(ctx, &query); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, dash := range query.Result {
|
||||
du.logger.Info("Deleting plugin dashboard", "pluginId", event.PluginId, "dashboard", dash.Slug)
|
||||
if err := du.dashboardService.DeleteDashboard(ctx, dash.Id, dash.OrgId); err != nil {
|
||||
if err := du.dashboardService.DeleteDashboard(ctx, dash.ID, dash.OrgID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,8 +210,8 @@ func TestDashboardUpdater(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, ctx.dashboardPluginService.args, 1)
|
||||
require.Equal(t, int64(2), ctx.dashboardPluginService.args[0].OrgId)
|
||||
require.Equal(t, "test", ctx.dashboardPluginService.args[0].PluginId)
|
||||
require.Equal(t, int64(2), ctx.dashboardPluginService.args[0].OrgID)
|
||||
require.Equal(t, "test", ctx.dashboardPluginService.args[0].PluginID)
|
||||
require.Empty(t, ctx.dashboardService.deleteDashboardArgs)
|
||||
})
|
||||
})
|
||||
@@ -258,8 +258,8 @@ func TestDashboardUpdater(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, ctx.dashboardPluginService.args, 1)
|
||||
require.Equal(t, int64(2), ctx.dashboardPluginService.args[0].OrgId)
|
||||
require.Equal(t, "test", ctx.dashboardPluginService.args[0].PluginId)
|
||||
require.Equal(t, int64(2), ctx.dashboardPluginService.args[0].OrgID)
|
||||
require.Equal(t, "test", ctx.dashboardPluginService.args[0].PluginID)
|
||||
require.Len(t, ctx.dashboardService.deleteDashboardArgs, 3)
|
||||
})
|
||||
|
||||
@@ -458,7 +458,7 @@ func (s *dashboardServiceMock) DeleteDashboard(_ context.Context, dashboardId in
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *dashboardServiceMock) GetDashboardByPublicUid(ctx context.Context, dashboardPublicUid string) (*models.Dashboard, error) {
|
||||
func (s *dashboardServiceMock) GetDashboardByPublicUid(ctx context.Context, dashboardPublicUid string) (*dashboards.Dashboard, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -514,14 +514,14 @@ func scenario(t *testing.T, desc string, input scenarioInput, f func(ctx *scenar
|
||||
pluginFunc: getPlugin,
|
||||
}
|
||||
|
||||
pluginDashboards := map[string][]*models.Dashboard{}
|
||||
pluginDashboards := map[string][]*dashboards.Dashboard{}
|
||||
for _, pluginDashboard := range input.pluginDashboards {
|
||||
if _, exists := pluginDashboards[pluginDashboard.PluginId]; !exists {
|
||||
pluginDashboards[pluginDashboard.PluginId] = []*models.Dashboard{}
|
||||
pluginDashboards[pluginDashboard.PluginId] = []*dashboards.Dashboard{}
|
||||
}
|
||||
|
||||
pluginDashboards[pluginDashboard.PluginId] = append(pluginDashboards[pluginDashboard.PluginId], &models.Dashboard{
|
||||
PluginId: pluginDashboard.PluginId,
|
||||
pluginDashboards[pluginDashboard.PluginId] = append(pluginDashboards[pluginDashboard.PluginId], &dashboards.Dashboard{
|
||||
PluginID: pluginDashboard.PluginId,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -554,7 +554,7 @@ func scenario(t *testing.T, desc string, input scenarioInput, f func(ctx *scenar
|
||||
for _, d := range input.pluginDashboards {
|
||||
if d.PluginId == req.PluginID && req.Reference == d.Reference {
|
||||
return &plugindashboards.LoadPluginDashboardResponse{
|
||||
Dashboard: &models.Dashboard{},
|
||||
Dashboard: &dashboards.Dashboard{},
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
pluginDashboardsManager "github.com/grafana/grafana/pkg/plugins/manager/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/plugindashboards"
|
||||
@@ -42,7 +41,7 @@ func (s Service) ListPluginDashboards(ctx context.Context, req *plugindashboards
|
||||
result := make([]*plugindashboards.PluginDashboard, 0)
|
||||
|
||||
// load current dashboards
|
||||
query := models.GetDashboardsByPluginIdQuery{OrgId: req.OrgID, PluginId: req.PluginID}
|
||||
query := dashboards.GetDashboardsByPluginIDQuery{OrgID: req.OrgID, PluginID: req.PluginID}
|
||||
if err := s.dashboardPluginService.GetDashboardsByPluginID(ctx, &query); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -61,7 +60,7 @@ func (s Service) ListPluginDashboards(ctx context.Context, req *plugindashboards
|
||||
dashboard := loadResp.Dashboard
|
||||
|
||||
res := &plugindashboards.PluginDashboard{}
|
||||
res.UID = dashboard.Uid
|
||||
res.UID = dashboard.UID
|
||||
res.Reference = reference
|
||||
res.PluginId = req.PluginID
|
||||
res.Title = dashboard.Title
|
||||
@@ -70,13 +69,13 @@ func (s Service) ListPluginDashboards(ctx context.Context, req *plugindashboards
|
||||
// find existing dashboard
|
||||
for _, existingDash := range query.Result {
|
||||
if existingDash.Slug == dashboard.Slug {
|
||||
res.UID = existingDash.Uid
|
||||
res.DashboardId = existingDash.Id
|
||||
res.UID = existingDash.UID
|
||||
res.DashboardId = existingDash.ID
|
||||
res.Imported = true
|
||||
res.ImportedUri = "db/" + existingDash.Slug
|
||||
res.ImportedUrl = existingDash.GetUrl()
|
||||
res.ImportedUrl = existingDash.GetURL()
|
||||
res.ImportedRevision = existingDash.Data.Get("revision").MustInt64(1)
|
||||
existingMatches[existingDash.Id] = true
|
||||
existingMatches[existingDash.ID] = true
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -86,11 +85,11 @@ func (s Service) ListPluginDashboards(ctx context.Context, req *plugindashboards
|
||||
|
||||
// find deleted dashboards
|
||||
for _, dash := range query.Result {
|
||||
if _, exists := existingMatches[dash.Id]; !exists {
|
||||
if _, exists := existingMatches[dash.ID]; !exists {
|
||||
result = append(result, &plugindashboards.PluginDashboard{
|
||||
UID: dash.Uid,
|
||||
UID: dash.UID,
|
||||
Slug: dash.Slug,
|
||||
DashboardId: dash.Id,
|
||||
DashboardId: dash.ID,
|
||||
Removed: true,
|
||||
})
|
||||
}
|
||||
@@ -127,7 +126,7 @@ func (s Service) LoadPluginDashboard(ctx context.Context, req *plugindashboards.
|
||||
}
|
||||
|
||||
return &plugindashboards.LoadPluginDashboardResponse{
|
||||
Dashboard: models.NewDashboardFromJson(data),
|
||||
Dashboard: dashboards.NewDashboardFromJson(data),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/dashboards"
|
||||
dashmodels "github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/plugindashboards"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -39,10 +39,10 @@ func TestGetPluginDashboards(t *testing.T) {
|
||||
},
|
||||
}
|
||||
dashboardPluginService := &dashboardPluginServiceMock{
|
||||
pluginDashboards: map[string][]*models.Dashboard{
|
||||
pluginDashboards: map[string][]*dashmodels.Dashboard{
|
||||
"test-app": {
|
||||
models.NewDashboardFromJson(testDashboardOld),
|
||||
models.NewDashboardFromJson(testDashboardDeleted),
|
||||
dashmodels.NewDashboardFromJson(testDashboardOld),
|
||||
dashmodels.NewDashboardFromJson(testDashboardDeleted),
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -203,19 +203,19 @@ func (m pluginDashboardStoreMock) GetPluginDashboardFileContents(ctx context.Con
|
||||
}
|
||||
|
||||
type dashboardPluginServiceMock struct {
|
||||
pluginDashboards map[string][]*models.Dashboard
|
||||
args []*models.GetDashboardsByPluginIdQuery
|
||||
pluginDashboards map[string][]*dashmodels.Dashboard
|
||||
args []*dashmodels.GetDashboardsByPluginIDQuery
|
||||
}
|
||||
|
||||
func (d *dashboardPluginServiceMock) GetDashboardsByPluginID(ctx context.Context, query *models.GetDashboardsByPluginIdQuery) error {
|
||||
query.Result = []*models.Dashboard{}
|
||||
func (d *dashboardPluginServiceMock) GetDashboardsByPluginID(ctx context.Context, query *dashmodels.GetDashboardsByPluginIDQuery) error {
|
||||
query.Result = []*dashmodels.Dashboard{}
|
||||
|
||||
if dashboards, exists := d.pluginDashboards[query.PluginId]; exists {
|
||||
if dashboards, exists := d.pluginDashboards[query.PluginID]; exists {
|
||||
query.Result = dashboards
|
||||
}
|
||||
|
||||
if d.args == nil {
|
||||
d.args = []*models.GetDashboardsByPluginIdQuery{}
|
||||
d.args = []*dashmodels.GetDashboardsByPluginIDQuery{}
|
||||
}
|
||||
|
||||
d.args = append(d.args, query)
|
||||
|
||||
Reference in New Issue
Block a user