Skip to content

Commit

Permalink
Resuming Work
Browse files Browse the repository at this point in the history
  • Loading branch information
williamsyang-work committed Feb 14, 2024
1 parent ff89b73 commit 05cdf04
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import * as React from 'react';
import { CommandService } from '@theia/core';
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';
import { TraceServerConnectionStatusClient } from '../../../common/trace-server-connection-status';

@injectable()
export class TraceExplorerPlaceholderWidget extends ReactWidget {
Expand All @@ -18,20 +17,21 @@ export class TraceExplorerPlaceholderWidget extends ReactWidget {
};

@inject(CommandService) protected readonly commandService!: CommandService;
@inject(TraceServerConnectionStatusBackend)
protected traceServerConnectionStatusProxy: TraceServerConnectionStatusBackend;
@inject(TraceServerConnectionStatusClient)
protected traceServerConnectionStatusProxy: TraceServerConnectionStatusClient;

@postConstruct()
protected init(): void {
this.id = TraceExplorerPlaceholderWidget.ID;
this.title.label = TraceExplorerPlaceholderWidget.LABEL;
RestClient.addConnectionStatusListener(this.handleOnServerStatusChange);
this.traceServerConnectionStatusProxy.addServerStatusChangeListener(this.handleOnServerStatusChange);
this.update();
}

dispose(): void {
super.dispose();
RestClient.removeConnectionStatusListener(this.handleOnServerStatusChange);
this.traceServerConnectionStatusProxy.removeServerStatusChangeListener(this.handleOnServerStatusChange);

}

render(): React.ReactNode {
Expand Down Expand Up @@ -64,8 +64,8 @@ export class TraceExplorerPlaceholderWidget extends ReactWidget {
this.update();
await this.commandService.executeCommand(StartServerCommand.id);
this.state.loading = false;
const status = await this.traceServerConnectionStatusProxy.getStatus();
this.handleOnServerStatusChange(status);
// const status = await this.traceServerConnectionStatusProxy.getStatus();
// this.handleOnServerStatusChange(status);
}

protected handleOnServerStatusChange = (status: boolean): void => this.doHandleOnServerStatusChange(status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { CommandService } from '@theia/core';
export class TraceExplorerServerStatusWidget extends ReactWidget {
static ID = 'trace-explorer-server-status-widget';
static LABEL = 'Trace Explorer Server Status Widget';
private serverOn = false;

@inject(CommandService) protected readonly commandService!: CommandService;

Expand All @@ -17,17 +18,37 @@ export class TraceExplorerServerStatusWidget extends ReactWidget {
this.update();
}

public updateStatus = (status: boolean): void => {
this.serverOn = status;
this.update();
};

render(): React.ReactNode {
return (
<div className="server-status-header">
<span className="theia-header">Server Status </span>
<i
id="server-status-id"
className="fa fa-times-circle-o fa-lg"
title="Trace Viewer Critical Error: Trace Server Offline"
style={{ color: 'red', marginLeft: '5px' }}
/>
</div>
);

if (this.serverOn) {
return (
<div className="server-status-header">
<span className="theia-header">Server Status </span>
<i
id="server-status-id"
className="'fa fa-check-circle-o fa-lg'"
title="Server health and latency are good. No known issues"
style={{ color: 'green', marginLeft: '5px' }}
/>
</div>
);
} else {
return (
<div className="server-status-header">
<span className="theia-header">Server Status </span>
<i
id="server-status-id"
className="fa fa-times-circle-o fa-lg"
title="Trace Viewer Critical Error: Trace Server Offline"
style={{ color: 'red', marginLeft: '5px' }}
/>
</div>
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,14 @@ export class TraceExplorerWidget extends BaseWidget {
layout.addWidget(this.traceViewsContainer);
this.node.tabIndex = 0;
signalManager().on(Signals.OPENED_TRACES_UPDATED, this.onUpdateSignal);
this.connectionStatusClient.addServerStatusChangeListener(this.onServerStatusChange);
this.update();
}

dispose(): void {
super.dispose();
signalManager().off(Signals.OPENED_TRACES_UPDATED, this.onUpdateSignal);
this.connectionStatusClient.removeServerStatusChangeListener(this.onServerStatusChange);
}

protected onUpdateSignal = (payload: OpenedTracesUpdatedSignalPayload): void =>
Expand All @@ -100,6 +102,13 @@ export class TraceExplorerWidget extends BaseWidget {

protected onUpdateRequest(msg: Message): void {
super.onUpdateRequest(msg);

if (this.connectionStatusClient.status === false) {
this.traceViewsContainer.hide();
this.placeholderWidget.show();
return;
}

if (this._numberOfOpenedTraces > 0) {
this.traceViewsContainer.show();
this.placeholderWidget.hide();
Expand All @@ -115,12 +124,25 @@ export class TraceExplorerWidget extends BaseWidget {
}

protected async onAfterShow(): Promise<void> {
this.connectionStatusClient.addConnectionStatusListener();
this.connectionStatusClient.subscribe();
const status = await this.traceServerConnectionStatusProxy.getStatus();
this.connectionStatusClient.updateStatus(status);
}

protected onAfterHide(): void {
this.connectionStatusClient.removeConnectionStatusListener();
this.connectionStatusClient.unsubscribe();
}

protected onServerStatusChange = (status: boolean): void => this.doHandleOnServerStatusChange(status);
protected doHandleOnServerStatusChange(status: boolean): void {
alert(`server status is: ${status}`);
this.serverStatusWidget.updateStatus(status);
if (status === true) {
this.placeholderWidget.hide();
} else {
this.placeholderWidget.show();
}
this.update();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,47 @@
import { injectable } from 'inversify';
import { TraceServerConnectionStatusClient } from '../common/trace-server-connection-status';

type Listener = (serverStatus: boolean) => void;
@injectable()
export class TraceServerConnectionStatusClientImpl implements TraceServerConnectionStatusClient {
protected active = false;
protected _status = false;
protected listeners: Listener[] = [];

updateStatus(status: boolean): void {
this._status = status;
if (this.active) {
TraceServerConnectionStatusClientImpl.renderStatus(status);
// TraceServerConnectionStatusClientImpl.renderStatus(status);
this.listeners.forEach(fn => {
fn(status);
console.dir(fn);
});
}
}

addConnectionStatusListener(): void {
subscribe(): void {
this.active = true;
}

removeConnectionStatusListener(): void {
unsubscribe(): void {
this.active = false;
}

addServerStatusChangeListener(fn: Listener): void {
this.listeners.push(fn);
}

removeServerStatusChangeListener(fn: Listener): void {
const index = this.listeners.indexOf(fn);
if (index) {
this.listeners.splice(index, 1);
}
}

get status(): boolean {
return this._status;
}

static renderStatus(status: boolean): void {
if (document.getElementById('server-status-id')) {
document.getElementById('server-status-id')!.className = status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import { TracePreferences, TRACE_PATH, TRACE_ARGS } from '../trace-server-prefer
import { TspClientProvider } from '../tsp-client-provider-impl';
import { ChartShortcutsDialog } from '../trace-explorer/trace-explorer-sub-widgets/charts-cheatsheet-component';
import { signalManager } from 'traceviewer-base/lib/signals/signal-manager';
import { TraceServerConnectionStatusClientImpl } from '../trace-server-connection-status-client-impl';
import { FileStat } from '@theia/filesystem/lib/common/files';
import { ITspClient } from 'tsp-typescript-client';
import { TraceServerConnectionStatusClient } from '../../common/trace-server-connection-status';

interface TraceViewerWidgetOpenerOptions extends WidgetOpenerOptions {
traceUUID: string;
Expand All @@ -50,6 +50,7 @@ export class TraceViewerContribution
@inject(TracePreferences) protected tracePreferences: TracePreferences;
@inject(TraceServerConfigService) protected readonly traceServerConfigService: TraceServerConfigService;
@inject(MessageService) protected readonly messageService: MessageService;
@inject(TraceServerConnectionStatusClient) protected readonly serverStatusService: TraceServerConnectionStatusClient;

readonly id = TraceViewerWidget.ID;
readonly label = 'Trace Viewer';
Expand Down Expand Up @@ -94,7 +95,7 @@ export class TraceViewerContribution
progress.report({ message: 'Trace server started.', work: { done: 100, total: 100 } });
}
progress.cancel();
TraceServerConnectionStatusClientImpl.renderStatus(true);
this.serverStatusService.updateStatus(true);
signalManager().fireTraceServerStartedSignal();
this.openDialog(rootPath);
}
Expand Down Expand Up @@ -163,7 +164,7 @@ export class TraceViewerContribution
} else {
progress.report({ message: 'Trace server started.', work: { done: 100, total: 100 } });
}
TraceServerConnectionStatusClientImpl.renderStatus(true);
this.serverStatusService.updateStatus(true);
signalManager().fireTraceServerStartedSignal();
return super.open(traceURI, options);
}
Expand Down Expand Up @@ -230,7 +231,7 @@ export class TraceViewerContribution
} else {
progress.report({ message: 'Trace server started.', work: { done: 100, total: 100 } });
}
TraceServerConnectionStatusClientImpl.renderStatus(true);
this.serverStatusService.updateStatus(true);
signalManager().fireTraceServerStartedSignal();
return;
}
Expand Down Expand Up @@ -261,7 +262,7 @@ export class TraceViewerContribution
try {
await this.traceServerConfigService.stopTraceServer();
this.messageService.info('Trace server terminated successfully.');
TraceServerConnectionStatusClientImpl.renderStatus(false);
this.serverStatusService.updateStatus(false);
} catch (err) {
this.messageService.error('Failed to stop the trace server.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,23 @@ export interface TraceServerConnectionStatusClient {
/**
* Subscribe this client to the connection status
*/
addConnectionStatusListener(): void;
subscribe(): void;
/**
* Unsubscribe this client from the connection status
*/
removeConnectionStatusListener(): void;
unsubscribe(): void;

/**
* Adds event listener for server status change
* @param fn event listener
*/
addServerStatusChangeListener(fn: (status: boolean) => void): void;

/**
* Removes event listener for server status change.
* @param fn event listener to be removed
*/
removeServerStatusChangeListener(fn: (status: boolean) => void): void;

status: boolean;
}

0 comments on commit 05cdf04

Please sign in to comment.