Skip to content

Commit

Permalink
fix: regressions
Browse files Browse the repository at this point in the history
  • Loading branch information
Akos Kitta committed Jul 25, 2023
1 parent e064f1a commit a3382ba
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ namespace BoardsConfigComponent {

export interface State {
searchResults: Array<BoardWithPackage>;
boardList: BoardList;
showAllPorts: boolean;
query: string;
}
Expand Down Expand Up @@ -88,7 +87,6 @@ export class BoardsConfigComponent extends React.Component<
searchResults: [],
showAllPorts: false,
query: '',
boardList: props.boardList,
};
this.toDispose = new DisposableCollection();
}
Expand Down Expand Up @@ -196,7 +194,8 @@ export class BoardsConfigComponent extends React.Component<
}

private renderBoards(): React.ReactNode {
const { boardList, searchResults, query } = this.state;
const { boardList } = this.props;
const { searchResults, query } = this.state;
// Board names are not unique per core https://github.com/arduino/arduino-pro-ide/issues/262#issuecomment-661019560
// It is tricky when the core is not yet installed, no FQBNs are available.
const distinctBoards = new Map<string, Board.Detailed>();
Expand Down Expand Up @@ -256,8 +255,9 @@ export class BoardsConfigComponent extends React.Component<
}

private renderPorts(): React.ReactNode {
const { boardList } = this.props;
const predicate = this.state.showAllPorts ? undefined : Port.isVisiblePort;
const detectedPorts = this.state.boardList.ports(predicate);
const detectedPorts = boardList.ports(predicate);
return !detectedPorts.length ? (
<div className="no-result">
{nls.localize('arduino/board/noPortsDiscovered', 'No ports discovered')}
Expand Down
59 changes: 30 additions & 29 deletions arduino-ide-extension/src/browser/boards/boards-config-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ import { ReactDialog } from '../theia/dialogs/dialogs';
import { BoardsServiceProvider } from './boards-service-provider';
import { BoardsConfigComponent } from './boards-config-component';

export interface OpenBoardsConfigDialogParams {
/**
* Use an empty string if you want to reset the search term. Using `undefined` has no effect.
*/
readonly query?: string | undefined;
readonly portToSelectBeforeOpen?: PortIdentifier;
}

@injectable()
export class BoardsConfigDialogProps extends DialogProps {}

Expand All @@ -33,6 +41,20 @@ export class BoardsConfigDialog extends ReactDialog<BoardsConfig> {
private readonly notificationCenter: NotificationCenter;

private readonly onFilterTextDidChangeEmitter: Emitter<string>;
private readonly onBoardSelected = (board: BoardIdentifier): void => {
this._boardsConfig.selectedBoard = board;
};
private readonly onPortSelected = (port: PortIdentifier): void => {
this._boardsConfig.selectedPort = port;
};
private readonly setFocusNode = (element: HTMLElement | undefined): void => {
this.focusNode = element;
};
private readonly searchBoards = (options: {
query?: string;
}): Promise<BoardWithPackage[]> => {
return this.boardsServiceProvider.searchBoards(options);
};
private _boardsConfig: BoardsConfig;
private focusNode: HTMLElement | undefined;

Expand All @@ -49,25 +71,22 @@ export class BoardsConfigDialog extends ReactDialog<BoardsConfig> {
this.appendAcceptButton(nls.localize('vscode/issueMainService/ok', 'OK'));
this._boardsConfig = emptyBoardsConfig();
this.onFilterTextDidChangeEmitter = new Emitter();
this.toDispose.push(this.onFilterTextDidChangeEmitter);
}

@postConstruct()
protected init(): void {
this.toDispose.push(
this.boardsServiceProvider.onBoardListDidChange(() => this.update())
);
this.boardsServiceProvider.onBoardListDidChange(() => this.update()); // Do not add to `toDispose`!
this._boardsConfig = deepClone(this.boardsServiceProvider.boardsConfig);
}

/**
* Pass in an empty string if you want to reset the search term. Using `undefined` has no effect.
*/
override async open(
query: string | undefined = undefined
params?: OpenBoardsConfigDialogParams
): Promise<BoardsConfig | undefined> {
if (typeof query === 'string') {
this.onFilterTextDidChangeEmitter.fire(query);
if (typeof params?.query === 'string') {
this.onFilterTextDidChangeEmitter.fire(params?.query);
}
if (params?.portToSelectBeforeOpen) {
this._boardsConfig.selectedPort = params.portToSelectBeforeOpen;
}
return super.open();
}
Expand All @@ -77,7 +96,7 @@ export class BoardsConfigDialog extends ReactDialog<BoardsConfig> {
this.update();
}

protected render(): ReactNode {
protected override render(): ReactNode {
return (
<>
<div className="head">
Expand Down Expand Up @@ -116,24 +135,6 @@ export class BoardsConfigDialog extends ReactDialog<BoardsConfig> {
);
}

private readonly onBoardSelected = (board: BoardIdentifier): void => {
this._boardsConfig.selectedBoard = board;
};

private readonly onPortSelected = (port: PortIdentifier): void => {
this._boardsConfig.selectedPort = port;
};

private readonly setFocusNode = (element: HTMLElement | undefined): void => {
this.focusNode = element;
};

private readonly searchBoards = (options: {
query?: string;
}): Promise<BoardWithPackage[]> => {
return this.boardsServiceProvider.searchBoards(options);
};

protected override onActivateRequest(msg: Message): void {
super.onActivateRequest(msg);
if (this.focusNode instanceof HTMLInputElement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class BoardsServiceProvider

onStart(): void {
this.notificationCenter.onDetectedPortsDidChange(({ detectedPorts }) =>
this.refreshBoardList(detectedPorts)
this.refreshBoardList({ detectedPorts })
);
this.appStateService.reachedState('ready').then(async () => {
const [detectedPorts, storedState] = await Promise.all([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import type { Command, CommandRegistry } from '@theia/core/lib/common/command';
import { deepClone } from '@theia/core/lib/common/objects';
import { inject, injectable } from '@theia/core/shared/inversify';
import {
BoardsConfig,
isDefinedBoardsConfig,
PortIdentifier,
} from '../../common/protocol/boards-service';
import { BoardsConfigDialog } from '../boards/boards-config-dialog';
import {
BoardsConfigDialog,
OpenBoardsConfigDialogParams,
} from '../boards/boards-config-dialog';
import { BoardsServiceProvider } from '../boards/boards-service-provider';
import { Contribution } from './contribution';

export interface OpenBoardsConfigParams {
readonly query?: string | undefined;
readonly portToSelectBeforeOpen?: PortIdentifier;
}

@injectable()
export class OpenBoardsConfig extends Contribution {
@inject(BoardsServiceProvider)
Expand All @@ -24,25 +20,15 @@ export class OpenBoardsConfig extends Contribution {

override registerCommands(registry: CommandRegistry): void {
registry.registerCommand(OpenBoardsConfig.Commands.OPEN_DIALOG, {
execute: async (params?: OpenBoardsConfigParams) => this.open(params),
execute: async (params?: OpenBoardsConfigDialogParams) =>
this.open(params),
});
}

private async open(
params: OpenBoardsConfigParams = {}
params: OpenBoardsConfigDialogParams = {}
): Promise<BoardsConfig | undefined> {
const { query, portToSelectBeforeOpen } = params;
const beforeOpenBoardsConfig = deepClone(
this.boardsServiceProvider.boardsConfig
);
if (portToSelectBeforeOpen) {
this.boardsServiceProvider.updatePort(portToSelectBeforeOpen);
}
let boardsConfig = await this.boardsConfigDialog.open(query);
if (!boardsConfig) {
// if dialog was canceled restore the state
boardsConfig = beforeOpenBoardsConfig;
}
const boardsConfig = await this.boardsConfigDialog.open(params);
if (isDefinedBoardsConfig(boardsConfig)) {
this.boardsServiceProvider.updateConfig(boardsConfig, 'dialog');
} else if (boardsConfig?.selectedBoard) {
Expand Down
4 changes: 2 additions & 2 deletions arduino-ide-extension/src/common/protocol/boards-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ export namespace Port {
}

/**
* Key is the combination of address and protocol formatted like `'${address}|${protocol}'` used to uniquely identify a port.
* Key is the combination of address and protocol formatted like `'arduino+${protocol}://${address}'` used to uniquely identify a port.
*/
export function keyOf({ protocol, address }: PortIdentifier): string {
return `${address}|${protocol}`;
return `arduino+${protocol}://${address}`;
}

export function toString({ addressLabel, protocolLabel }: Port): string {
Expand Down

0 comments on commit a3382ba

Please sign in to comment.