diff --git a/theia-extensions/viewer-prototype/src/browser/trace-explorer/trace-explorer-sub-widgets/theia-trace-explorer-placeholder-widget.tsx b/theia-extensions/viewer-prototype/src/browser/trace-explorer/trace-explorer-sub-widgets/theia-trace-explorer-placeholder-widget.tsx index 5fd101ae..1a0a23f1 100644 --- a/theia-extensions/viewer-prototype/src/browser/trace-explorer/trace-explorer-sub-widgets/theia-trace-explorer-placeholder-widget.tsx +++ b/theia-extensions/viewer-prototype/src/browser/trace-explorer/trace-explorer-sub-widgets/theia-trace-explorer-placeholder-widget.tsx @@ -13,7 +13,8 @@ export class TraceExplorerPlaceholderWidget extends ReactWidget { state = { loading: false, - serverStatus: false + serverStatus: false, + tracesOpened: false }; @inject(CommandService) protected readonly commandService!: CommandService; @@ -24,20 +25,18 @@ export class TraceExplorerPlaceholderWidget extends ReactWidget { protected init(): void { this.id = TraceExplorerPlaceholderWidget.ID; this.title.label = TraceExplorerPlaceholderWidget.LABEL; - this.traceServerConnectionStatusProxy.addServerStatusChangeListener(this.handleOnServerStatusChange); this.update(); } dispose(): void { super.dispose(); - this.traceServerConnectionStatusProxy.removeServerStatusChangeListener(this.handleOnServerStatusChange); } render(): React.ReactNode { - const { loading, serverStatus } = this.state; + const { loading, serverStatus, tracesOpened } = this.state; return ( this.doHandleOnServerStatusChange(status); - - private doHandleOnServerStatusChange = (status: boolean): void => { - this.state.serverStatus = status; - this.update(); - }; + public setStateAndShow(newState: { serverStatus: boolean; tracesOpened: boolean }): void { + this.state = { ...newState, ...this.state }; + this.show(); + } } diff --git a/theia-extensions/viewer-prototype/src/browser/trace-explorer/trace-explorer-widget.tsx b/theia-extensions/viewer-prototype/src/browser/trace-explorer/trace-explorer-widget.tsx index edaab17c..da765d6e 100644 --- a/theia-extensions/viewer-prototype/src/browser/trace-explorer/trace-explorer-widget.tsx +++ b/theia-extensions/viewer-prototype/src/browser/trace-explorer/trace-explorer-widget.tsx @@ -105,15 +105,16 @@ export class TraceExplorerWidget extends BaseWidget { protected onUpdateRequest(msg: Message): void { super.onUpdateRequest(msg); - if (this.connectionStatusClient.status === false) { - this.togglePlaceholderWidget(true); - return; - } + const serverStatus = this.connectionStatusClient.status; + const tracesOpened = this._numberOfOpenedTraces > 0; + const shouldShowPlaceholder = serverStatus === false || tracesOpened === false; - if (this._numberOfOpenedTraces > 0) { - this.togglePlaceholderWidget(false); + if (shouldShowPlaceholder) { + this.placeholderWidget.setStateAndShow({ serverStatus, tracesOpened }); + this.traceViewsContainer.hide(); } else { - this.togglePlaceholderWidget(true); + this.placeholderWidget.hide(); + this.traceViewsContainer.show(); } } @@ -136,21 +137,5 @@ export class TraceExplorerWidget extends BaseWidget { protected doHandleOnServerStatusChange(status: boolean): void { this.serverStatusWidget.updateStatus(status); - if (status === true) { - this.togglePlaceholderWidget(true); - } else { - this.togglePlaceholderWidget(false); - } - this.update(); - } - - private togglePlaceholderWidget(shouldShowWidget: boolean): void { - if (shouldShowWidget) { - this.placeholderWidget.show(); - this.traceViewsContainer.hide(); - } else { - this.placeholderWidget.hide(); - this.traceViewsContainer.show(); - } } }