From 9f36e36c89996262040046e385566fd7aec03771 Mon Sep 17 00:00:00 2001 From: Serge Zaitsev Date: Thu, 22 Jul 2021 09:11:33 +0200 Subject: [PATCH] Pick changes from PR 33811, use UID in dashboard navlinks (#36899) * pick changes from PR 33811, use UID in dashboard navlinks * use proper spelling for UID * add uid to the plugin schema * Update docs/sources/developers/plugins/plugin.schema.json Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> --- docs/sources/developers/plugins/plugin.schema.json | 4 ++++ pkg/api/index.go | 2 +- pkg/plugins/app_plugin.go | 2 +- pkg/plugins/models.go | 9 +++++++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/sources/developers/plugins/plugin.schema.json b/docs/sources/developers/plugins/plugin.schema.json index 6d986382ad5..4da5583afbe 100644 --- a/docs/sources/developers/plugins/plugin.schema.json +++ b/docs/sources/developers/plugins/plugin.schema.json @@ -62,6 +62,10 @@ "type": "object", "additionalItems": false, "properties": { + "uid": { + "type": "string", + "description": "Unique identifier of the included resource" + }, "type": { "type": "string", "enum": ["dashboard", "page", "panel", "datasource"] diff --git a/pkg/api/index.go b/pkg/api/index.go index fe4ccf416f5..07b900b7988 100644 --- a/pkg/api/index.go +++ b/pkg/api/index.go @@ -110,7 +110,7 @@ func (hs *HTTPServer) getAppLinks(c *models.ReqContext) ([]*dtos.NavLink, error) if include.Type == "dashboard" && include.AddToNav { link := &dtos.NavLink{ - Url: hs.Cfg.AppSubURL + "/dashboard/db/" + include.Slug, + Url: hs.Cfg.AppSubURL + include.GetSlugOrUIDLink(), Text: include.Name, } appLink.Children = append(appLink.Children, link) diff --git a/pkg/plugins/app_plugin.go b/pkg/plugins/app_plugin.go index cb734924853..a5d1f5f738a 100644 --- a/pkg/plugins/app_plugin.go +++ b/pkg/plugins/app_plugin.go @@ -117,7 +117,7 @@ func (app *AppPlugin) InitApp(panels map[string]*PanelPlugin, dataSources map[st app.DefaultNavUrl = cfg.AppSubURL + "/plugins/" + app.Id + "/page/" + include.Slug } if include.Type == "dashboard" && include.DefaultNav { - app.DefaultNavUrl = cfg.AppSubURL + "/dashboard/db/" + include.Slug + app.DefaultNavUrl = cfg.AppSubURL + include.GetSlugOrUIDLink() } } diff --git a/pkg/plugins/models.go b/pkg/plugins/models.go index 9eb104d20c3..e4672d7657f 100644 --- a/pkg/plugins/models.go +++ b/pkg/plugins/models.go @@ -95,10 +95,19 @@ type PluginInclude struct { DefaultNav bool `json:"defaultNav"` Slug string `json:"slug"` Icon string `json:"icon"` + UID string `json:"uid"` Id string `json:"-"` } +func (e PluginInclude) GetSlugOrUIDLink() string { + if len(e.UID) > 0 { + return "/d/" + e.UID + } else { + return "/dashboard/db/" + e.Slug + } +} + type PluginDependencyItem struct { Type string `json:"type"` Id string `json:"id"`