Skip to content

Commit abdebd2

Browse files
silverwindlafrikszeripathlunny
authored
Rework repo buttons (#20602)
* Rework repo buttons - Replace "New PR" and "Go to File" button with Icon Button - Move all "Add File" actions into a dropdown button - Remove most custom styling of clone buttons - Margin and wiki tweaks Buttons are now all equal height, mobile layout wraps gracefully. Fixes: #13671 Replaces: #20375 Co-authored-by: Lauris BH <[email protected]> Co-authored-by: zeripath <[email protected]> Co-authored-by: Lunny Xiao <[email protected]>
1 parent be82489 commit abdebd2

File tree

11 files changed

+120
-143
lines changed

11 files changed

+120
-143
lines changed

Diff for: options/locale/locale_en-US.ini

+1
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,7 @@ normal_view = Normal View
10631063
line = line
10641064
lines = lines
10651065

1066+
editor.add_file = Add File
10661067
editor.new_file = New File
10671068
editor.upload_file = Upload File
10681069
editor.edit_file = Edit File

Diff for: templates/repo/branch_dropdown.tmpl

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
{{$release := .release}}
22
{{$defaultBranch := $.root.BranchName}}{{if and .root.IsViewTag (not .noTag)}}{{$defaultBranch = .root.TagName}}{{end}}{{if eq $defaultBranch ""}}{{$defaultBranch = $.root.Repository.DefaultBranch}}{{end}}
3+
{{$type := ""}}{{if and .root.IsViewTag (not .noTag)}}{{$type = "tag"}}{{else if .root.IsViewBranch}}{{$type = "branch"}}{{else}}{{$type = "tree"}}{{end}}
34
{{$showBranchesInDropdown := not .root.HideBranchesInDropdown}}
45
<div class="fitted item choose reference{{if not $release}} mr-1{{end}}">
56
<div class="ui floating filter dropdown custom"
67
data-branch-form="{{if $.branchForm}}{{$.branchForm}}{{end}}"
78
data-can-create-branch="{{if .canCreateBranch}}{{.canCreateBranch}}{{else}}{{.root.CanCreateBranch}}{{end}}"
89
data-no-results="{{.root.locale.Tr "repo.pulls.no_results"}}"
910
data-set-action="{{.setAction}}" data-submit-form="{{.submitForm}}"
10-
data-view-type="{{if and .root.IsViewTag (not .noTag)}}tag{{else if .root.IsViewBranch}}branch{{else}}tree{{end}}"
11+
data-view-type="{{$type}}"
1112
data-ref-name="{{if and .root.IsViewTag (not .noTag)}}{{.root.TagName}}{{else if .root.IsViewBranch}}{{.root.BranchName}}{{else}}{{ShortSha .root.CommitID}}{{end}}"
1213
data-branch-url-prefix="{{if .branchURLPrefix}}{{.branchURLPrefix}}{{else}}{{$.root.RepoLink}}/{{if $.root.PageIsCommits}}commits{{else}}src{{end}}/branch/{{end}}"
1314
data-branch-url-suffix="{{if .branchURLSuffix}}{{.branchURLSuffix}}{{else}}{{if $.root.TreePath}}/{{PathEscapeSegments $.root.TreePath}}{{end}}{{end}}"
1415
data-tag-url-prefix="{{if .tagURLPrefix}}{{.tagURLPrefix}}{{else if $release}}{{$.root.RepoLink}}/compare/{{else}}{{$.root.RepoLink}}/{{if $.root.PageIsCommits}}commits{{else}}src{{end}}/tag/{{end}}"
1516
data-tag-url-suffix="{{if .tagURLSuffix}}{{.tagURLSuffix}}{{else if $release}}...{{if $release.IsDraft}}{{PathEscapeSegments $release.Target}}{{else}}{{if $release.TagName}}{{PathEscapeSegments $release.TagName}}{{else}}{{PathEscapeSegments $release.Sha1}}{{end}}{{end}}{{else}}{{if $.root.TreePath}}/{{PathEscapeSegments $.root.TreePath}}{{end}}{{end}}">
16-
<div class="ui basic small compact button" @click="menuVisible = !menuVisible" @keyup.enter="menuVisible = !menuVisible">
17+
<div class="branch-dropdown-button ellipsis ui basic small compact button" @click="menuVisible = !menuVisible" @keyup.enter="menuVisible = !menuVisible">
1718
<span class="text">
1819
{{if $release}}
1920
{{.root.locale.Tr "repo.release.compare"}}
2021
{{else}}
21-
<span :class="{visible: isViewTag}" v-if="isViewTag" v-cloak>{{svg "octicon-tag"}} {{.root.locale.Tr "repo.tag"}}:</span>
22-
<span :class="{visible: isViewBranch}" v-if="isViewBranch" v-cloak>{{svg "octicon-git-branch"}} {{.root.locale.Tr "repo.branch"}}:</span>
23-
<span :class="{visible: isViewTree}" v-if="isViewTree" v-cloak>{{svg "octicon-git-branch"}} {{.root.locale.Tr "repo.tree"}}:</span>
22+
<span :class="{visible: isViewTag}" v-if="isViewTag" {{if not (eq $type "tag")}}v-cloak{{end}}>{{svg "octicon-tag"}} {{.root.locale.Tr "repo.tag"}}:</span>
23+
<span :class="{visible: isViewBranch}" v-if="isViewBranch" {{if not (eq $type "branch")}}v-cloak{{end}}>{{svg "octicon-git-branch"}} {{.root.locale.Tr "repo.branch"}}:</span>
24+
<span :class="{visible: isViewTree}" v-if="isViewTree" {{if not (eq $type "tree")}}v-cloak{{end}}>{{svg "octicon-git-branch"}} {{.root.locale.Tr "repo.tree"}}:</span>
2425
<strong ref="dropdownRefName">{{if and .root.IsViewTag (not .noTag)}}{{.root.TagName}}{{else if .root.IsViewBranch}}{{.root.BranchName}}{{else}}{{ShortSha .root.CommitID}}{{end}}</strong>
2526
{{end}}
2627
</span>

Diff for: templates/repo/clone_buttons.tmpl

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<!-- there is always at least one button (by context/repo.go) -->
22
{{if $.CloneButtonShowHTTPS}}
3-
<button class="ui basic clone button no-transition" id="repo-clone-https" data-link="{{$.CloneButtonOriginLink.HTTPS}}">
3+
<button class="ui basic small compact clone button no-transition" id="repo-clone-https" data-link="{{$.CloneButtonOriginLink.HTTPS}}">
44
{{if UseHTTPS}}HTTPS{{else}}HTTP{{end}}
55
</button>
66
{{end}}
77
{{if $.CloneButtonShowSSH}}
8-
<button class="ui basic clone button no-transition" id="repo-clone-ssh" data-link="{{$.CloneButtonOriginLink.SSH}}">
8+
<button class="ui basic small compact clone button no-transition" id="repo-clone-ssh" data-link="{{$.CloneButtonOriginLink.SSH}}">
99
SSH
1010
</button>
1111
{{end}}
12-
<input id="repo-clone-url" class="js-clone-url" value="{{$.CloneButtonOriginLink.HTTPS}}" size="1" readonly>
13-
<button class="ui basic icon button tooltip" id="clipboard-btn" data-content="{{.locale.Tr "copy_url"}}" data-clipboard-target="#repo-clone-url" aria-label="{{.locale.Tr "copy_url"}}">
14-
{{svg "octicon-paste"}}
12+
<input id="repo-clone-url" size="20" class="js-clone-url br-0" value="{{$.CloneButtonOriginLink.HTTPS}}" readonly>
13+
<button class="ui basic small compact icon button tooltip" id="clipboard-btn" data-content="{{.locale.Tr "copy_url"}}" data-clipboard-target="#repo-clone-url" aria-label="{{.locale.Tr "copy_url"}}">
14+
{{svg "octicon-copy" 14}}
1515
</button>

Diff for: templates/repo/commits.tmpl

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
{{template "repo/header" .}}
44
<div class="ui container">
55
{{template "repo/sub_menu" .}}
6-
<div class="ui secondary stackable menu mobile--margin-between-items">
7-
{{template "repo/branch_dropdown" dict "root" .}}
8-
<div class="fitted item">
6+
<div class="repo-button-row df ac sb fw mb-4 mt-3">
7+
<div class="df ac">
8+
{{template "repo/branch_dropdown" dict "root" .}}
99
<a href="{{.RepoLink}}/graph" class="ui basic small compact button">
1010
<span class="text">
1111
{{svg "octicon-git-branch"}}

Diff for: templates/repo/home.tmpl

+47-52
Original file line numberDiff line numberDiff line change
@@ -60,55 +60,52 @@
6060
</div>
6161
{{end}}
6262
{{template "repo/sub_menu" .}}
63-
<div class="ui stackable secondary menu mobile--margin-between-items mobile--no-negative-margins no-vertical-tabs">
64-
{{template "repo/branch_dropdown" dict "root" .}}
65-
{{ $n := len .TreeNames}}
66-
{{ $l := Subtract $n 1}}
67-
<!-- If home page, show new PR. If not, show breadcrumb -->
68-
{{if eq $n 0}}
69-
{{if and .CanCompareOrPull .IsViewBranch (not .Repository.IsArchived)}}
70-
<div class="fitted item mx-0">
63+
<div class="repo-button-row df ac sb fw">
64+
<div class="df ac">
65+
{{template "repo/branch_dropdown" dict "root" .}}
66+
{{ $n := len .TreeNames}}
67+
{{ $l := Subtract $n 1}}
68+
<!-- If home page, show new PR. If not, show breadcrumb -->
69+
{{if eq $n 0}}
70+
{{if and .CanCompareOrPull .IsViewBranch (not .Repository.IsArchived)}}
7171
<a href="{{.BaseRepo.Link}}/compare/{{PathEscapeSegments .BaseRepo.DefaultBranch}}...{{if ne .Repository.Owner.Name .BaseRepo.Owner.Name}}{{PathEscape .Repository.Owner.Name}}{{if .BaseRepo.IsFork}}/{{PathEscape .Repository.Name}}{{end}}:{{end}}{{PathEscapeSegments .BranchName}}">
72-
<button id="new-pull-request" class="ui compact basic button">{{if .PullRequestCtx.Allowed}}{{.locale.Tr "repo.pulls.compare_changes"}}{{else}}{{.locale.Tr "action.compare_branch"}}{{end}}</button>
73-
</a>
74-
</div>
75-
{{end}}
76-
<div class="fitted item mx-0">
77-
<a href="{{.Repository.Link}}/find/{{.BranchNameSubURL}}" class="ui compact basic button">
78-
{{.locale.Tr "repo.find_file.go_to_file"}}
79-
</a>
80-
</div>
81-
{{else}}
82-
<div class="fitted item"><span class="ui breadcrumb repo-path"><a class="section" href="{{.RepoLink}}/src/{{.BranchNameSubURL}}" title="{{.Repository.Name}}">{{EllipsisString .Repository.Name 30}}</a>{{range $i, $v := .TreeNames}}<span class="divider">/</span>{{if eq $i $l}}<span class="active section" title="{{$v}}">{{EllipsisString $v 30}}</span>{{else}}{{ $p := index $.Paths $i}}<span class="section"><a href="{{$.BranchLink}}/{{PathEscapeSegments $p}}" title="{{$v}}">{{EllipsisString $v 30}}</a></span>{{end}}{{end}}</span></div>
83-
{{end}}
84-
<div class="right fitted item mr-0" id="file-buttons">
85-
<div class="ui tiny primary buttons">
86-
{{if .Repository.CanEnableEditor}}
87-
{{if .CanAddFile}}
88-
<a href="{{.RepoLink}}/_new/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}" class="ui button">
89-
{{.locale.Tr "repo.editor.new_file"}}
90-
</a>
91-
{{end}}
92-
{{if .CanUploadFile}}
93-
<a href="{{.RepoLink}}/_upload/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}" class="ui button">
94-
{{.locale.Tr "repo.editor.upload_file"}}
95-
</a>
96-
{{end}}
97-
{{if .CanAddFile}}
98-
<a href="{{.RepoLink}}/_diffpatch/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}" class="ui button">
99-
{{.locale.Tr "repo.editor.patch"}}
100-
</a>
101-
{{end}}
102-
{{end}}
103-
{{if and (ne $n 0) (not .IsViewFile) (not .IsBlame) }}
104-
<a href="{{.RepoLink}}/commits/{{.BranchNameSubURL}}/{{.TreePath | PathEscapeSegments}}" class="ui button">
105-
{{.locale.Tr "repo.file_history"}}
72+
<button id="new-pull-request" class="ui compact basic button tooltip" data-content="{{if .PullRequestCtx.Allowed}}{{.locale.Tr "repo.pulls.compare_changes"}}{{else}}{{.locale.Tr "action.compare_branch"}}{{end}}"><span class="text">{{svg "octicon-git-pull-request"}}</span></button>
10673
</a>
10774
{{end}}
108-
</div>
109-
75+
<a href="{{.Repository.Link}}/find/{{.BranchNameSubURL}}" class="ui compact basic button tooltip" data-content="{{.locale.Tr "repo.find_file.go_to_file"}}">{{svg "octicon-file-moved" 15}}</a>
76+
<button class="ui basic small compact dropdown jump icon button mr-2">
77+
<span class="text">{{.locale.Tr "repo.editor.add_file"}}</span>
78+
<div class="menu">
79+
{{if .Repository.CanEnableEditor}}
80+
{{if .CanAddFile}}
81+
<a class="item" href="{{.RepoLink}}/_new/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}">
82+
{{.locale.Tr "repo.editor.new_file"}}
83+
</a>
84+
{{end}}
85+
{{if .CanUploadFile}}
86+
<a class="item" href="{{.RepoLink}}/_upload/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}">
87+
{{.locale.Tr "repo.editor.upload_file"}}
88+
</a>
89+
{{end}}
90+
{{if .CanAddFile}}
91+
<a class="item" href="{{.RepoLink}}/_diffpatch/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}">
92+
{{.locale.Tr "repo.editor.patch"}}
93+
</a>
94+
{{end}}
95+
{{end}}
96+
{{if and (ne $n 0) (not .IsViewFile) (not .IsBlame) }}
97+
<a class="item"href="{{.RepoLink}}/commits/{{.BranchNameSubURL}}/{{.TreePath | PathEscapeSegments}}">
98+
{{.locale.Tr "repo.file_history"}}
99+
</a>
100+
{{end}}
101+
</div>
102+
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
103+
</button>
104+
{{else}}
105+
<span class="ui breadcrumb repo-path"><a class="section" href="{{.RepoLink}}/src/{{.BranchNameSubURL}}" title="{{.Repository.Name}}">{{EllipsisString .Repository.Name 30}}</a>{{range $i, $v := .TreeNames}}<span class="divider">/</span>{{if eq $i $l}}<span class="active section" title="{{$v}}">{{EllipsisString $v 30}}</span>{{else}}{{ $p := index $.Paths $i}}<span class="section"><a href="{{$.BranchLink}}/{{PathEscapeSegments $p}}" title="{{$v}}">{{EllipsisString $v 30}}</a></span>{{end}}{{end}}</span>
106+
{{end}}
110107
</div>
111-
<div class="fitted item">
108+
<div class="df ac">
112109
{{if eq $n 0}}
113110
{{if .Repository.IsTemplate}}
114111
<div class="ui tiny primary buttons">
@@ -118,15 +115,13 @@
118115
</div>
119116
{{end}}
120117
{{end}}
121-
</div>
122-
<div class="fitted item">
123118
<!-- Only show clone panel in repository home page -->
124119
{{if eq $n 0}}
125120
<div class="ui action tiny input" id="clone-panel">
126-
{{template "repo/clone_buttons" .}}
127-
{{template "repo/clone_script" .}}
128-
{{if not .DisableDownloadSourceArchives}}
129-
<button id="download-btn" class="ui basic jump dropdown icon button tooltip" data-content="{{.locale.Tr "repo.download_archive"}}" data-position="top right">
121+
{{template "repo/clone_buttons" .}}
122+
{{template "repo/clone_script" .}}
123+
{{if not .DisableDownloadSourceArchives}}
124+
<button id="download-btn" class="ui basic small compact jump dropdown icon button tooltip" data-content="{{.locale.Tr "repo.download_archive"}}" data-position="top right">
130125
{{svg "octicon-download"}}
131126
<div class="menu">
132127
<a class="item archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments $.BranchName}}.zip" rel="nofollow">{{svg "octicon-file-zip" 16 "mr-3"}}{{.locale.Tr "repo.download_zip"}}</a>
@@ -135,7 +130,7 @@
135130
<a class="item" href="vscode://vscode.git/clone?url={{$.RepoCloneLink.HTTPS}}">{{svg "gitea-vscode" 16 "mr-3"}}{{.locale.Tr "repo.clone_in_vsc"}}</a>
136131
</div>
137132
</button>
138-
{{end}}
133+
{{end}}
139134
</div>
140135
{{end}}
141136
</div>

Diff for: templates/repo/sub_menu.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="ui segments repository-summary{{if and (.Permission.CanRead $.UnitTypeCode) (not .IsEmptyRepo) .LanguageStats }} repository-summary-language-stats{{end}} mt-3">
1+
<div class="ui segments repository-summary{{if and (.Permission.CanRead $.UnitTypeCode) (not .IsEmptyRepo) .LanguageStats }} repository-summary-language-stats{{end}} mt-2 mb-0">
22
<div class="ui segment sub-menu repository-menu">
33
<div class="ui two horizontal center link list">
44
{{if and (.Permission.CanRead $.UnitTypeCode) (not .IsEmptyRepo)}}

Diff for: templates/repo/view_list.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<table id="repo-files-table" class="ui single line table" data-last-commit-loader-url="{{.LastCommitLoaderURL}}">
1+
<table id="repo-files-table" class="ui single line table mt-0" data-last-commit-loader-url="{{.LastCommitLoaderURL}}">
22
<thead>
33
<tr class="commit-list">
44
<th colspan="2" {{if not .LatestCommit}}class="notready"{{end}}>

Diff for: templates/repo/wiki/view.tmpl

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
{{template "repo/header" .}}
44
{{ $title := .title}}
55
<div class="ui container">
6-
<div class="ui stackable secondary menu mobile--margin-between-items mobile--no-negative-margins no-vertical-tabs">
7-
<div class="fitted item">
6+
<div class="repo-button-row df ac sb fw">
7+
<div class="df ac">
88
<div class="choose page">
99
<div class="ui floating filter dropdown" data-no-results="{{.locale.Tr "repo.pulls.no_results"}}">
1010
<div class="ui basic small button">
@@ -28,7 +28,7 @@
2828
</div>
2929
</div>
3030
</div>
31-
<div class="right fitted item">
31+
<div class="df ac">
3232
<div class="ui action small input" id="clone-panel">
3333
{{template "repo/clone_buttons" .}}
3434
{{template "repo/clone_script" .}}

Diff for: web_src/js/features/repo-common.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export function initRepoCloneLink() {
6767
window.updateCloneStates();
6868
});
6969

70-
$inputLink.on('click', () => {
70+
$inputLink.on('focus', () => {
7171
$inputLink.select();
7272
});
7373
}

0 commit comments

Comments
 (0)