Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rearrange Clone Panel #31142

Merged
merged 19 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions routers/web/repo/view_home.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ func prepareOpenWithEditorApps(ctx *context.Context) {
schema, _, _ := strings.Cut(app.OpenURL, ":")
var iconHTML template.HTML
if schema == "vscode" || schema == "vscodium" || schema == "jetbrains" {
iconHTML = svg.RenderHTML(fmt.Sprintf("gitea-%s", schema), 16, "tw-mr-2")
iconHTML = svg.RenderHTML(fmt.Sprintf("gitea-%s", schema), 16)
} else {
iconHTML = svg.RenderHTML("gitea-git", 16, "tw-mr-2") // TODO: it could support user's customized icon in the future
iconHTML = svg.RenderHTML("gitea-git", 16) // TODO: it could support user's customized icon in the future
}
tmplApps = append(tmplApps, map[string]any{
"DisplayName": app.DisplayName,
Expand Down
26 changes: 12 additions & 14 deletions templates/repo/clone_buttons.tmpl
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<!-- there is always at least one button (by context/repo.go) -->
{{if $.CloneButtonShowHTTPS}}
<button class="ui small button" id="repo-clone-https" data-link="{{$.CloneButtonOriginLink.HTTPS}}">
HTTPS
<!-- there is always at least one button (guaranteed by context/repo.go) -->
<div class="ui action small input clone-buttons-combo">
{{if $.CloneButtonShowHTTPS}}
<button class="ui small button repo-clone-https" data-link="{{$.CloneButtonOriginLink.HTTPS}}">HTTPS</button>
{{end}}
{{if $.CloneButtonShowSSH}}
<button class="ui small button repo-clone-ssh" data-link="{{$.CloneButtonOriginLink.SSH}}">SSH</button>
{{end}}
<input size="10" class="repo-clone-url js-clone-url" value="{{$.CloneButtonOriginLink.HTTPS}}" readonly>
<button class="ui small icon button" data-clipboard-target=".repo-clone-url" data-tooltip-content="{{ctx.Locale.Tr "copy_url"}}">
{{svg "octicon-copy" 14}}
</button>
{{end}}
{{if $.CloneButtonShowSSH}}
<button class="ui small button" id="repo-clone-ssh" data-link="{{$.CloneButtonOriginLink.SSH}}">
SSH
</button>
{{end}}
<input id="repo-clone-url" size="10" class="js-clone-url" value="{{$.CloneButtonOriginLink.HTTPS}}" readonly>
<button class="ui small icon button" id="clipboard-btn" data-tooltip-content="{{ctx.Locale.Tr "copy_url"}}" data-clipboard-target="#repo-clone-url" aria-label="{{ctx.Locale.Tr "copy_url"}}">
{{svg "octicon-copy" 14}}
</button>
</div>
44 changes: 44 additions & 0 deletions templates/repo/clone_panel.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<button class="ui green button js-btn-clone-panel">
<span>{{svg "octicon-code" 16}} Code</span>
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
</button>
<div class="clone-panel-popup tippy-target">
<div class="flex-text-block clone-panel-field">{{svg "octicon-terminal"}} Clone</div>

<div class="clone-panel-tab">
<!-- there is always at least one button (guaranteed by context/repo.go) -->
{{if $.CloneButtonShowHTTPS}}
<button class="item repo-clone-https" data-link="{{$.CloneButtonOriginLink.HTTPS}}">HTTPS</button>
{{end}}
{{if $.CloneButtonShowSSH}}
<button class="item repo-clone-ssh" data-link="{{$.CloneButtonOriginLink.SSH}}">SSH</button>
{{end}}
</div>
<div class="divider"></div>

<div class="clone-panel-field">
<div class="ui input tiny action">
<input size="30" class="repo-clone-url js-clone-url" value="{{$.CloneButtonOriginLink.HTTPS}}" readonly>
<div class="ui small compact icon button" data-clipboard-target=".js-clone-url" data-tooltip-content="{{ctx.Locale.Tr "copy_url"}}">
{{svg "octicon-copy" 14}}
</div>
</div>
</div>

{{if not .PageIsWiki}}
<div class="flex-items-block clone-panel-list">
{{range .OpenWithEditorApps}}
<a class="item muted js-clone-url-editor" data-href-template="{{.OpenURL}}">{{.IconHTML}}{{ctx.Locale.Tr "repo.open_with_editor" .DisplayName}}</a>
{{end}}
</div>

{{if and (not $.DisableDownloadSourceArchives) $.RefName}}
<div class="divider"></div>
<div class="flex-items-block clone-panel-list">
<a class="item muted archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments $.RefName}}.zip" rel="nofollow">{{svg "octicon-file-zip"}} {{ctx.Locale.Tr "repo.download_zip"}}</a>
<a class="item muted archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments $.RefName}}.tar.gz" rel="nofollow">{{svg "octicon-file-zip"}} {{ctx.Locale.Tr "repo.download_tar"}}</a>
<a class="item muted archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments $.RefName}}.bundle" rel="nofollow">{{svg "octicon-package"}} {{ctx.Locale.Tr "repo.download_bundle"}}</a>
</div>
{{end}}
{{end}}
</div>
50 changes: 0 additions & 50 deletions templates/repo/clone_script.tmpl

This file was deleted.

5 changes: 1 addition & 4 deletions templates/repo/empty.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@
</a>
{{end}}
{{end}}
<div class="clone-panel ui action small input tw-flex-1">
{{template "repo/clone_buttons" .}}
</div>
{{template "repo/clone_buttons" .}}
</div>
</div>

Expand Down Expand Up @@ -73,7 +71,6 @@ git push -u origin {{.Repository.DefaultBranch}}</code></pre>
{{ctx.Locale.Tr "repo.empty_message"}}
</div>
{{end}}
{{template "repo/clone_script" .}}
</div>
</div>
</div>
Expand Down
18 changes: 1 addition & 17 deletions templates/repo/home.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,7 @@
<div class="repo-button-row-right {{if not $isTreePathRoot}}tw-flex-grow-0{{end}}">
<!-- Only show clone panel in repository home page -->
{{if $isTreePathRoot}}
<div class="clone-panel ui action tiny input">
{{template "repo/clone_buttons" .}}
<button class="ui small jump dropdown icon button" data-tooltip-content="{{ctx.Locale.Tr "repo.more_operations"}}">
{{svg "octicon-kebab-horizontal"}}
<div class="menu">
{{if not $.DisableDownloadSourceArchives}}
<a class="item archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments $.RefName}}.zip" rel="nofollow">{{svg "octicon-file-zip" 16 "tw-mr-2"}}{{ctx.Locale.Tr "repo.download_zip"}}</a>
<a class="item archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments $.RefName}}.tar.gz" rel="nofollow">{{svg "octicon-file-zip" 16 "tw-mr-2"}}{{ctx.Locale.Tr "repo.download_tar"}}</a>
<a class="item archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments $.RefName}}.bundle" rel="nofollow">{{svg "octicon-package" 16 "tw-mr-2"}}{{ctx.Locale.Tr "repo.download_bundle"}}</a>
{{end}}
{{range .OpenWithEditorApps}}
<a class="item js-clone-url-editor" data-href-template="{{.OpenURL}}">{{.IconHTML}}{{ctx.Locale.Tr "repo.open_with_editor" .DisplayName}}</a>
{{end}}
</div>
</button>
{{template "repo/clone_script" .}}{{/* the script will update `.js-clone-url` and related elements */}}
</div>
{{template "repo/clone_panel" .}}
{{end}}
{{if and (not $isTreePathRoot) (not .IsViewFile) (not .IsBlame)}}{{/* IsViewDirectory (not home), TODO: split the templates, avoid using "if" tricks */}}
<a class="ui button" href="{{.RepoLink}}/commits/{{.BranchNameSubURL}}/{{.TreePath | PathEscapeSegments}}">
Expand Down
5 changes: 1 addition & 4 deletions templates/repo/wiki/revision.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
</div>
</div>
<div class="ui eight wide column text right">
<div class="clone-panel ui action small input">
{{template "repo/clone_buttons" .}}
{{template "repo/clone_script" .}}
</div>
{{template "repo/clone_panel" .}}
</div>
</div>
<h2 class="ui top header">{{ctx.Locale.Tr "repo.wiki.wiki_page_revisions"}}</h2>
Expand Down
5 changes: 1 addition & 4 deletions templates/repo/wiki/view.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@
</div>
</div>
</div>
<div class="clone-panel ui action small input">
{{template "repo/clone_buttons" .}}
{{template "repo/clone_script" .}}
</div>
{{template "repo/clone_panel" .}}
</div>
<div class="ui dividing header">
<div class="flex-text-block tw-flex-wrap tw-justify-end">
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ func TestViewRepo1CloneLinkAnonymous(t *testing.T) {
resp := MakeRequest(t, req, http.StatusOK)

htmlDoc := NewHTMLParser(t, resp.Body)
link, exists := htmlDoc.doc.Find("#repo-clone-https").Attr("data-link")
link, exists := htmlDoc.doc.Find(".repo-clone-https").Attr("data-link")
assert.True(t, exists, "The template has changed")
assert.Equal(t, setting.AppURL+"user2/repo1.git", link)
_, exists = htmlDoc.doc.Find("#repo-clone-ssh").Attr("data-link")
_, exists = htmlDoc.doc.Find(".repo-clone-ssh").Attr("data-link")
assert.False(t, exists)
}

Expand All @@ -143,10 +143,10 @@ func TestViewRepo1CloneLinkAuthorized(t *testing.T) {
resp := session.MakeRequest(t, req, http.StatusOK)

htmlDoc := NewHTMLParser(t, resp.Body)
link, exists := htmlDoc.doc.Find("#repo-clone-https").Attr("data-link")
link, exists := htmlDoc.doc.Find(".repo-clone-https").Attr("data-link")
assert.True(t, exists, "The template has changed")
assert.Equal(t, setting.AppURL+"user2/repo1.git", link)
link, exists = htmlDoc.doc.Find("#repo-clone-ssh").Attr("data-link")
link, exists = htmlDoc.doc.Find(".repo-clone-ssh").Attr("data-link")
assert.True(t, exists, "The template has changed")
sshURL := fmt.Sprintf("ssh://%s@%s:%d/user2/repo1.git", setting.SSH.User, setting.SSH.Domain, setting.SSH.Port)
assert.Equal(t, sshURL, link)
Expand Down
1 change: 1 addition & 0 deletions web_src/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
@import "./repo/header.css";
@import "./repo/home.css";
@import "./repo/reactions.css";
@import "./repo/clone.css";

@import "./editor/fileeditor.css";
@import "./editor/combomarkdowneditor.css";
Expand Down
44 changes: 0 additions & 44 deletions web_src/css/repo.css
Original file line number Diff line number Diff line change
Expand Up @@ -101,42 +101,6 @@
margin-bottom: 12px;
}

.repository .clone-panel {
display: flex;
flex: 1;
}

.repository.wiki .clone-panel {
flex: 0;
}

.repository.wiki .clone-panel input {
width: 20ch;
}

.repository .clone-panel #repo-clone-url {
border-radius: 0;
flex: 1;
}

.repository .ui.action.input.clone-panel > button + button,
.repository .ui.action.input.clone-panel > button + input {
margin-left: -1px; /* make the borders overlap to avoid double borders */
}

.repository .clone-panel > button:first-of-type {
border-radius: var(--border-radius) 0 0 var(--border-radius) !important;
}

.repository .clone-panel > button:last-of-type {
border-radius: 0 var(--border-radius) var(--border-radius) 0 !important;
}

.repository .clone-panel .dropdown .menu {
right: 0 !important;
left: auto !important;
}

.repository .repo-description {
font-size: 16px;
margin-bottom: 5px;
Expand Down Expand Up @@ -1615,14 +1579,6 @@ td .commit-summary {
font-weight: var(--font-weight-normal);
}

.repository.quickstart .guide #repo-clone-url {
border-radius: 0;
padding: 5px 10px;
font-size: 1.2em;
line-height: 1.4;
flex: 1
}

.empty-placeholder {
display: flex;
flex-direction: column;
Expand Down
32 changes: 32 additions & 0 deletions web_src/css/repo/clone.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* only used by "repo/empty.tmpl" */
.clone-buttons-combo {
flex: 1;
}

.clone-buttons-combo input {
border-left: none !important;
border-radius: 0 !important;
}

/* used by the clone-panel popup */
.clone-panel-field,
.clone-panel-list {
margin: 10px;
}

.clone-panel-tab .item {
padding: 5px 10px;
background: none;
}

.clone-panel-tab .item.active {
border-bottom: 3px solid var(--color-secondary);
}

.clone-panel-tab + .divider {
margin: -1px 0 0;
}

.clone-panel-list .item {
margin: 5px 0;
}
3 changes: 0 additions & 3 deletions web_src/css/repo/wiki.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@
}

@media (max-width: 767.98px) {
.repository.wiki .clone-panel #repo-clone-url {
width: 160px;
}
.repository.wiki .wiki-content-main.with-sidebar,
.repository.wiki .wiki-content-sidebar {
float: none;
Expand Down
Loading
Loading