Skip to content

Commit 8610332

Browse files
author
Alberto Iannaccone
authored
Fix board selector synchronization (#1214)
* prevent deselecting a board from the board selctor * orrectly update board selector when baord config changes
1 parent 1f7c2eb commit 8610332

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

Diff for: arduino-ide-extension/src/browser/boards/boards-service-provider.ts

+1
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
516516
for (let i = 0; !hasChanged && i < availableBoards.length; i++) {
517517
const [left, right] = [availableBoards[i], currentAvailableBoards[i]];
518518
hasChanged =
519+
left.fqbn !== right.fqbn ||
519520
!!AvailableBoard.compare(left, right) ||
520521
left.selected !== right.selected;
521522
}

Diff for: arduino-ide-extension/src/browser/boards/boards-toolbar-item.tsx

+24-12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from './boards-service-provider';
1111
import { nls } from '@theia/core/lib/common';
1212
import classNames from 'classnames';
13+
import { BoardsConfig } from './boards-config';
1314

1415
export 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
}
273285
export namespace BoardsToolBarItem {

Diff for: arduino-ide-extension/src/browser/contributions/open-boards-config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class OpenBoardsConfig extends Contribution {
1717
execute: async (query?: string | undefined) => {
1818
const boardsConfig = await this.boardsConfigDialog.open(query);
1919
if (boardsConfig) {
20-
this.boardsServiceProvider.boardsConfig = boardsConfig;
20+
return (this.boardsServiceProvider.boardsConfig = boardsConfig);
2121
}
2222
},
2323
});

0 commit comments

Comments
 (0)