From 281ed4a69ceb9b251f498c28ec92edec76e9bbf1 Mon Sep 17 00:00:00 2001 From: Nina Doschek Date: Wed, 20 Jan 2021 15:48:43 +0100 Subject: [PATCH] Address review comments #2 Signed-off-by: Nina Doschek --- .../src/browser/empty-property-view-widget-provider.tsx | 4 +++- .../src/browser/property-view-frontend-module.ts | 3 ++- .../property-view/src/browser/property-view-service.ts | 9 ++++----- .../property-view/src/browser/property-view-widget.tsx | 8 ++++++-- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/property-view/src/browser/empty-property-view-widget-provider.tsx b/packages/property-view/src/browser/empty-property-view-widget-provider.tsx index 351162c5ea13b..15f6bdc7f5da3 100644 --- a/packages/property-view/src/browser/empty-property-view-widget-provider.tsx +++ b/packages/property-view/src/browser/empty-property-view-widget-provider.tsx @@ -39,9 +39,11 @@ class EmptyPropertyViewWidget extends ReactWidget implements PropertyViewContent } protected render(): React.ReactNode { - return
{'No properties available.'}
; + return this.emptyComponent; } + protected emptyComponent: JSX.Element =
No properties available.
; + } /** diff --git a/packages/property-view/src/browser/property-view-frontend-module.ts b/packages/property-view/src/browser/property-view-frontend-module.ts index 0598cd1d1cb51..5912e5d850ab4 100644 --- a/packages/property-view/src/browser/property-view-frontend-module.ts +++ b/packages/property-view/src/browser/property-view-frontend-module.ts @@ -32,7 +32,8 @@ export default new ContainerModule(bind => { bindContributionProvider(bind, PropertyDataService); bindContributionProvider(bind, PropertyViewWidgetProvider); - bind(PropertyViewWidgetProvider).to(EmptyPropertyViewWidgetProvider).inSingletonScope(); + bind(EmptyPropertyViewWidgetProvider).toSelf().inSingletonScope(); + bind(PropertyViewWidgetProvider).to(EmptyPropertyViewWidgetProvider); bind(PropertyViewWidget).toSelf(); bind(WidgetFactory).toDynamicValue(({ container }) => ({ diff --git a/packages/property-view/src/browser/property-view-service.ts b/packages/property-view/src/browser/property-view-service.ts index 8282edc20601c..6097f1e39a917 100644 --- a/packages/property-view/src/browser/property-view-service.ts +++ b/packages/property-view/src/browser/property-view-service.ts @@ -28,6 +28,9 @@ export class PropertyViewService { @inject(ContributionProvider) @named(PropertyViewWidgetProvider) private readonly contributions: ContributionProvider; + @inject(EmptyPropertyViewWidgetProvider) + private readonly emptyWidgetProvider: EmptyPropertyViewWidgetProvider; + private providers: PropertyViewWidgetProvider[] = []; @postConstruct() @@ -41,7 +44,7 @@ export class PropertyViewService { */ async getProvider(selection: Object | undefined): Promise { const provider = await this.prioritize(selection); - return provider ?? this.getEmptyProvider(); + return provider ?? this.emptyWidgetProvider; } protected async prioritize(selection: Object | undefined): Promise { @@ -55,8 +58,4 @@ export class PropertyViewService { return prioritized.length !== 0 ? prioritized[0].value : undefined; } - private getEmptyProvider(): PropertyViewWidgetProvider { - return this.providers.find(p => p.id === EmptyPropertyViewWidgetProvider.ID) as EmptyPropertyViewWidgetProvider; - } - } diff --git a/packages/property-view/src/browser/property-view-widget.tsx b/packages/property-view/src/browser/property-view-widget.tsx index af7aaf3d69f41..6f256f86a850f 100644 --- a/packages/property-view/src/browser/property-view-widget.tsx +++ b/packages/property-view/src/browser/property-view-widget.tsx @@ -46,11 +46,15 @@ export class PropertyViewWidget extends BaseWidget { this.addClass('theia-property-view-widget'); this.node.tabIndex = 0; + let disposed = false; + this.toDispose.push(Disposable.create(() => disposed = true)); this.toDispose.push(this.selectionService.onSelectionChanged((selection: Object | undefined) => { this.propertyViewService.getProvider(selection).then(provider => { provider.provideWidget(selection).then(contentWidget => { - this.replaceContentWidget(contentWidget); - provider.updateContentWidget(selection); + if (!disposed) { + this.replaceContentWidget(contentWidget); + provider.updateContentWidget(selection); + } }); }); }));