Whitelabelling: Override version in UI from config (#84392)

* Unify how the version is shown in the UI

* use versionString in dashboard help bundles

* fix lint

* remove comment

* fix test types

* make test less flakey
This commit is contained in:
Josh Hunt
2024-03-15 16:39:13 +00:00
committed by GitHub
parent 1ce2ae427f
commit f2628bfad4
11 changed files with 44 additions and 26 deletions

View File

@@ -127,6 +127,14 @@ func Sort(nodes []*NavLink) {
}
}
func (root *NavTreeRoot) ApplyHelpVersion(version string) {
helpNode := root.FindById("help")
if helpNode != nil {
helpNode.SubTitle = version
}
}
func (root *NavTreeRoot) ApplyAdminIA() {
orgAdminNode := root.FindById(NavIDCfg)

View File

@@ -1,7 +1,6 @@
package navtreeimpl
import (
"fmt"
"sort"
"github.com/grafana/grafana/pkg/api/dtos"
@@ -188,25 +187,11 @@ func isSupportBundlesEnabled(s *ServiceImpl) bool {
return s.cfg.SectionWithEnvOverrides("support_bundles").Key("enabled").MustBool(true)
}
// don't need to show the full commit hash in the UI
// let's substring to 10 chars like local git does automatically
func getShortCommitHash(commitHash string, maxLength int) string {
if len(commitHash) > maxLength {
return commitHash[:maxLength]
}
return commitHash
}
func (s *ServiceImpl) addHelpLinks(treeRoot *navtree.NavTreeRoot, c *contextmodel.ReqContext) {
if s.cfg.HelpEnabled {
helpVersion := fmt.Sprintf(`%s v%s (%s)`, setting.ApplicationName, setting.BuildVersion, getShortCommitHash(setting.BuildCommit, 10))
if s.cfg.AnonymousHideVersion && !c.IsSignedIn {
helpVersion = setting.ApplicationName
}
// The version subtitle is set later by NavTree.ApplyHelpVersion
helpNode := &navtree.NavLink{
Text: "Help",
SubTitle: helpVersion,
Id: "help",
Url: "#",
Icon: "question-circle",