Refactor pull-request compare&create page (#33071)
The old code is unnecessarily complex.
This commit is contained in:
parent
d030cace1a
commit
85c756e279
5 changed files with 217 additions and 275 deletions
|
@ -825,10 +825,6 @@ td .commit-summary {
|
|||
height: 10px;
|
||||
}
|
||||
|
||||
.repository.compare.pull .show-form-container {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.repository .choose.branch {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
@ -866,11 +862,6 @@ td .commit-summary {
|
|||
margin-top: -8px;
|
||||
}
|
||||
|
||||
.repository.compare.pull .pullrequest-form {
|
||||
margin-top: 16px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.repository.compare.pull .markup {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import {initIssueSidebarComboList} from './repo-issue-sidebar-combolist.ts';
|
|||
|
||||
function initBranchSelector() {
|
||||
// TODO: RemoveIssueRef: see "repo/issue/branch_selector_field.tmpl"
|
||||
const elSelectBranch = document.querySelector('.ui.dropdown.select-branch');
|
||||
const elSelectBranch = document.querySelector('.ui.dropdown.select-branch.branch-selector-dropdown');
|
||||
if (!elSelectBranch) return;
|
||||
|
||||
const urlUpdateIssueRef = elSelectBranch.getAttribute('data-url-update-issueref');
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import $ from 'jquery';
|
||||
import {
|
||||
initRepoCommentFormAndSidebar,
|
||||
initRepoIssueBranchSelect, initRepoIssueCodeCommentCancel, initRepoIssueCommentDelete,
|
||||
|
@ -15,7 +14,7 @@ import {initCompReactionSelector} from './comp/ReactionSelector.ts';
|
|||
import {initRepoSettings} from './repo-settings.ts';
|
||||
import {initRepoPullRequestMergeForm} from './repo-issue-pr-form.ts';
|
||||
import {initRepoPullRequestCommitStatus} from './repo-issue-pr-status.ts';
|
||||
import {hideElem, queryElemChildren, showElem} from '../utils/dom.ts';
|
||||
import {hideElem, queryElemChildren, queryElems, showElem} from '../utils/dom.ts';
|
||||
import {initRepoIssueCommentEdit} from './repo-issue-edit.ts';
|
||||
import {initRepoMilestone} from './repo-milestone.ts';
|
||||
import {initRepoNew} from './repo-new.ts';
|
||||
|
@ -29,47 +28,20 @@ function initRepoBranchTagSelector(selector: string) {
|
|||
}
|
||||
|
||||
export function initBranchSelectorTabs() {
|
||||
const elSelectBranch = document.querySelector('.ui.dropdown.select-branch');
|
||||
if (!elSelectBranch) return;
|
||||
|
||||
$(elSelectBranch).find('.reference.column').on('click', function () {
|
||||
hideElem($(elSelectBranch).find('.scrolling.reference-list-menu'));
|
||||
showElem(this.getAttribute('data-target'));
|
||||
queryElemChildren(this.parentNode, '.branch-tag-item', (el) => el.classList.remove('active'));
|
||||
this.classList.add('active');
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
function initRepoCommonBranchOrTagDropdown(selector: string) {
|
||||
$(selector).each(function () {
|
||||
const $dropdown = $(this);
|
||||
$dropdown.find('.reference.column').on('click', function () {
|
||||
hideElem($dropdown.find('.scrolling.reference-list-menu'));
|
||||
showElem($($(this).data('target')));
|
||||
return false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function initRepoCommonFilterSearchDropdown(selector: string) {
|
||||
const $dropdown = $(selector);
|
||||
if (!$dropdown.length) return;
|
||||
|
||||
$dropdown.dropdown({
|
||||
fullTextSearch: 'exact',
|
||||
selectOnKeydown: false,
|
||||
onChange(_text, _value, $choice) {
|
||||
if ($choice[0].getAttribute('data-url')) {
|
||||
window.location.href = $choice[0].getAttribute('data-url');
|
||||
}
|
||||
},
|
||||
message: {noResults: $dropdown[0].getAttribute('data-no-results')},
|
||||
});
|
||||
const elSelectBranches = document.querySelectorAll('.ui.dropdown.select-branch');
|
||||
for (const elSelectBranch of elSelectBranches) {
|
||||
queryElems(elSelectBranch, '.reference.column', (el) => el.addEventListener('click', () => {
|
||||
hideElem(elSelectBranch.querySelectorAll('.scrolling.reference-list-menu'));
|
||||
showElem(el.getAttribute('data-target'));
|
||||
queryElemChildren(el.parentNode, '.branch-tag-item', (el) => el.classList.remove('active'));
|
||||
el.classList.add('active');
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
export function initRepository() {
|
||||
if (!$('.page-content.repository').length) return;
|
||||
const pageContent = document.querySelector('.page-content.repository');
|
||||
if (!pageContent) return;
|
||||
|
||||
initRepoBranchTagSelector('.js-branch-tag-selector');
|
||||
initRepoCommentFormAndSidebar();
|
||||
|
@ -79,19 +51,12 @@ export function initRepository() {
|
|||
initRepoMilestone();
|
||||
initRepoNew();
|
||||
|
||||
// Compare or pull request
|
||||
const $repoDiff = $('.repository.diff');
|
||||
if ($repoDiff.length) {
|
||||
initRepoCommonBranchOrTagDropdown('.choose.branch .dropdown');
|
||||
initRepoCommonFilterSearchDropdown('.choose.branch .dropdown');
|
||||
}
|
||||
|
||||
initRepoCloneButtons();
|
||||
initCitationFileCopyContent();
|
||||
initRepoSettings();
|
||||
|
||||
// Issues
|
||||
if ($('.repository.view.issue').length > 0) {
|
||||
if (pageContent.matches('.page-content.repository.view.issue')) {
|
||||
initRepoIssueCommentEdit();
|
||||
|
||||
initRepoIssueBranchSelect();
|
||||
|
@ -112,18 +77,5 @@ export function initRepository() {
|
|||
initRepoPullRequestCommitStatus();
|
||||
}
|
||||
|
||||
// Pull request
|
||||
const $repoComparePull = $('.repository.compare.pull');
|
||||
if ($repoComparePull.length > 0) {
|
||||
// show pull request form
|
||||
$repoComparePull.find('button.show-form').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
hideElem($(this).parent());
|
||||
|
||||
const $form = $repoComparePull.find('.pullrequest-form');
|
||||
showElem($form);
|
||||
});
|
||||
}
|
||||
|
||||
initUnicodeEscapeButton();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue