Skip to content

Commit c61ed6f

Browse files
Rework repo buttons (#20602, #20718) (#20719)
* 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 * Restore history button and hide add button when unable to add (#20718) Fix two regressions from #20602: - Restore the 'History' button that was previously unable to render because it's show condition was never hit - Hide the 'Add File' button when there would be no items in the dropdown. Co-authored-by: wxiaoguang <[email protected]>
1 parent b88a4b4 commit c61ed6f

File tree

11 files changed

+121
-140
lines changed

11 files changed

+121
-140
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,7 @@ normal_view = Normal View
10611061
line = line
10621062
lines = lines
10631063

1064+
editor.add_file = Add File
10641065
editor.new_file = New File
10651066
editor.upload_file = Upload File
10661067
editor.edit_file = Edit File

templates/repo/branch_dropdown.tmpl

Lines changed: 6 additions & 5 deletions
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.i18n.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.i18n.Tr "repo.release.compare"}}
2021
{{else}}
21-
<span :class="{visible: isViewTag}" v-if="isViewTag" v-cloak>{{svg "octicon-tag"}} {{.root.i18n.Tr "repo.tag"}}:</span>
22-
<span :class="{visible: isViewBranch}" v-if="isViewBranch" v-cloak>{{svg "octicon-git-branch"}} {{.root.i18n.Tr "repo.branch"}}:</span>
23-
<span :class="{visible: isViewTree}" v-if="isViewTree" v-cloak>{{svg "octicon-git-branch"}} {{.root.i18n.Tr "repo.tree"}}:</span>
22+
<span :class="{visible: isViewTag}" v-if="isViewTag" {{if not (eq $type "tag")}}v-cloak{{end}}>{{svg "octicon-tag"}} {{.root.i18n.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.i18n.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.i18n.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>

templates/repo/clone_buttons.tmpl

Lines changed: 5 additions & 5 deletions
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="{{.i18n.Tr "copy_url"}}" data-clipboard-target="#repo-clone-url" aria-label="{{.i18n.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="{{.i18n.Tr "copy_url"}}" data-clipboard-target="#repo-clone-url" aria-label="{{.i18n.Tr "copy_url"}}">
14+
{{svg "octicon-copy" 14}}
1515
</button>

templates/repo/commits.tmpl

Lines changed: 3 additions & 3 deletions
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"}}

templates/repo/home.tmpl

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -60,55 +60,49 @@
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}}{{.i18n.Tr "repo.pulls.compare_changes"}}{{else}}{{.i18n.Tr "action.compare_branch"}}{{end}}</button>
72+
<button id="new-pull-request" class="ui compact basic button tooltip" data-content="{{if .PullRequestCtx.Allowed}}{{.i18n.Tr "repo.pulls.compare_changes"}}{{else}}{{.i18n.Tr "action.compare_branch"}}{{end}}"><span class="text">{{svg "octicon-git-pull-request"}}</span></button>
7373
</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-
{{.i18n.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-
{{.i18n.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-
{{.i18n.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-
{{.i18n.Tr "repo.editor.patch"}}
100-
</a>
101-
{{end}}
10274
{{end}}
103-
{{if and (ne $n 0) (not .IsViewFile) (not .IsBlame) }}
104-
<a href="{{.RepoLink}}/commits/{{.BranchNameSubURL}}/{{.TreePath | PathEscapeSegments}}" class="ui button">
105-
{{.i18n.Tr "repo.file_history"}}
106-
</a>
75+
<a href="{{.Repository.Link}}/find/{{.BranchNameSubURL}}" class="ui compact basic button tooltip" data-content="{{.i18n.Tr "repo.find_file.go_to_file"}}">{{svg "octicon-file-moved" 15}}</a>
76+
{{if or .CanAddFile .CanUploadFile}}
77+
<button class="ui basic small compact dropdown jump icon button mr-2">
78+
<span class="text">{{.i18n.Tr "repo.editor.add_file"}}</span>
79+
<div class="menu">
80+
{{if .Repository.CanEnableEditor}}
81+
{{if .CanAddFile}}
82+
<a class="item" href="{{.RepoLink}}/_new/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}">
83+
{{.i18n.Tr "repo.editor.new_file"}}
84+
</a>
85+
{{end}}
86+
{{if .CanUploadFile}}
87+
<a class="item" href="{{.RepoLink}}/_upload/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}">
88+
{{.i18n.Tr "repo.editor.upload_file"}}
89+
</a>
90+
{{end}}
91+
{{if .CanAddFile}}
92+
<a class="item" href="{{.RepoLink}}/_diffpatch/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}">
93+
{{.i18n.Tr "repo.editor.patch"}}
94+
</a>
95+
{{end}}
96+
{{end}}
97+
</div>
98+
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
99+
</button>
107100
{{end}}
108-
</div>
109-
101+
{{else}}
102+
<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>
103+
{{end}}
110104
</div>
111-
<div class="fitted item">
105+
<div class="df ac">
112106
{{if eq $n 0}}
113107
{{if .Repository.IsTemplate}}
114108
<div class="ui tiny primary buttons">
@@ -118,14 +112,13 @@
118112
</div>
119113
{{end}}
120114
{{end}}
121-
</div>
122-
<div class="fitted item">
123115
<!-- Only show clone panel in repository home page -->
124116
{{if eq $n 0}}
125117
<div class="ui action tiny input" id="clone-panel">
126-
{{template "repo/clone_buttons" .}}
127-
{{template "repo/clone_script" .}}
128-
<button id="download-btn" class="ui basic jump dropdown icon button tooltip" data-content="{{.i18n.Tr "repo.download_archive"}}" data-position="top right">
118+
{{template "repo/clone_buttons" .}}
119+
{{template "repo/clone_script" .}}
120+
{{if not .DisableDownloadSourceArchives}}
121+
<button id="download-btn" class="ui basic small compact jump dropdown icon button tooltip" data-content="{{.i18n.Tr "repo.download_archive"}}" data-position="top right">
129122
{{svg "octicon-download"}}
130123
<div class="menu">
131124
{{if not $.DisableDownloadSourceArchives}}
@@ -136,8 +129,14 @@
136129
<a class="item" href="vscode://vscode.git/clone?url={{$.RepoCloneLink.HTTPS}}">{{svg "gitea-vscode" 16 "mr-3"}}{{.i18n.Tr "repo.clone_in_vsc"}}</a>
137130
</div>
138131
</button>
132+
{{end}}
139133
</div>
140134
{{end}}
135+
{{if and (ne $n 0) (not .IsViewFile) (not .IsBlame) }}
136+
<a class="ui button" href="{{.RepoLink}}/commits/{{.BranchNameSubURL}}/{{.TreePath | PathEscapeSegments}}">
137+
{{svg "octicon-history" 16 "mr-3"}}{{.i18n.Tr "repo.file_history"}}
138+
</a>
139+
{{end}}
141140
</div>
142141
</div>
143142
{{if .IsViewFile}}

templates/repo/sub_menu.tmpl

Lines changed: 1 addition & 1 deletion
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)}}

templates/repo/view_list.tmpl

Lines changed: 1 addition & 1 deletion
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}}>

templates/repo/wiki/view.tmpl

Lines changed: 3 additions & 3 deletions
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="{{.i18n.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" .}}

web_src/js/features/repo-common.js

Lines changed: 1 addition & 1 deletion
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)