@@ -82,62 +82,66 @@ function initRepoIssueListCheckboxes() {
82
82
} ) ;
83
83
}
84
84
85
- function initRepoIssueListAuthorDropdown ( ) {
86
- const $searchDropdown = $ ( '.user-remote-search' ) ;
87
- if ( ! $searchDropdown . length ) return ;
88
-
89
- let searchUrl = $searchDropdown . attr ( 'data-search-url' ) ;
90
- const actionJumpUrl = $searchDropdown . attr ( 'data-action-jump-url' ) ;
91
- const selectedUserId = $searchDropdown . attr ( 'data-selected-user-id' ) ;
92
- if ( ! searchUrl . includes ( '?' ) ) searchUrl += '?' ;
93
-
94
- $searchDropdown . dropdown ( 'setting' , {
95
- fullTextSearch : true ,
96
- selectOnKeydown : false ,
97
- apiSettings : {
98
- cache : false ,
99
- url : `${ searchUrl } &q={query}` ,
100
- onResponse ( resp ) {
101
- // the content is provided by backend IssuePosters handler
102
- const processedResults = [ ] ; // to be used by dropdown to generate menu items
103
- for ( const item of resp . results ) {
104
- let html = `<img class="ui avatar gt-vm" src="${ htmlEscape ( item . avatar_link ) } " aria-hidden="true" alt="" width="20" height="20"><span class="gt-ellipsis">${ htmlEscape ( item . username ) } </span>` ;
105
- if ( item . full_name ) html += `<span class="search-fullname gt-ml-3">${ htmlEscape ( item . full_name ) } </span>` ;
106
- processedResults . push ( { value : item . user_id , name : html } ) ;
107
- }
108
- resp . results = processedResults ;
109
- return resp ;
85
+ function initRepoIssueListUserDropdowns ( ) {
86
+ const userDropdowns = document . getElementsByClassName ( 'user-remote-search' ) ;
87
+ if ( ! userDropdowns . length ) return ;
88
+
89
+ for ( let i = 0 ; i < userDropdowns . length ; i ++ ) {
90
+ const $searchDropdown = $ ( userDropdowns [ i ] ) ;
91
+
92
+ let searchUrl = $searchDropdown . attr ( 'data-search-url' ) ;
93
+ const actionJumpUrl = $searchDropdown . attr ( 'data-action-jump-url' ) ;
94
+ const selectedUserId = $searchDropdown . attr ( 'data-selected-user-id' ) ;
95
+ if ( ! searchUrl . includes ( '?' ) ) searchUrl += '?' ;
96
+
97
+ $searchDropdown . dropdown ( 'setting' , {
98
+ fullTextSearch : true ,
99
+ selectOnKeydown : false ,
100
+ apiSettings : {
101
+ cache : false ,
102
+ url : `${ searchUrl } &q={query}` ,
103
+ onResponse ( resp ) {
104
+ // the content is provided by backend IssuePosters handler
105
+ const processedResults = [ ] ; // to be used by dropdown to generate menu items
106
+ for ( const item of resp . results ) {
107
+ let html = `<img class="ui avatar gt-vm" src="${ htmlEscape ( item . avatar_link ) } " aria-hidden="true" alt="" width="20" height="20"><span class="gt-ellipsis">${ htmlEscape ( item . username ) } </span>` ;
108
+ if ( item . full_name ) html += `<span class="search-fullname gt-ml-3">${ htmlEscape ( item . full_name ) } </span>` ;
109
+ processedResults . push ( { value : item . user_id , name : html } ) ;
110
+ }
111
+ resp . results = processedResults ;
112
+ return resp ;
113
+ } ,
110
114
} ,
111
- } ,
112
- action : ( _text , value ) => {
113
- window . location . href = actionJumpUrl . replace ( '{user_id}' , encodeURIComponent ( value ) ) ;
114
- } ,
115
- onShow : ( ) => {
116
- $searchDropdown . dropdown ( 'filter' , ' ' ) ; // trigger a search on first show
117
- } ,
118
- } ) ;
115
+ action : ( _text , value ) => {
116
+ window . location . href = actionJumpUrl . replace ( '{user_id}' , encodeURIComponent ( value ) ) ;
117
+ } ,
118
+ onShow : ( ) => {
119
+ $searchDropdown . dropdown ( 'filter' , ' ' ) ; // trigger a search on first show
120
+ } ,
121
+ } ) ;
119
122
120
- // we want to generate the dropdown menu items by ourselves, replace its internal setup functions
121
- const dropdownSetup = { ...$searchDropdown . dropdown ( 'internal' , 'setup' ) } ;
122
- const dropdownTemplates = $searchDropdown . dropdown ( 'setting' , 'templates' ) ;
123
- $searchDropdown . dropdown ( 'internal' , 'setup' , dropdownSetup ) ;
124
- dropdownSetup . menu = function ( values ) {
125
- const $menu = $searchDropdown . find ( '> .menu' ) ;
126
- $menu . find ( '> .dynamic-item' ) . remove ( ) ; // remove old dynamic items
127
-
128
- const newMenuHtml = dropdownTemplates . menu ( values , $searchDropdown . dropdown ( 'setting' , 'fields' ) , true /* html */ , $searchDropdown . dropdown ( 'setting' , 'className' ) ) ;
129
- if ( newMenuHtml ) {
130
- const $newMenuItems = $ ( newMenuHtml ) ;
131
- $newMenuItems . addClass ( 'dynamic-item' ) ;
132
- $menu . append ( '<div class="divider dynamic-item"></div>' , ...$newMenuItems ) ;
133
- }
134
- $searchDropdown . dropdown ( 'refresh' ) ;
135
- // defer our selection to the next tick, because dropdown will set the selection item after this `menu` function
136
- setTimeout ( ( ) => {
137
- $menu . find ( '.item.active, .item.selected' ) . removeClass ( 'active selected' ) ;
138
- $menu . find ( `.item[data-value="${ selectedUserId } "]` ) . addClass ( 'selected' ) ;
139
- } , 0 ) ;
140
- } ;
123
+ // we want to generate the dropdown menu items by ourselves, replace its internal setup functions
124
+ const dropdownSetup = { ...$searchDropdown . dropdown ( 'internal' , 'setup' ) } ;
125
+ const dropdownTemplates = $searchDropdown . dropdown ( 'setting' , 'templates' ) ;
126
+ $searchDropdown . dropdown ( 'internal' , 'setup' , dropdownSetup ) ;
127
+ dropdownSetup . menu = function ( values ) {
128
+ const $menu = $searchDropdown . find ( '> .menu' ) ;
129
+ $menu . find ( '> .dynamic-item' ) . remove ( ) ; // remove old dynamic items
130
+
131
+ const newMenuHtml = dropdownTemplates . menu ( values , $searchDropdown . dropdown ( 'setting' , 'fields' ) , true /* html */ , $searchDropdown . dropdown ( 'setting' , 'className' ) ) ;
132
+ if ( newMenuHtml ) {
133
+ const $newMenuItems = $ ( newMenuHtml ) ;
134
+ $newMenuItems . addClass ( 'dynamic-item' ) ;
135
+ $menu . append ( '<div class="divider dynamic-item"></div>' , ...$newMenuItems ) ;
136
+ }
137
+ $searchDropdown . dropdown ( 'refresh' ) ;
138
+ // defer our selection to the next tick, because dropdown will set the selection item after this `menu` function
139
+ setTimeout ( ( ) => {
140
+ $menu . find ( '.item.active, .item.selected' ) . removeClass ( 'active selected' ) ;
141
+ $menu . find ( `.item[data-value="${ selectedUserId } "]` ) . addClass ( 'selected' ) ;
142
+ } , 0 ) ;
143
+ } ;
144
+ }
141
145
}
142
146
143
147
function initPinRemoveButton ( ) {
@@ -222,9 +226,9 @@ function initArchivedLabelFilter() {
222
226
}
223
227
224
228
export function initRepoIssueList ( ) {
225
- if ( ! document . querySelectorAll ( '.page-content.repository.issue-list, .page-content.repository.milestone-issue-list' ) . length ) return ;
229
+ if ( ! document . querySelectorAll ( '.page-content.repository.issue-list, .page-content.repository.milestone-issue-list, .page-content.dashboard.issues ' ) . length ) return ;
226
230
initRepoIssueListCheckboxes ( ) ;
227
- initRepoIssueListAuthorDropdown ( ) ;
231
+ initRepoIssueListUserDropdowns ( ) ;
228
232
initIssuePinSort ( ) ;
229
233
initArchivedLabelFilter ( ) ;
230
234
}
0 commit comments