Navtree: Make it possible to configure standalone plugin pages (#56393)

* feat: make it possible to register standalone app plugin pages under different sections

* refactor(sample.ini): use "admin" instead of "starred" section in the INI

Co-authored-by: Torkel Ödegaard <torkel@grafana.com>

* feat(defaults.ini): add app navigation settings to the defaults.ini as well

* fix: use the correct key in the tests

Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
This commit is contained in:
Levente Balogh
2022-10-06 12:57:03 +02:00
committed by GitHub
co-authored by Torkel Ödegaard
parent b1df15c4b9
commit 55187ebc48
4 changed files with 49 additions and 7 deletions
+19 -3
View File
@@ -214,12 +214,13 @@ func (s *ServiceImpl) readNavigationSettings() {
"/a/grafana-auth-app": {SectionID: navtree.NavIDCfg, SortWeight: 7},
}
sec := s.cfg.Raw.Section("navigation.apps")
appSections := s.cfg.Raw.Section("navigation.app_sections")
appStandalonePages := s.cfg.Raw.Section("navigation.app_standalone_pages")
for _, key := range sec.Keys() {
for _, key := range appSections.Keys() {
pluginId := key.Name()
// Support <id> <weight> value
values := util.SplitString(sec.Key(key.Name()).MustString(""))
values := util.SplitString(appSections.Key(key.Name()).MustString(""))
appCfg := &NavigationAppConfig{SectionID: values[0]}
if len(values) > 1 {
@@ -230,4 +231,19 @@ func (s *ServiceImpl) readNavigationSettings() {
s.navigationAppConfig[pluginId] = *appCfg
}
for _, key := range appStandalonePages.Keys() {
url := key.Name()
// Support <id> <weight> value
values := util.SplitString(appStandalonePages.Key(key.Name()).MustString(""))
appCfg := &NavigationAppConfig{SectionID: values[0]}
if len(values) > 1 {
if weight, err := strconv.ParseInt(values[1], 10, 64); err == nil {
appCfg.SortWeight = weight
}
}
s.navigationAppPathConfig[url] = *appCfg
}
}
@@ -180,7 +180,7 @@ func TestReadingNavigationSettings(t *testing.T) {
cfg: setting.NewCfg(),
}
_, _ = service.cfg.Raw.NewSection("navigation.apps")
_, _ = service.cfg.Raw.NewSection("navigation.app_sections")
service.readNavigationSettings()
require.Equal(t, "monitoring", service.navigationAppConfig["grafana-k8s-app"].SectionID)
@@ -191,9 +191,11 @@ func TestReadingNavigationSettings(t *testing.T) {
cfg: setting.NewCfg(),
}
sec, _ := service.cfg.Raw.NewSection("navigation.apps")
_, _ = sec.NewKey("grafana-k8s-app", "dashboards")
_, _ = sec.NewKey("other-app", "admin 12")
appSections, _ := service.cfg.Raw.NewSection("navigation.app_sections")
appStandalonePages, _ := service.cfg.Raw.NewSection("navigation.app_standalone_pages")
_, _ = appSections.NewKey("grafana-k8s-app", "dashboards")
_, _ = appSections.NewKey("other-app", "admin 12")
_, _ = appStandalonePages.NewKey("/a/grafana-k8s-app/foo", "admin 30")
service.readNavigationSettings()
@@ -202,5 +204,8 @@ func TestReadingNavigationSettings(t *testing.T) {
require.Equal(t, int64(0), service.navigationAppConfig["grafana-k8s-app"].SortWeight)
require.Equal(t, int64(12), service.navigationAppConfig["other-app"].SortWeight)
require.Equal(t, "admin", service.navigationAppPathConfig["/a/grafana-k8s-app/foo"].SectionID)
require.Equal(t, int64(30), service.navigationAppPathConfig["/a/grafana-k8s-app/foo"].SortWeight)
})
}