@@ -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