Navigation: Add pluginId to standalone plugin page NavLinks (#57769)

* feat(Navigation): add `pluginId` to NavLink and override sibling navlinks with the same URL

* test replacing page from plugin

* chore: fix go lint issues

* fix(NavLink): change `PluginId` to `PluginID`

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

* fix(NavLink): make the `PluginId` -> `PluginID` change everywhere

* chore(navModel.ts): update explanatory comment for `pluginId`

Co-authored-by: Miklós Tolnai <miklos.tolnai@grafana.com>
Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
This commit is contained in:
Levente Balogh
2022-11-03 21:19:42 +01:00
committed by GitHub
co-authored by Torkel Ödegaard Miklós Tolnai
parent 6fcc5b42c0
commit 376f4b0cc7
4 changed files with 70 additions and 6 deletions
+27 -5
View File
@@ -72,6 +72,7 @@ func (s *ServiceImpl) processAppPlugin(plugin plugins.PluginDTO, c *models.ReqCo
Section: navtree.NavSectionPlugin,
SortWeight: navtree.WeightPlugin,
IsSection: true,
PluginID: plugin.ID,
}
if topNavEnabled {
@@ -87,8 +88,9 @@ func (s *ServiceImpl) processAppPlugin(plugin plugins.PluginDTO, c *models.ReqCo
if include.Type == "page" && include.AddToNav {
link := &navtree.NavLink{
Text: include.Name,
Icon: include.Icon,
Text: include.Name,
Icon: include.Icon,
PluginID: plugin.ID,
}
if len(include.Path) > 0 {
@@ -100,11 +102,30 @@ func (s *ServiceImpl) processAppPlugin(plugin plugins.PluginDTO, c *models.ReqCo
link.Url = s.cfg.AppSubURL + "/plugins/" + plugin.ID + "/page/" + include.Slug
}
// Register standalone plugin pages to certain sections using the Grafana config
if pathConfig, ok := s.navigationAppPathConfig[include.Path]; ok {
if sectionForPage := treeRoot.FindById(pathConfig.SectionID); sectionForPage != nil {
link.Id = "standalone-plugin-page-" + include.Path
link.SortWeight = pathConfig.SortWeight
sectionForPage.Children = append(sectionForPage.Children, link)
// Check if the section already has a page with the same URL, and in that case override it
// (This only happens if it is explicitly set by `navigation.app_standalone_pages` in the INI config)
isOverridingCorePage := false
for _, child := range sectionForPage.Children {
if child.Url == link.Url {
child.Id = link.Id
child.SortWeight = link.SortWeight
child.PluginID = link.PluginID
child.Children = []*navtree.NavLink{}
isOverridingCorePage = true
break
}
}
// Append the page to the section
if !isOverridingCorePage {
sectionForPage.Children = append(sectionForPage.Children, link)
}
}
} else {
appLink.Children = append(appLink.Children, link)
@@ -115,8 +136,9 @@ func (s *ServiceImpl) processAppPlugin(plugin plugins.PluginDTO, c *models.ReqCo
dboardURL := include.DashboardURLPath()
if dboardURL != "" {
link := &navtree.NavLink{
Url: path.Join(s.cfg.AppSubURL, dboardURL),
Text: include.Name,
Url: path.Join(s.cfg.AppSubURL, dboardURL),
Text: include.Name,
PluginID: plugin.ID,
}
appLink.Children = append(appLink.Children, link)
}