Fix branch selector UI (#30803)

Fix  #30802
This commit is contained in:
wxiaoguang 2024-05-02 18:45:23 +08:00 committed by GitHub
parent 82eca44581
commit ebe6f4cad7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 96 additions and 117 deletions

View File

@ -69,9 +69,9 @@
<div class="js-branch-tag-selector {{if .ContainerClasses}}{{.ContainerClasses}}{{end}}"> <div class="js-branch-tag-selector {{if .ContainerClasses}}{{.ContainerClasses}}{{end}}">
{{/* show dummy elements before Vue componment is mounted, this code must match the code in BranchTagSelector.vue */}} {{/* show dummy elements before Vue componment is mounted, this code must match the code in BranchTagSelector.vue */}}
<div class="ui dropdown custom"> <div class="ui dropdown custom branch-selector-dropdown">
<button class="branch-dropdown-button gt-ellipsis ui basic small compact button tw-flex tw-m-0"> <div class="ui button branch-dropdown-button">
<span class="text tw-flex tw-items-center tw-mr-1 gt-ellipsis"> <span class="flex-text-block gt-ellipsis">
{{if .release}} {{if .release}}
{{ctx.Locale.Tr "repo.release.compare"}} {{ctx.Locale.Tr "repo.release.compare"}}
{{else}} {{else}}
@ -84,6 +84,6 @@
{{end}} {{end}}
</span> </span>
{{svg "octicon-triangle-down" 14 "dropdown icon"}} {{svg "octicon-triangle-down" 14 "dropdown icon"}}
</button> </div>
</div> </div>
</div> </div>

View File

@ -4,10 +4,12 @@
<form method="post" action="{{$.RepoLink}}/issues/{{.Issue.Index}}/ref" id="update_issueref_form"> <form method="post" action="{{$.RepoLink}}/issues/{{.Issue.Index}}/ref" id="update_issueref_form">
{{$.CsrfTokenHtml}} {{$.CsrfTokenHtml}}
</form> </form>
{{/* TODO: share this branch selector dropdown with the same in repo page */}} <div class="ui dropdown select-branch branch-selector-dropdown {{if not .HasIssuesOrPullsWritePermission}}disabled{{end}}"
<div class="ui {{if not .HasIssuesOrPullsWritePermission}}disabled{{end}} floating filter select-branch dropdown tw-max-w-full" data-no-results="{{ctx.Locale.Tr "no_results_found"}}"> data-no-results="{{ctx.Locale.Tr "no_results_found"}}"
<div class="ui basic small button"> {{if not .Issue}}data-for-new-issue="true"{{end}}
<span class="text branch-name gt-ellipsis">{{if .Reference}}{{$.RefEndName}}{{else}}{{ctx.Locale.Tr "repo.issues.no_ref"}}{{end}}</span> >
<div class="ui button branch-dropdown-button">
<span class="text-branch-name gt-ellipsis">{{if .Reference}}{{$.RefEndName}}{{else}}{{ctx.Locale.Tr "repo.issues.no_ref"}}{{end}}</span>
{{if .HasIssuesOrPullsWritePermission}}{{svg "octicon-triangle-down" 14 "dropdown icon"}}{{end}} {{if .HasIssuesOrPullsWritePermission}}{{svg "octicon-triangle-down" 14 "dropdown icon"}}{{end}}
</div> </div>
<div class="menu"> <div class="menu">
@ -15,26 +17,18 @@
<i class="icon">{{svg "octicon-filter" 16}}</i> <i class="icon">{{svg "octicon-filter" 16}}</i>
<input name="search" placeholder="{{ctx.Locale.Tr "repo.filter_branch_and_tag"}}..."> <input name="search" placeholder="{{ctx.Locale.Tr "repo.filter_branch_and_tag"}}...">
</div> </div>
<div class="header"> <div class="branch-tag-tab">
<div class="ui grid"> <a class="branch-tag-item reference column muted active" href="#" data-target="#branch-list">
<div class="two column row"> {{svg "octicon-git-branch" 16 "tw-mr-1"}} {{ctx.Locale.Tr "repo.branches"}}
<a class="reference column muted" href="#" data-target="#branch-list"> </a>
<span class="text black"> <a class="branch-tag-item reference column muted" href="#" data-target="#tag-list">
{{svg "octicon-git-branch" 16 "tw-mr-1"}}{{ctx.Locale.Tr "repo.branches"}} {{svg "octicon-tag" 16 "tw-mr-1"}} {{ctx.Locale.Tr "repo.tags"}}
</span> </a>
</a>
<a class="reference column muted" href="#" data-target="#tag-list">
<span class="text">
{{svg "octicon-tag" 16 "tw-mr-1"}}{{ctx.Locale.Tr "repo.tags"}}
</span>
</a>
</div>
</div>
</div> </div>
<div class="branch-tag-divider"></div> <div class="branch-tag-divider"></div>
<div id="branch-list" class="scrolling menu reference-list-menu {{if not .Issue}}new-issue{{end}}"> <div id="branch-list" class="scrolling menu reference-list-menu">
{{if .Reference}} {{if or .Reference (not .Issue)}}
<div class="item text small" data-id="" data-id-selector="#ref_selector"><strong><a href="#">{{ctx.Locale.Tr "repo.clear_ref"}}</a></strong></div> <div class="item text small" data-id="" data-name="{{ctx.Locale.Tr "repo.issues.no_ref"}}" data-id-selector="#ref_selector"><strong><a href="#">{{ctx.Locale.Tr "repo.clear_ref"}}</a></strong></div>
{{end}} {{end}}
{{range .Branches}} {{range .Branches}}
<div class="item" data-id="refs/heads/{{.}}" data-name="{{.}}" data-id-selector="#ref_selector" title="{{.}}">{{.}}</div> <div class="item" data-id="refs/heads/{{.}}" data-name="{{.}}" data-id-selector="#ref_selector" title="{{.}}">{{.}}</div>
@ -42,9 +36,9 @@
<div class="item">{{ctx.Locale.Tr "no_results_found"}}</div> <div class="item">{{ctx.Locale.Tr "no_results_found"}}</div>
{{end}} {{end}}
</div> </div>
<div id="tag-list" class="scrolling menu reference-list-menu {{if not .Issue}}new-issue{{end}} tw-hidden"> <div id="tag-list" class="scrolling menu reference-list-menu tw-hidden">
{{if .Reference}} {{if or .Reference (not .Issue)}}
<div class="item text small" data-id="" data-id-selector="#ref_selector"><strong><a href="#">{{ctx.Locale.Tr "repo.clear_ref"}}</a></strong></div> <div class="item text small" data-id="" data-name="{{ctx.Locale.Tr "repo.issues.no_ref"}}" data-id-selector="#ref_selector"><strong><a href="#">{{ctx.Locale.Tr "repo.clear_ref"}}</a></strong></div>
{{end}} {{end}}
{{range .Tags}} {{range .Tags}}
<div class="item" data-id="refs/tags/{{.}}" data-name="tags/{{.}}" data-id-selector="#ref_selector">{{.}}</div> <div class="item" data-id="refs/tags/{{.}}" data-name="tags/{{.}}" data-id-selector="#ref_selector">{{.}}</div>

View File

@ -1,6 +1,6 @@
<div class="ui labels list"> <div class="ui labels list">
<span class="no-select item {{if .root.HasSelectedLabel}}tw-hidden{{end}}">{{ctx.Locale.Tr "repo.issues.new.no_label"}}</span>
<span class="labels-list"> <span class="labels-list">
<span class="no-select {{if .root.HasSelectedLabel}}tw-hidden{{end}}">{{ctx.Locale.Tr "repo.issues.new.no_label"}}</span>
{{range .root.Labels}} {{range .root.Labels}}
{{template "repo/issue/labels/label" dict "root" $.root "label" .}} {{template "repo/issue/labels/label" dict "root" $.root "label" .}}
{{end}} {{end}}

View File

@ -871,6 +871,7 @@ input:-webkit-autofill:active,
.ui.dropdown .scrolling.menu { .ui.dropdown .scrolling.menu {
border-color: var(--color-secondary); border-color: var(--color-secondary);
border-radius: 0 0 var(--border-radius) var(--border-radius) !important;
} }
.color-preview { .color-preview {

View File

@ -2748,23 +2748,6 @@ tbody.commit-list {
} }
} }
.branch-dropdown-button {
max-width: 340px;
vertical-align: bottom !important;
}
@media (min-width: 768px) and (max-width: 991.98px) {
.branch-dropdown-button {
max-width: 185px;
}
}
@media (max-width: 767.98px) {
.branch-dropdown-button {
max-width: 165px;
}
}
.commit-status-header { .commit-status-header {
/* reset the default ".ui.attached.header" styles, to use the outer border */ /* reset the default ".ui.attached.header" styles, to use the outer border */
border: none !important; border: none !important;
@ -2841,32 +2824,70 @@ tbody.commit-list {
max-height: 200px; max-height: 200px;
} }
/* Branch tag selector - TODO: Merge this into the same selector on repo page */ .branch-selector-dropdown {
.repository .issue-content .issue-content-right .ui.grid .column.row { max-width: 100%;
padding: 10px;
padding-bottom: 0;
} }
.repository .issue-content .issue-content-right .ui.grid .column.muted {
padding: 0; .ui.dropdown.branch-selector-dropdown > .menu {
margin-top: 4px;
} }
.repository .issue-content .issue-content-right .ui.grid .column.muted .text {
.branch-selector-dropdown .branch-dropdown-button {
margin: 0;
max-width: 340px;
line-height: var(--line-height-default);
}
/* FIXME: These media selectors are not ideal (just keep them from old code).
There are many different pages, some need the max-width while some others don't,
they should be tested and improved in the future. */
@media (min-width: 768px) and (max-width: 991.98px) {
.branch-selector-dropdown .branch-dropdown-button {
max-width: 185px;
}
}
@media (max-width: 767.98px) {
.branch-selector-dropdown .branch-dropdown-button {
max-width: 165px;
}
}
.branch-selector-dropdown .branch-tag-tab {
padding: 0 10px;
}
.branch-selector-dropdown .branch-tag-item {
display: inline-block; display: inline-block;
padding: 10px; padding: 10px;
width: 100%;
text-align: center;
border: 1px solid transparent; border: 1px solid transparent;
border-bottom: none; border-bottom: none;
} }
.repository .issue-content .issue-content-right .ui.grid .column.muted .text.black {
.branch-selector-dropdown .branch-tag-item.active {
border-color: var(--color-secondary); border-color: var(--color-secondary);
background: var(--color-menu); background: var(--color-menu);
border-top-left-radius: var(--border-radius); border-top-left-radius: var(--border-radius);
border-top-right-radius: var(--border-radius); border-top-right-radius: var(--border-radius);
} }
.repository .issue-content .issue-content-right .ui.dropdown .scrolling.menu {
border-top: none; .branch-selector-dropdown .branch-tag-divider {
} margin-top: -1px !important;
.repository .issue-content .issue-content-right .branch-tag-divider {
margin-top: -1px;
border-top: 1px solid var(--color-secondary); border-top: 1px solid var(--color-secondary);
} }
.branch-selector-dropdown .scrolling.menu {
border-top: none !important;
}
.branch-selector-dropdown .menu .item .rss-icon {
visibility: hidden; /* only show RSS icon on hover */
}
.branch-selector-dropdown .menu .item:hover .rss-icon {
visibility: visible;
}
.branch-selector-dropdown .scrolling.menu .loading-indicator {
height: 4em;
}

View File

@ -246,9 +246,9 @@ export function initRepoBranchTagSelector(selector) {
export default sfc; // activate IDE's Vue plugin export default sfc; // activate IDE's Vue plugin
</script> </script>
<template> <template>
<div class="ui dropdown custom"> <div class="ui dropdown custom branch-selector-dropdown">
<button class="branch-dropdown-button gt-ellipsis ui basic small compact button tw-flex tw-m-0" @click="menuVisible = !menuVisible" @keyup.enter="menuVisible = !menuVisible"> <div class="ui button branch-dropdown-button" @click="menuVisible = !menuVisible" @keyup.enter="menuVisible = !menuVisible">
<span class="text tw-flex tw-items-center tw-mr-1 gt-ellipsis"> <span class="flex-text-block gt-ellipsis">
<template v-if="release">{{ textReleaseCompare }}</template> <template v-if="release">{{ textReleaseCompare }}</template>
<template v-else> <template v-else>
<svg-icon v-if="isViewTag" name="octicon-tag"/> <svg-icon v-if="isViewTag" name="octicon-tag"/>
@ -257,7 +257,7 @@ export default sfc; // activate IDE's Vue plugin
</template> </template>
</span> </span>
<svg-icon name="octicon-triangle-down" :size="14" class-name="dropdown icon"/> <svg-icon name="octicon-triangle-down" :size="14" class-name="dropdown icon"/>
</button> </div>
<div class="menu transition" :class="{visible: menuVisible}" v-show="menuVisible" v-cloak> <div class="menu transition" :class="{visible: menuVisible}" v-show="menuVisible" v-cloak>
<div class="ui icon search input"> <div class="ui icon search input">
<i class="icon"><svg-icon name="octicon-filter" :size="16"/></i> <i class="icon"><svg-icon name="octicon-filter" :size="16"/></i>
@ -317,43 +317,3 @@ export default sfc; // activate IDE's Vue plugin
</div> </div>
</div> </div>
</template> </template>
<style scoped>
.branch-tag-tab {
padding: 0 10px;
}
.branch-tag-item {
display: inline-block;
padding: 10px;
border: 1px solid transparent;
border-bottom: none;
}
.branch-tag-item.active {
border-color: var(--color-secondary);
background: var(--color-menu);
border-top-left-radius: var(--border-radius);
border-top-right-radius: var(--border-radius);
}
.branch-tag-divider {
margin-top: -1px !important;
border-top: 1px solid var(--color-secondary);
}
.scrolling.menu {
border-top: none !important;
}
.menu .item .rss-icon {
display: none; /* only show RSS icon on hover */
}
.menu .item:hover .rss-icon {
display: inline-block;
}
.scrolling.menu .loading-indicator {
height: 4em;
}
</style>

View File

@ -19,7 +19,7 @@ import {initCompReactionSelector} from './comp/ReactionSelector.js';
import {initRepoSettingBranches} from './repo-settings.js'; import {initRepoSettingBranches} from './repo-settings.js';
import {initRepoPullRequestMergeForm} from './repo-issue-pr-form.js'; import {initRepoPullRequestMergeForm} from './repo-issue-pr-form.js';
import {initRepoPullRequestCommitStatus} from './repo-issue-pr-status.js'; import {initRepoPullRequestCommitStatus} from './repo-issue-pr-status.js';
import {hideElem, showElem} from '../utils/dom.js'; import {hideElem, queryElemChildren, showElem} from '../utils/dom.js';
import {POST} from '../modules/fetch.js'; import {POST} from '../modules/fetch.js';
import {initRepoIssueCommentEdit} from './repo-issue-edit.js'; import {initRepoIssueCommentEdit} from './repo-issue-edit.js';
@ -56,16 +56,19 @@ export function initRepoCommentForm() {
} }
function initBranchSelector() { function initBranchSelector() {
const $selectBranch = $('.ui.select-branch'); const elSelectBranch = document.querySelector('.ui.dropdown.select-branch');
const isForNewIssue = elSelectBranch.getAttribute('data-for-new-issue') === 'true';
const $selectBranch = $(elSelectBranch);
const $branchMenu = $selectBranch.find('.reference-list-menu'); const $branchMenu = $selectBranch.find('.reference-list-menu');
const $isNewIssue = $branchMenu.hasClass('new-issue'); $branchMenu.find('.item:not(.no-select)').on('click', async function (e) {
$branchMenu.find('.item:not(.no-select)').on('click', async function () { e.preventDefault();
const selectedValue = $(this).data('id'); const selectedValue = $(this).data('id'); // eg: "refs/heads/my-branch"
const editMode = $('#editing_mode').val(); const editMode = $('#editing_mode').val();
$($(this).data('id-selector')).val(selectedValue); $($(this).data('id-selector')).val(selectedValue);
if ($isNewIssue) { if (isForNewIssue) {
$selectBranch.find('.ui .branch-name').text($(this).data('name')); elSelectBranch.querySelector('.text-branch-name').textContent = this.getAttribute('data-name');
return; return; // only update UI&form, do not send request/reload
} }
if (editMode === 'true') { if (editMode === 'true') {
@ -84,9 +87,9 @@ export function initRepoCommentForm() {
}); });
$selectBranch.find('.reference.column').on('click', function () { $selectBranch.find('.reference.column').on('click', function () {
hideElem($selectBranch.find('.scrolling.reference-list-menu')); hideElem($selectBranch.find('.scrolling.reference-list-menu'));
$selectBranch.find('.reference .text').removeClass('black'); showElem(this.getAttribute('data-target'));
showElem($($(this).data('target'))); queryElemChildren(this.parentNode, '.branch-tag-item', (el) => el.classList.remove('active'));
$(this).find('.text').addClass('black'); this.classList.add('active');
return false; return false;
}); });
} }