diff --git a/packages/react-components/src/trace-explorer/trace-explorer-placeholder-widget.tsx b/packages/react-components/src/trace-explorer/trace-explorer-placeholder-widget.tsx index 44bd1ffd0..dc15297d3 100644 --- a/packages/react-components/src/trace-explorer/trace-explorer-placeholder-widget.tsx +++ b/packages/react-components/src/trace-explorer/trace-explorer-placeholder-widget.tsx @@ -4,31 +4,43 @@ import * as React from 'react'; export interface ReactPlaceholderWidgetProps { loading: boolean; + serverOn: boolean; + tracesOpen: boolean; handleOpenTrace: () => void; + handleStartServer: () => void; } -export class ReactExplorerPlaceholderWidget extends React.Component { +export class ReactExplorerPlaceholderWidget extends React.Component { constructor(props: ReactPlaceholderWidgetProps) { super(props); } render(): React.ReactNode { + const { loading, serverOn, handleOpenTrace, handleStartServer } = this.props; + const onClick = serverOn ? handleOpenTrace : handleStartServer; + const infoText = serverOn + ? 'You have not yet opened a trace.' + : 'No trace server instance is currently running.'; + const buttonText = serverOn ? 'Open Trace' : 'Start Trace Server'; + return (
-
{'You have not yet opened a trace.'}
+
{infoText}
); } } + +export default ReactExplorerPlaceholderWidget; 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 9ef03f1bb..a1b4fe7c9 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 @@ -2,8 +2,10 @@ import { inject, injectable, postConstruct } from '@theia/core/shared/inversify' import { ReactWidget } from '@theia/core/lib/browser'; import * as React from 'react'; import { CommandService } from '@theia/core'; -import { OpenTraceCommand } from '../../trace-viewer/trace-viewer-commands'; +import { OpenTraceCommand, StartServerCommand } from '../../trace-viewer/trace-viewer-commands'; import { ReactExplorerPlaceholderWidget } from 'traceviewer-react-components/lib/trace-explorer/trace-explorer-placeholder-widget'; +import { RestClient } from 'tsp-typescript-client/lib/protocol/rest-client'; +import { TraceServerConnectionStatusBackend } from '../../../common/trace-server-connection-status'; @injectable() export class TraceExplorerPlaceholderWidget extends ReactWidget { @@ -11,22 +13,34 @@ export class TraceExplorerPlaceholderWidget extends ReactWidget { static LABEL = 'Trace Explorer Placeholder Widget'; state = { - loading: false + loading: false, + serverStatus: false }; @inject(CommandService) protected readonly commandService!: CommandService; + @inject(TraceServerConnectionStatusBackend) + protected traceServerConnectionStatusProxy: TraceServerConnectionStatusBackend; @postConstruct() protected init(): void { this.id = TraceExplorerPlaceholderWidget.ID; this.title.label = TraceExplorerPlaceholderWidget.LABEL; + RestClient.addConnectionStatusListener(this.handleOnServerStatusChange); this.update(); } + dispose(): void { + super.dispose(); + RestClient.removeConnectionStatusListener(this.handleOnServerStatusChange); + } + render(): React.ReactNode { - const { loading } = this.state; + const { loading, serverStatus } = this.state; return ( @@ -42,4 +56,22 @@ export class TraceExplorerPlaceholderWidget extends ReactWidget { this.state.loading = false; this.update(); } + + protected handleStartServer = async (): Promise => this.doHandleStartServer(); + + private async doHandleStartServer() { + this.state.loading = true; + this.update(); + await this.commandService.executeCommand(StartServerCommand.id); + this.state.loading = false; + const status = await this.traceServerConnectionStatusProxy.getStatus(); + this.handleOnServerStatusChange(status); + } + + protected handleOnServerStatusChange = (status: boolean): void => this.doHandleOnServerStatusChange(status); + + private doHandleOnServerStatusChange = (status: boolean): void => { + this.state.serverStatus = status; + this.update(); + }; }