fix: board <select> update on board detach

When the previously selected board is not detected, unset the `<select>`
option.

Closes #2222

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
Akos Kitta 2023-11-22 16:33:01 +01:00 committed by Akos Kitta
parent d01f95647e
commit 0ca1a31747
3 changed files with 9 additions and 4 deletions

View File

@ -69,6 +69,7 @@ export const CertificateUploaderComponent = ({
const onItemSelect = React.useCallback( const onItemSelect = React.useCallback(
(item: BoardOptionValue | null) => { (item: BoardOptionValue | null) => {
if (!item) { if (!item) {
setSelectedItem(null);
return; return;
} }
const board = item.board; const board = item.board;

View File

@ -1,8 +1,9 @@
import { nls } from '@theia/core/lib/common'; import { nls } from '@theia/core/lib/common';
import React from '@theia/core/shared/react'; import React from '@theia/core/shared/react';
import type { import {
BoardList, boardListItemEquals,
BoardListItemWithBoard, type BoardList,
type BoardListItemWithBoard,
} from '../../../common/protocol/board-list'; } from '../../../common/protocol/board-list';
import { ArduinoSelect } from '../../widgets/arduino-select'; import { ArduinoSelect } from '../../widgets/arduino-select';
@ -75,7 +76,9 @@ export const SelectBoardComponent = ({
setSelectOptions(boardOptions); setSelectOptions(boardOptions);
if (selectedItem) { if (selectedItem) {
selBoard = updatableBoards.indexOf(selectedItem); selBoard = updatableBoards.findIndex((board) =>
boardListItemEquals(board, selectedItem)
);
} }
selectOption(boardOptions[selBoard] || null); selectOption(boardOptions[selBoard] || null);

View File

@ -104,6 +104,7 @@ export const FirmwareUploaderComponent = ({
const onItemSelect = React.useCallback( const onItemSelect = React.useCallback(
(item: BoardListItemWithBoard | null) => { (item: BoardListItemWithBoard | null) => {
if (!item) { if (!item) {
setSelectedItem(null);
return; return;
} }
const board = item.board; const board = item.board;