@@ -10,6 +10,7 @@ import {
1010} from './boards-service-provider' ;
1111import { nls } from '@theia/core/lib/common' ;
1212import classNames from 'classnames' ;
13+ import { BoardsConfig } from './boards-config' ;
1314
1415export interface BoardsDropDownListCoords {
1516 readonly top : number ;
@@ -199,18 +200,17 @@ export class BoardsToolBarItem extends React.Component<
199200
200201 override render ( ) : React . ReactNode {
201202 const { coords, availableBoards } = this . state ;
202- const selectedBoard = availableBoards . find ( ( { selected } ) => selected ) ;
203+ const { selectedBoard, selectedPort } =
204+ this . props . boardsServiceProvider . boardsConfig ;
203205
204206 const boardLabel =
205207 selectedBoard ?. name ||
206208 nls . localize ( 'arduino/board/selectBoard' , 'Select Board' ) ;
207- const selectedPortLabel = portLabel ( selectedBoard ?. port ?. address ) ;
209+ const selectedPortLabel = portLabel ( selectedPort ?. address ) ;
208210
209- const isConnected = Boolean (
210- selectedBoard && AvailableBoard . hasPort ( selectedBoard )
211- ) ;
211+ const isConnected = Boolean ( selectedBoard && selectedPort ) ;
212212 const protocolIcon = isConnected
213- ? iconNameFromProtocol ( selectedBoard ?. port ?. protocol || '' )
213+ ? iconNameFromProtocol ( selectedPort ?. protocol || '' )
214214 : null ;
215215 const protocolIconClassNames = classNames (
216216 'arduino-boards-toolbar-item--protocol' ,
@@ -244,11 +244,13 @@ export class BoardsToolBarItem extends React.Component<
244244 . map ( ( board ) => ( {
245245 ...board ,
246246 onClick : ( ) => {
247- if ( board . state === AvailableBoard . State . incomplete ) {
247+ if ( ! board . fqbn ) {
248+ const previousBoardConfig =
249+ this . props . boardsServiceProvider . boardsConfig ;
248250 this . props . boardsServiceProvider . boardsConfig = {
249251 selectedPort : board . port ,
250252 } ;
251- this . openDialog ( ) ;
253+ this . openDialog ( previousBoardConfig ) ;
252254 } else {
253255 this . props . boardsServiceProvider . boardsConfig = {
254256 selectedBoard : board ,
@@ -264,10 +266,20 @@ export class BoardsToolBarItem extends React.Component<
264266 ) ;
265267 }
266268
267- protected openDialog = ( ) : void => {
268- this . props . commands . executeCommand (
269- OpenBoardsConfig . Commands . OPEN_DIALOG . id
270- ) ;
269+ protected openDialog = async (
270+ previousBoardConfig ?: BoardsConfig . Config
271+ ) : Promise < void > => {
272+ const selectedBoardConfig =
273+ await this . props . commands . executeCommand < BoardsConfig . Config > (
274+ OpenBoardsConfig . Commands . OPEN_DIALOG . id
275+ ) ;
276+ if (
277+ previousBoardConfig &&
278+ ( ! selectedBoardConfig ?. selectedPort ||
279+ ! selectedBoardConfig ?. selectedBoard )
280+ ) {
281+ this . props . boardsServiceProvider . boardsConfig = previousBoardConfig ;
282+ }
271283 } ;
272284}
273285export namespace BoardsToolBarItem {
0 commit comments