Plugins: Extend panel menu with links from plugins (#63089)

* feat(plugins): introduce dashboard panel menu placement for adding menu items

* test: add test for getPanelMenu()

* added an unique identifier for each extension.

* added context to getPluginExtensions.

* wip

* Wip

* wiwip

* Wip

* feat: WWWIIIIPPPP 🧨

* Wip

* Renamed some of the types to align a bit better.

* added limit to how many extensions a plugin can register per placement.

* decreased number of items to 2

* will trim the lenght of titles to max 25 chars.

* wrapping configure function with error handling.

* added error handling for all scenarios.

* moved extension menu items to the bottom of the more sub menu.

* added tests for configuring the title.

* minor refactorings.

* changed so you need to specify the full path in package.json.

* wip

* removed unused type.

* big refactor to make things simpler and to centralize all configure error/validation handling.

* added missing import.

* fixed failing tests.

* fixed tests.

* revert(extensions): remove static extensions config in favour of registering via AppPlugin APIs

* removed the compose that didn't work for some reason.

* added tests just to verify that validation and error handling is tied together in configuration function.

* adding some more values to the context.

* draft validation.

* added missing tests for getPanelMenu.

* added more tests.

* refactor(extensions): move logic for validating extension link config to function

* Fixed ts errors.

* Update packages/grafana-data/src/types/app.ts

Co-authored-by: Levente Balogh <balogh.levente.hu@gmail.com>

* Update packages/grafana-runtime/src/services/pluginExtensions/extensions.test.ts

Co-authored-by: Levente Balogh <balogh.levente.hu@gmail.com>

* refactor(extensions): rename limiter -> pluginPlacementCount

* refactor(getpanelmenu): remove redundant continue statement

---------

Co-authored-by: Levente Balogh <balogh.levente.hu@gmail.com>
Co-authored-by: Marcus Andersson <marcus.andersson@grafana.com>
This commit is contained in:
Jack Westbrook
2023-03-02 15:42:00 +01:00
committed by GitHub
parent 5bd2fac9c8
commit 8c8f584b41
36 changed files with 1382 additions and 713 deletions
+19 -134
View File
@@ -16,7 +16,6 @@ import (
"github.com/grafana/grafana/pkg/login/social"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/plugins/config"
"github.com/grafana/grafana/pkg/plugins/plugindef"
"github.com/grafana/grafana/pkg/plugins/pluginscdn"
accesscontrolmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
"github.com/grafana/grafana/pkg/services/featuremgmt"
@@ -215,47 +214,25 @@ func TestHTTPServer_GetFrontendSettings_apps(t *testing.T) {
expected settings
}{
{
desc: "app without extensions",
desc: "disabled app with preload",
pluginStore: func() plugins.Store {
return &plugins.FakePluginStore{
PluginList: newPlugins("test-app", nil),
}
},
pluginSettings: func() pluginSettings.Service {
return &pluginSettings.FakePluginSettings{
Plugins: newAppSettings("test-app", true),
}
},
expected: settings{
Apps: map[string]*plugins.AppDTO{
"test-app": {
ID: "test-app",
Preload: false,
Path: "/test-app/module.js",
Version: "0.5.0",
Extensions: nil,
},
},
},
},
{
desc: "enabled app with link extensions",
pluginStore: func() plugins.Store {
return &plugins.FakePluginStore{
PluginList: newPlugins("test-app", []*plugindef.ExtensionsLink{
PluginList: []plugins.PluginDTO{
{
Placement: "core/home/menu",
Type: plugindef.ExtensionsLinkTypeLink,
Title: "Title",
Description: "Home route of app",
Path: "/home",
Module: fmt.Sprintf("/%s/module.js", "test-app"),
JSONData: plugins.JSONData{
ID: "test-app",
Info: plugins.Info{Version: "0.5.0"},
Type: plugins.App,
Preload: true,
},
},
}),
},
}
},
pluginSettings: func() pluginSettings.Service {
return &pluginSettings.FakePluginSettings{
Plugins: newAppSettings("test-app", true),
Plugins: newAppSettings("test-app", false),
}
},
expected: settings{
@@ -265,82 +242,6 @@ func TestHTTPServer_GetFrontendSettings_apps(t *testing.T) {
Preload: false,
Path: "/test-app/module.js",
Version: "0.5.0",
Extensions: []*plugindef.ExtensionsLink{
{
Placement: "core/home/menu",
Type: plugindef.ExtensionsLinkTypeLink,
Title: "Title",
Description: "Home route of app",
Path: "/home",
},
},
},
},
},
},
{
desc: "disabled app with link extensions",
pluginStore: func() plugins.Store {
return &plugins.FakePluginStore{
PluginList: newPlugins("test-app", []*plugindef.ExtensionsLink{
{
Placement: "core/home/menu",
Type: plugindef.ExtensionsLinkTypeLink,
Title: "Title",
Description: "Home route of app",
Path: "/home",
},
}),
}
},
pluginSettings: func() pluginSettings.Service {
return &pluginSettings.FakePluginSettings{
Plugins: newAppSettings("test-app", false),
}
},
expected: settings{
Apps: map[string]*plugins.AppDTO{
"test-app": {
ID: "test-app",
Preload: false,
Path: "/test-app/module.js",
Version: "0.5.0",
Extensions: nil,
},
},
},
},
{
desc: "disabled app with preload",
pluginStore: func() plugins.Store {
return &plugins.FakePluginStore{
PluginList: []plugins.PluginDTO{
{
Module: fmt.Sprintf("/%s/module.js", "test-app"),
JSONData: plugins.JSONData{
ID: "test-app",
Info: plugins.Info{Version: "0.5.0"},
Type: plugins.App,
Extensions: []*plugindef.ExtensionsLink{},
Preload: true,
},
},
},
}
},
pluginSettings: func() pluginSettings.Service {
return &pluginSettings.FakePluginSettings{
Plugins: newAppSettings("test-app", false),
}
},
expected: settings{
Apps: map[string]*plugins.AppDTO{
"test-app": {
ID: "test-app",
Preload: false,
Path: "/test-app/module.js",
Version: "0.5.0",
Extensions: nil,
},
},
},
@@ -353,11 +254,10 @@ func TestHTTPServer_GetFrontendSettings_apps(t *testing.T) {
{
Module: fmt.Sprintf("/%s/module.js", "test-app"),
JSONData: plugins.JSONData{
ID: "test-app",
Info: plugins.Info{Version: "0.5.0"},
Type: plugins.App,
Extensions: []*plugindef.ExtensionsLink{},
Preload: true,
ID: "test-app",
Info: plugins.Info{Version: "0.5.0"},
Type: plugins.App,
Preload: true,
},
},
},
@@ -371,11 +271,10 @@ func TestHTTPServer_GetFrontendSettings_apps(t *testing.T) {
expected: settings{
Apps: map[string]*plugins.AppDTO{
"test-app": {
ID: "test-app",
Preload: true,
Path: "/test-app/module.js",
Version: "0.5.0",
Extensions: nil,
ID: "test-app",
Preload: true,
Path: "/test-app/module.js",
Version: "0.5.0",
},
},
},
@@ -409,17 +308,3 @@ func newAppSettings(id string, enabled bool) map[string]*pluginSettings.DTO {
},
}
}
func newPlugins(id string, extensions []*plugindef.ExtensionsLink) []plugins.PluginDTO {
return []plugins.PluginDTO{
{
Module: fmt.Sprintf("/%s/module.js", id),
JSONData: plugins.JSONData{
ID: id,
Info: plugins.Info{Version: "0.5.0"},
Type: plugins.App,
Extensions: extensions,
},
},
}
}