Skip to content

Commit 3fdb2d4

Browse files
authored
Fix incorrect issue form (#30881)
Fix #30864
1 parent f09e68e commit 3fdb2d4

File tree

2 files changed

+12
-21
lines changed

2 files changed

+12
-21
lines changed

templates/repo/issue/branch_selector_field.tmpl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
{{if and (not .Issue.IsPull) (not .PageIsComparePull)}}
22
<input id="ref_selector" name="ref" type="hidden" value="{{.Reference}}">
3-
<input id="editing_mode" name="edit_mode" type="hidden" value="{{(or .IsIssueWriter .HasIssuesOrPullsWritePermission)}}">
4-
<form method="post" action="{{$.RepoLink}}/issues/{{.Issue.Index}}/ref" id="update_issueref_form">
5-
{{$.CsrfTokenHtml}}
6-
</form>
73
<div class="ui dropdown select-branch branch-selector-dropdown ellipsis-items-nowrap {{if not .HasIssuesOrPullsWritePermission}}disabled{{end}}"
84
data-no-results="{{ctx.Locale.Tr "no_results_found"}}"
9-
{{if not .Issue}}data-for-new-issue="true"{{end}}
5+
{{if and .Issue (or .IsIssueWriter .HasIssuesOrPullsWritePermission)}}data-url-update-issueref="{{$.RepoLink}}/issues/{{.Issue.Index}}/ref"{{end}}
106
>
117
<div class="ui button branch-dropdown-button">
128
<span class="text-branch-name gt-ellipsis">{{if .Reference}}{{$.RefEndName}}{{else}}{{ctx.Locale.Tr "repo.issues.no_ref"}}{{end}}</span>

web_src/js/features/repo-legacy.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,32 +58,27 @@ export function initRepoCommentForm() {
5858
function initBranchSelector() {
5959
const elSelectBranch = document.querySelector('.ui.dropdown.select-branch');
6060
if (!elSelectBranch) return;
61-
const isForNewIssue = elSelectBranch.getAttribute('data-for-new-issue') === 'true';
6261

62+
const urlUpdateIssueRef = elSelectBranch.getAttribute('data-url-update-issueref');
6363
const $selectBranch = $(elSelectBranch);
6464
const $branchMenu = $selectBranch.find('.reference-list-menu');
6565
$branchMenu.find('.item:not(.no-select)').on('click', async function (e) {
6666
e.preventDefault();
67-
const selectedValue = $(this).data('id'); // eg: "refs/heads/my-branch"
68-
const editMode = $('#editing_mode').val();
69-
$($(this).data('id-selector')).val(selectedValue);
70-
if (isForNewIssue) {
71-
elSelectBranch.querySelector('.text-branch-name').textContent = this.getAttribute('data-name');
72-
return; // only update UI&form, do not send request/reload
73-
}
74-
75-
if (editMode === 'true') {
76-
const form = document.getElementById('update_issueref_form');
77-
const params = new URLSearchParams();
78-
params.append('ref', selectedValue);
67+
const selectedValue = this.getAttribute('data-id'); // eg: "refs/heads/my-branch"
68+
const selectedText = this.getAttribute('data-name'); // eg: "my-branch"
69+
if (urlUpdateIssueRef) {
70+
// for existing issue, send request to update issue ref, and reload page
7971
try {
80-
await POST(form.getAttribute('action'), {data: params});
72+
await POST(urlUpdateIssueRef, {data: new URLSearchParams({ref: selectedValue})});
8173
window.location.reload();
8274
} catch (error) {
8375
console.error(error);
8476
}
85-
} else if (editMode === '') {
86-
$selectBranch.find('.ui .branch-name').text(selectedValue);
77+
} else {
78+
// for new issue, only update UI&form, do not send request/reload
79+
const selectedHiddenSelector = this.getAttribute('data-id-selector');
80+
document.querySelector(selectedHiddenSelector).value = selectedValue;
81+
elSelectBranch.querySelector('.text-branch-name').textContent = selectedText;
8782
}
8883
});
8984
$selectBranch.find('.reference.column').on('click', function () {

0 commit comments

Comments
 (0)