Highlight the correct small menu item when viewing a tag

When viewing a tag that isn't associated with a release, highlight the
"N Tags" sub-menu item, rather than the "M releases" one.

Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
This commit is contained in:
Gergely Nagy 2024-02-27 13:19:18 +01:00
parent fc635f1014
commit c9b410fb35
No known key found for this signature in database
2 changed files with 11 additions and 3 deletions

View file

@ -5,9 +5,9 @@
<div class="gt-df">
<div class="gt-f1 gt-df gt-ac">
<h2 class="ui compact small menu header small-menu-items">
<a class="{{if .PageIsReleaseList}}active {{end}}item" href="{{.RepoLink}}/releases">{{ctx.Locale.PrettyNumber .NumReleases}} {{ctx.Locale.TrN .NumReleases "repo.release" "repo.releases"}}</a>
<a class="{{if and .PageIsReleaseList (not .PageIsSingleTag)}}active {{end}}item" href="{{.RepoLink}}/releases">{{ctx.Locale.PrettyNumber .NumReleases}} {{ctx.Locale.TrN .NumReleases "repo.release" "repo.releases"}}</a>
{{if $canReadCode}}
<a class="{{if .PageIsTagList}}active {{end}}item" href="{{.RepoLink}}/tags">{{ctx.Locale.PrettyNumber .NumTags}} {{ctx.Locale.TrN .NumTags "repo.tag" "repo.tags"}}</a>
<a class="{{if or .PageIsTagList .PageIsSingleTag}}active {{end}}item" href="{{.RepoLink}}/tags">{{ctx.Locale.PrettyNumber .NumTags}} {{ctx.Locale.TrN .NumTags "repo.tag" "repo.tags"}}</a>
{{end}}
</h2>
</div>

View file

@ -47,7 +47,15 @@ func TestTagViewWithoutRelease(t *testing.T) {
// Test that the page loads
req := NewRequestf(t, "GET", "/%s/releases/tag/no-release", repo.FullName())
MakeRequest(t, req, http.StatusOK)
resp := MakeRequest(t, req, http.StatusOK)
// Test that the tags sub-menu is active
htmlDoc := NewHTMLParser(t, resp.Body)
htmlDoc.AssertElement(t, ".small-menu-items .active.item[href*='/tags']", true)
// Test that the release sub-menu isn't active
releaseLink := htmlDoc.Find(".small-menu-items .item[href*='/releases']")
assert.False(t, releaseLink.HasClass("active"))
}
func TestCreateNewTagProtected(t *testing.T) {