ATL-786: Progress indication for install.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta
2021-04-08 15:18:44 +02:00
committed by Akos Kitta
parent 8071298598
commit 9aff90b0af
30 changed files with 557 additions and 219 deletions

View File

@@ -3,16 +3,15 @@ import debounce = require('lodash.debounce');
import { Event } from '@theia/core/lib/common/event';
import { CommandService } from '@theia/core/lib/common/command';
import { MessageService } from '@theia/core/lib/common/message-service';
import { OutputCommands } from '@theia/output/lib/browser/output-commands';
import { ConfirmDialog } from '@theia/core/lib/browser/dialogs';
import { Searchable } from '../../../common/protocol/searchable';
import { Installable } from '../../../common/protocol/installable';
import { ArduinoComponent } from '../../../common/protocol/arduino-component';
import { InstallationProgressDialog, UninstallationProgressDialog } from '../progress-dialog';
import { SearchBar } from './search-bar';
import { ListWidget } from './list-widget';
import { ComponentList } from './component-list';
import { ListItemRenderer } from './list-item-renderer';
import { ResponseServiceImpl } from '../../response-service-impl';
export class FilterableListContainer<T extends ArduinoComponent> extends React.Component<FilterableListContainer.Props<T>, FilterableListContainer.State<T>> {
@@ -84,20 +83,14 @@ export class FilterableListContainer<T extends ArduinoComponent> extends React.C
}
protected async install(item: T, version: Installable.Version): Promise<void> {
const { install, searchable, itemLabel } = this.props;
const dialog = new InstallationProgressDialog(itemLabel(item), version);
try {
dialog.open();
await this.clearArduinoChannel();
await install({ item, version });
const items = await searchable.search({ query: this.state.filterText });
this.setState({ items: this.sort(items) });
} catch (error) {
this.props.messageService.error(error instanceof Error ? error.message : String(error));
throw error;
} finally {
dialog.close();
}
const { install, searchable } = this.props;
await Installable.doWithProgress({
...this.props,
progressText: `Processing ${item.name}:${version}`,
run: ({ progressId }) => install({ item, progressId, version })
});
const items = await searchable.search({ query: this.state.filterText });
this.setState({ items: this.sort(items) });
}
protected async uninstall(item: T): Promise<void> {
@@ -110,21 +103,14 @@ export class FilterableListContainer<T extends ArduinoComponent> extends React.C
if (!ok) {
return;
}
const { uninstall, searchable, itemLabel } = this.props;
const dialog = new UninstallationProgressDialog(itemLabel(item));
try {
await this.clearArduinoChannel();
dialog.open();
await uninstall({ item });
const items = await searchable.search({ query: this.state.filterText });
this.setState({ items: this.sort(items) });
} finally {
dialog.close();
}
}
private async clearArduinoChannel(): Promise<void> {
return this.props.commandService.executeCommand(OutputCommands.CLEAR.id, { name: 'Arduino' });
const { uninstall, searchable } = this.props;
await Installable.doWithProgress({
...this.props,
progressText: `Processing ${item.name}${item.installedVersion ? `:${item.installedVersion}` : ''}`,
run: ({ progressId }) => uninstall({ item, progressId })
});
const items = await searchable.search({ query: this.state.filterText });
this.setState({ items: this.sort(items) });
}
}
@@ -139,9 +125,10 @@ export namespace FilterableListContainer {
readonly resolveContainer: (element: HTMLElement) => void;
readonly resolveFocus: (element: HTMLElement | undefined) => void;
readonly filterTextChangeEvent: Event<string | undefined>;
readonly install: ({ item, version }: { item: T, version: Installable.Version }) => Promise<void>;
readonly uninstall: ({ item }: { item: T }) => Promise<void>;
readonly messageService: MessageService;
readonly responseService: ResponseServiceImpl;
readonly install: ({ item, progressId, version }: { item: T, progressId: string, version: Installable.Version }) => Promise<void>;
readonly uninstall: ({ item, progressId }: { item: T, progressId: string }) => Promise<void>;
readonly commandService: CommandService;
}

