Skip to content

Commit

Permalink
Update UI documentation link if it's present
Browse files Browse the repository at this point in the history
Signed-off-by: Ruben Vargas Palma <[email protected]>
  • Loading branch information
rubenvp8510 committed Nov 3, 2020
1 parent c418931 commit 96db555
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 2 deletions.
44 changes: 42 additions & 2 deletions pkg/strategy/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,53 @@ func disableDependenciesTab(uiOpts map[string]interface{}, storage v1.JaegerStor
}
}

func hasDocumentationLink(menus []interface{}) (bool, int) {
// Verify it a documentation entry exists.
// for now the only way we have to see if a documentation link exists is comparing searching by labels
for menuIndex, menuItem := range menus {
converted, ok := menuItem.(map[string]interface{})
if !ok {
return false, 0
}
if label, ok := converted["label"]; ok && label == "About" {
items := converted["items"]
convertedItems, ok := items.([]interface{})
if !ok {
return false, 0
}
for _, item := range convertedItems {
itemMap, ok := item.(map[string]interface{})
if !ok {
return false, 0
}
if itemLabel, ok := itemMap["label"]; ok && itemLabel == "Documentation" {
return true, menuIndex
}
}
}
}
return false, 0
}

func enableDocumentationLink(uiOpts map[string]interface{}, spec *v1.JaegerSpec) {
if !viper.IsSet("documentation-url") {
return
}

// if a custom menu has been specified, do not add the link to the documentation
if _, ok := uiOpts["menu"]; ok {
if menus, ok := uiOpts["menu"]; ok {
menuArray := menus.([]interface{})
// If a documentation menu exists, update it, otherwise is a custom menu, don't touch it.
if hasDocLink, menuIndex := hasDocumentationLink(menuArray); hasDocLink {
// Update menu link
e := map[string]interface{}{
"label": "About",
"items": []interface{}{map[string]interface{}{
"label": "Documentation",
"url": viper.GetString("documentation-url"),
}},
}
menuArray[menuIndex] = e
}
return
}

Expand Down
68 changes: 68 additions & 0 deletions pkg/strategy/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,74 @@ func TestMenuWithCustomDocURL(t *testing.T) {
assert.Equal(t, expected, uiOpts["menu"])
}

func TestUpdateMenuDocURL(t *testing.T) {
docURLv1 := "http://testv1/doc/url"
docURLv2 := "http://testv2/doc/url"

viper.Set("documentation-url", docURLv1)
defer viper.Reset()

uiOpts := map[string]interface{}{}

spec := &v1.JaegerSpec{Ingress: v1.JaegerIngressSpec{Security: v1.IngressSecurityOAuthProxy}}
enableDocumentationLink(uiOpts, spec)
assert.Contains(t, uiOpts, "menu")

expected := []interface{}{
map[string]interface{}{
"label": "About",
"items": []interface{}{
map[string]interface{}{
"label": "Documentation",
"url": docURLv1,
},
},
},
}
assert.Equal(t, expected, uiOpts["menu"])

viper.Set("documentation-url", docURLv2)
enableDocumentationLink(uiOpts, spec)
assert.Contains(t, uiOpts, "menu")

expected = []interface{}{
map[string]interface{}{
"label": "About",
"items": []interface{}{
map[string]interface{}{
"label": "Documentation",
"url": docURLv2,
},
},
},
}
assert.Equal(t, expected, uiOpts["menu"])

}

func TestNoDocWithCustomMenu(t *testing.T) {
viper.Set("documentation-url", "http://testv1/doc/url")
defer viper.Reset()

internalLink := map[string]interface{}{
"label": "Some internal links",
"items": []interface{}{
map[string]interface{}{
"label": "The internal link",
"url": "http://example.com/internal",
},
},
}
uiOpts := map[string]interface{}{
"menu": []interface{}{internalLink},
}

spec := &v1.JaegerSpec{Ingress: v1.JaegerIngressSpec{Security: v1.IngressSecurityOAuthProxy}}
enableDocumentationLink(uiOpts, spec)
assert.Equal(t, uiOpts, uiOpts)

}

func TestMenuNoLogOutIngressSecurityNone(t *testing.T) {
uiOpts := map[string]interface{}{}
spec := &v1.JaegerSpec{Ingress: v1.JaegerIngressSpec{Security: v1.IngressSecurityNoneExplicit}}
Expand Down

0 comments on commit 96db555

Please sign in to comment.