@@ -10,10 +10,7 @@ import React from '@theia/core/shared/react';
1010import ReactDOM from '@theia/core/shared/react-dom' ;
1111import classNames from 'classnames' ;
1212import { boardIdentifierLabel , Port } from '../../common/protocol' ;
13- import {
14- BoardListItem ,
15- BoardListItemUI ,
16- } from '../../common/protocol/board-list' ;
13+ import { BoardListItemUI } from '../../common/protocol/board-list' ;
1714import { assertUnreachable } from '../../common/utils' ;
1815import { BoardListUI , BoardsServiceProvider } from './boards-service-provider' ;
1916
@@ -29,13 +26,11 @@ export namespace BoardsDropDown {
2926 readonly coords : BoardsDropDownListCoords | 'hidden' ;
3027 readonly boardList : BoardListUI ;
3128 readonly openBoardsConfig : ( ) => void ;
29+ readonly hide : ( ) => void ;
3230 }
3331}
3432
35- export class BoardListDropDown extends React . Component <
36- BoardsDropDown . Props ,
37- { expandedItems : BoardListItem [ ] }
38- > {
33+ export class BoardListDropDown extends React . Component < BoardsDropDown . Props > {
3934 private dropdownElement : HTMLElement ;
4035 private listRef : React . RefObject < HTMLDivElement > ;
4136
@@ -49,7 +44,6 @@ export class BoardListDropDown extends React.Component<
4944 document . body . appendChild ( list ) ;
5045 this . dropdownElement = list ;
5146 }
52- this . state = { expandedItems : [ ] } ;
5347 }
5448
5549 override componentDidUpdate ( prevProps : BoardsDropDown . Props ) : void {
@@ -105,14 +99,15 @@ export class BoardListDropDown extends React.Component<
10599 }
106100
107101 private readonly onDefaultAction = ( item : BoardListItemUI ) : unknown => {
108- const { boardList } = this . props ;
102+ const { boardList, hide } = this . props ;
109103 const { type, params } = item . defaultAction ;
104+ hide ( ) ;
110105 switch ( type ) {
111106 case 'select-boards-config' : {
112- return boardList . onSelect ( params ) ;
107+ return boardList . select ( params ) ;
113108 }
114109 case 'edit-boards-config' : {
115- return boardList . onEdit ( params ) ;
110+ return boardList . edit ( params ) ;
116111 }
117112 default :
118113 return assertUnreachable ( type ) ;
@@ -166,11 +161,20 @@ export class BoardListDropDown extends React.Component<
166161 }
167162
168163 private renderActions ( item : BoardListItemUI ) : React . ReactNode {
169- const { boardList } = this . props ;
164+ const { boardList, hide } = this . props ;
170165 const { revert, edit } = item . otherActions ;
171166 if ( ! edit && ! revert ) {
172167 return undefined ;
173168 }
169+ const handleOnClick = (
170+ event : React . MouseEvent < HTMLElement , MouseEvent > ,
171+ callback : ( ) => void
172+ ) => {
173+ event . preventDefault ( ) ;
174+ event . stopPropagation ( ) ;
175+ hide ( ) ;
176+ callback ( ) ;
177+ } ;
174178 return (
175179 < div className = { TabBarToolbar . Styles . TAB_BAR_TOOLBAR } >
176180 { edit && (
@@ -185,11 +189,9 @@ export class BoardListDropDown extends React.Component<
185189 'arduino/board/editBoardsConfig' ,
186190 'Edit Board and Port...'
187191 ) }
188- onClick = { ( event ) => {
189- event . preventDefault ( ) ;
190- event . stopPropagation ( ) ;
191- boardList . onEdit ( edit . params ) ;
192- } }
192+ onClick = { ( event ) =>
193+ handleOnClick ( event , ( ) => boardList . edit ( edit . params ) )
194+ }
193195 />
194196 }
195197 </ div >
@@ -208,11 +210,9 @@ export class BoardListDropDown extends React.Component<
208210 boardIdentifierLabel ( revert . params . selectedBoard ) ,
209211 item . labels . portLabel
210212 ) }
211- onClick = { ( event ) => {
212- event . preventDefault ( ) ;
213- event . stopPropagation ( ) ;
214- boardList . onSelect ( revert . params ) ;
215- } }
213+ onClick = { ( event ) =>
214+ handleOnClick ( event , ( ) => boardList . select ( revert . params ) )
215+ }
216216 />
217217 }
218218 </ div >
@@ -292,16 +292,6 @@ export class BoardsToolBarItem extends React.Component<
292292 'fa' ,
293293 protocolIcon
294294 ) ;
295- const originalOnSelect = boardList . onSelect ;
296- boardList [ 'onSelect' ] = ( params ) => {
297- this . hide ( ) ;
298- return originalOnSelect . bind ( boardList ) ( params ) ;
299- } ;
300- const originalOnEdit = boardList . onEdit ;
301- boardList [ 'onEdit' ] = ( params ) => {
302- this . hide ( ) ;
303- return originalOnEdit . bind ( boardList ) ( params ) ;
304- } ;
305295 return (
306296 < React . Fragment >
307297 < div
@@ -325,7 +315,8 @@ export class BoardsToolBarItem extends React.Component<
325315 < BoardListDropDown
326316 coords = { coords }
327317 boardList = { boardList }
328- openBoardsConfig = { ( ) => boardList . onEdit ( { query : '' } ) }
318+ openBoardsConfig = { ( ) => boardList . edit ( { query : '' } ) }
319+ hide = { this . hide }
329320 />
330321 </ React . Fragment >
331322 ) ;
0 commit comments