Skip to content

Commit 1657bfd

Browse files
KN4CK3Rsilverwindwxiaoguang
committed
Improve user search display name (go-gitea#29002)
I tripped over this strange method and I don't think we need that workaround to fix the value. old: ![grafik](https://github.com/go-gitea/gitea/assets/1666336/c8b6797b-eb45-4dec-99db-1b0649a34ec5) new: ![grafik](https://github.com/go-gitea/gitea/assets/1666336/ab1a65ae-de5b-4ce4-9813-3b8b39c7922e) --------- Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
1 parent 60fd9f4 commit 1657bfd

File tree

8 files changed

+18
-29
lines changed

8 files changed

+18
-29
lines changed

routers/utils/utils.go

-8
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,6 @@ import (
1111
"code.gitea.io/gitea/modules/setting"
1212
)
1313

14-
// RemoveUsernameParameterSuffix returns the username parameter without the (fullname) suffix - leaving just the username
15-
func RemoveUsernameParameterSuffix(name string) string {
16-
if index := strings.Index(name, " ("); index >= 0 {
17-
name = name[:index]
18-
}
19-
return name
20-
}
21-
2214
// SanitizeFlashErrorString will sanitize a flash error string
2315
func SanitizeFlashErrorString(x string) string {
2416
return strings.ReplaceAll(html.EscapeString(x), "\n", "<br>")

routers/utils/utils_test.go

-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ import (
1111
"github.com/stretchr/testify/assert"
1212
)
1313

14-
func TestRemoveUsernameParameterSuffix(t *testing.T) {
15-
assert.Equal(t, "foobar", RemoveUsernameParameterSuffix("foobar (Foo Bar)"))
16-
assert.Equal(t, "foobar", RemoveUsernameParameterSuffix("foobar"))
17-
assert.Equal(t, "", RemoveUsernameParameterSuffix(""))
18-
}
19-
2014
func TestIsExternalURL(t *testing.T) {
2115
setting.AppURL = "https://try.gitea.io/"
2216
type test struct {

routers/web/org/teams.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"code.gitea.io/gitea/modules/log"
2525
"code.gitea.io/gitea/modules/setting"
2626
"code.gitea.io/gitea/modules/web"
27-
"code.gitea.io/gitea/routers/utils"
2827
shared_user "code.gitea.io/gitea/routers/web/shared/user"
2928
"code.gitea.io/gitea/services/convert"
3029
"code.gitea.io/gitea/services/forms"
@@ -127,7 +126,7 @@ func TeamsAction(ctx *context.Context) {
127126
ctx.Error(http.StatusNotFound)
128127
return
129128
}
130-
uname := utils.RemoveUsernameParameterSuffix(strings.ToLower(ctx.FormString("uname")))
129+
uname := strings.ToLower(ctx.FormString("uname"))
131130
var u *user_model.User
132131
u, err = user_model.GetUserByName(ctx, uname)
133132
if err != nil {

routers/web/repo/setting/collaboration.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"code.gitea.io/gitea/modules/log"
1818
repo_module "code.gitea.io/gitea/modules/repository"
1919
"code.gitea.io/gitea/modules/setting"
20-
"code.gitea.io/gitea/routers/utils"
2120
"code.gitea.io/gitea/services/mailer"
2221
org_service "code.gitea.io/gitea/services/org"
2322
repo_service "code.gitea.io/gitea/services/repository"
@@ -52,7 +51,7 @@ func Collaboration(ctx *context.Context) {
5251

5352
// CollaborationPost response for actions for a collaboration of a repository
5453
func CollaborationPost(ctx *context.Context) {
55-
name := utils.RemoveUsernameParameterSuffix(strings.ToLower(ctx.FormString("collaborator")))
54+
name := strings.ToLower(ctx.FormString("collaborator"))
5655
if len(name) == 0 || ctx.Repo.Owner.LowerName == name {
5756
ctx.Redirect(setting.AppSubURL + ctx.Req.URL.EscapedPath())
5857
return
@@ -144,7 +143,7 @@ func AddTeamPost(ctx *context.Context) {
144143
return
145144
}
146145

147-
name := utils.RemoveUsernameParameterSuffix(strings.ToLower(ctx.FormString("team")))
146+
name := strings.ToLower(ctx.FormString("team"))
148147
if len(name) == 0 {
149148
ctx.Redirect(ctx.Repo.RepoLink + "/settings/collaboration")
150149
return

web_src/css/base.css

+4
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,14 @@ a.label,
196196
.ui.search > .results {
197197
background: var(--color-body);
198198
border-color: var(--color-secondary);
199+
overflow-wrap: anywhere; /* allow text to wrap as fomantic limits this to 18em width */
199200
}
200201

201202
.ui.search > .results .result {
202203
background: var(--color-body);
204+
border-color: var(--color-secondary);
205+
display: flex;
206+
align-items: center;
203207
}
204208

205209
.ui.search > .results .result .title {

web_src/css/repo.css

+5-3
Original file line numberDiff line numberDiff line change
@@ -2128,14 +2128,16 @@
21282128
}
21292129

21302130
#search-user-box .results .result .image {
2131-
float: left;
2132-
margin-right: 8px;
2131+
order: 0;
2132+
margin-right: 12px;
21332133
width: 2em;
21342134
height: 2em;
2135+
min-width: 2em;
2136+
min-height: 2em;
21352137
}
21362138

21372139
#search-user-box .results .result .content {
2138-
margin: 6px 0; /* this trick is used to align with the sibling avatar image */
2140+
margin: 0; /* remove margin reserved for avatar because we move it to left via `order: 0` */
21392141
}
21402142

21412143
.ui.menu .item > img:not(.ui) {

web_src/js/features/comp/SearchUserBox.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ export function initCompSearchUserBox() {
1717
const searchQuery = $searchUserBox.find('input').val();
1818
const searchQueryUppercase = searchQuery.toUpperCase();
1919
$.each(response.data, (_i, item) => {
20-
let title = item.login;
21-
if (item.full_name && item.full_name.length > 0) {
22-
title += ` (${htmlEscape(item.full_name)})`;
23-
}
2420
const resultItem = {
25-
title,
21+
title: item.login,
2622
image: item.avatar_url
2723
};
24+
if (item.full_name) {
25+
resultItem.description = htmlEscape(item.full_name);
26+
}
2827
if (searchQueryUppercase === item.login.toUpperCase()) {
2928
items.unshift(resultItem);
3029
} else {

web_src/js/features/repo-settings.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ export function initRepoSettingSearchTeamBox() {
5252
onResponse(response) {
5353
const items = [];
5454
$.each(response.data, (_i, item) => {
55-
const title = `${item.name} (${item.permission} access)`;
5655
items.push({
57-
title,
56+
title: item.name,
57+
description: `${item.permission} access` // TODO: translate this string
5858
});
5959
});
6060

0 commit comments

Comments
 (0)