@@ -58,32 +58,27 @@ export function initRepoCommentForm() {
58
58
function initBranchSelector ( ) {
59
59
const elSelectBranch = document . querySelector ( '.ui.dropdown.select-branch' ) ;
60
60
if ( ! elSelectBranch ) return ;
61
- const isForNewIssue = elSelectBranch . getAttribute ( 'data-for-new-issue' ) === 'true' ;
62
61
62
+ const urlUpdateIssueRef = elSelectBranch . getAttribute ( 'data-url-update-issueref' ) ;
63
63
const $selectBranch = $ ( elSelectBranch ) ;
64
64
const $branchMenu = $selectBranch . find ( '.reference-list-menu' ) ;
65
65
$branchMenu . find ( '.item:not(.no-select)' ) . on ( 'click' , async function ( e ) {
66
66
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
79
71
try {
80
- await POST ( form . getAttribute ( 'action' ) , { data : params } ) ;
72
+ await POST ( urlUpdateIssueRef , { data : new URLSearchParams ( { ref : selectedValue } ) } ) ;
81
73
window . location . reload ( ) ;
82
74
} catch ( error ) {
83
75
console . error ( error ) ;
84
76
}
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 ;
87
82
}
88
83
} ) ;
89
84
$selectBranch . find ( '.reference.column' ) . on ( 'click' , function ( ) {
0 commit comments