Skip to content

Commit 2902d1e

Browse files
authored
Sort repo topic labels by name (#24123)
Close #24077
1 parent ed81b60 commit 2902d1e

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

models/repo/topic.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,16 @@ func (opts *FindTopicOptions) toConds() builder.Cond {
194194
// FindTopics retrieves the topics via FindTopicOptions
195195
func FindTopics(opts *FindTopicOptions) ([]*Topic, int64, error) {
196196
sess := db.GetEngine(db.DefaultContext).Select("topic.*").Where(opts.toConds())
197+
orderBy := "topic.repo_count DESC"
197198
if opts.RepoID > 0 {
198199
sess.Join("INNER", "repo_topic", "repo_topic.topic_id = topic.id")
200+
orderBy = "topic.name" // when render topics for a repo, it's better to sort them by name, to get consistent result
199201
}
200202
if opts.PageSize != 0 && opts.Page != 0 {
201203
sess = db.SetSessionPagination(sess, opts)
202204
}
203205
topics := make([]*Topic, 0, 10)
204-
total, err := sess.Desc("topic.repo_count").FindAndCount(&topics)
206+
total, err := sess.OrderBy(orderBy).FindAndCount(&topics)
205207
return topics, total, err
206208
}
207209

routers/web/repo/blame.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212

1313
repo_model "code.gitea.io/gitea/models/repo"
1414
user_model "code.gitea.io/gitea/models/user"
15-
"code.gitea.io/gitea/modules/base"
1615
"code.gitea.io/gitea/modules/charset"
1716
"code.gitea.io/gitea/modules/context"
1817
"code.gitea.io/gitea/modules/git"
@@ -23,10 +22,6 @@ import (
2322
"code.gitea.io/gitea/modules/util"
2423
)
2524

26-
const (
27-
tplBlame base.TplName = "repo/home"
28-
)
29-
3025
type blameRow struct {
3126
RowNumber int
3227
Avatar gotemplate.HTML
@@ -140,7 +135,7 @@ func RefBlame(ctx *context.Context) {
140135

141136
renderBlame(ctx, blameParts, commitNames, previousCommits)
142137

143-
ctx.HTML(http.StatusOK, tplBlame)
138+
ctx.HTML(http.StatusOK, tplRepoHome)
144139
}
145140

146141
func processBlameParts(ctx *context.Context, blameParts []git.BlamePart) (map[string]*user_model.UserCommit, map[string]string) {

web_src/js/features/repo-home.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export function initRepoTopicBar() {
4141
viewDiv.children('.topic').remove();
4242
if (topics.length) {
4343
const topicArray = topics.split(',');
44+
topicArray.sort();
4445
for (let i = 0; i < topicArray.length; i++) {
4546
const link = $('<a class="ui repo-topic large label topic"></a>');
4647
link.attr('href', `${appSubUrl}/explore/repos?q=${encodeURIComponent(topicArray[i])}&topic=1`);
@@ -57,12 +58,12 @@ export function initRepoTopicBar() {
5758
topicPrompts.formatPrompt = xhr.responseJSON.message;
5859

5960
const {invalidTopics} = xhr.responseJSON;
60-
const topicLables = topicDropdown.children('a.ui.label');
61+
const topicLabels = topicDropdown.children('a.ui.label');
6162

6263
for (const [index, value] of topics.split(',').entries()) {
6364
for (let i = 0; i < invalidTopics.length; i++) {
6465
if (invalidTopics[i] === value) {
65-
topicLables.eq(index).removeClass('green').addClass('red');
66+
topicLabels.eq(index).removeClass('green').addClass('red');
6667
}
6768
}
6869
}

0 commit comments

Comments
 (0)