View File

@@ -1,5 +1,6 @@
import * as React from 'react';
import { injectable, postConstruct, inject } from 'inversify';
import { Widget } from '@phosphor/widgets';
import { Message } from '@phosphor/messaging';
import { Deferred } from '@theia/core/lib/common/promise-util';
import { Emitter } from '@theia/core/lib/common/event';
@@ -7,12 +8,11 @@ import { MaybePromise } from '@theia/core/lib/common/types';
import { ReactWidget } from '@theia/core/lib/browser/widgets/react-widget';
import { CommandService } from '@theia/core/lib/common/command';
import { MessageService } from '@theia/core/lib/common/message-service';
import { Installable } from '../../../common/protocol/installable';
import { Searchable } from '../../../common/protocol/searchable';
import { ArduinoComponent } from '../../../common/protocol/arduino-component';
import { Installable, Searchable, ArduinoComponent } from '../../../common/protocol';
import { FilterableListContainer } from './filterable-list-container';
import { ListItemRenderer } from './list-item-renderer';
import { NotificationCenter } from '../../notification-center';
import { ResponseServiceImpl } from '../../response-service-impl';
@injectable()
export abstract class ListWidget<T extends ArduinoComponent> extends ReactWidget {
@@ -23,6 +23,9 @@ export abstract class ListWidget<T extends ArduinoComponent> extends ReactWidget
@inject(CommandService)
protected readonly commandService: CommandService;
@inject(ResponseServiceImpl)
protected readonly responseService: ResponseServiceImpl;
@inject(NotificationCenter)
protected readonly notificationCenter: NotificationCenter;
@@ -63,26 +66,31 @@ export abstract class ListWidget<T extends ArduinoComponent> extends ReactWidget
return this.deferredContainer.promise;
}
protected onActivateRequest(msg: Message): void {
super.onActivateRequest(msg);
protected onActivateRequest(message: Message): void {
super.onActivateRequest(message);
(this.focusNode || this.node).focus();
}
protected onUpdateRequest(msg: Message): void {
super.onUpdateRequest(msg);
protected onUpdateRequest(message: Message): void {
super.onUpdateRequest(message);
this.render();
}
protected onResize(message: Widget.ResizeMessage): void {
super.onResize(message);
this.updateScrollBar();
}
protected onFocusResolved = (element: HTMLElement | undefined) => {
this.focusNode = element;
};
protected async install({ item, version }: { item: T, version: Installable.Version }): Promise<void> {
return this.options.installable.install({ item, version });
protected async install({ item, progressId, version }: { item: T, progressId: string, version: Installable.Version }): Promise<void> {
return this.options.installable.install({ item, progressId, version });
}
protected async uninstall({ item }: { item: T }): Promise<void> {
return this.options.installable.uninstall({ item });
protected async uninstall({ item, progressId }: { item: T, progressId: string }): Promise<void> {
return this.options.installable.uninstall({ item, progressId });
}
render(): React.ReactNode {
@@ -97,7 +105,8 @@ export abstract class ListWidget<T extends ArduinoComponent> extends ReactWidget
itemRenderer={this.options.itemRenderer}
filterTextChangeEvent={this.filterTextChangeEmitter.event}
messageService={this.messageService}
commandService={this.commandService} />;
commandService={this.commandService}
responseService={this.responseService} />;
}
/**

View File

@@ -1,23 +0,0 @@
import { AbstractDialog } from '@theia/core/lib/browser';
export class InstallationProgressDialog extends AbstractDialog<undefined> {
readonly value = undefined;
constructor(componentName: string, version: string) {
super({ title: 'Installation in progress' });
this.contentNode.textContent = `Installing ${componentName} [${version}]. Please wait...`;
}
}
export class UninstallationProgressDialog extends AbstractDialog<undefined> {
readonly value = undefined;
constructor(componentName: string) {
super({ title: 'Uninstallation in progress' });
this.contentNode.textContent = `Uninstalling ${componentName}. Please wait...`;
}
}