Skip to content

Commit

Permalink
small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
williamsyang-work committed Feb 20, 2024
1 parent 0a4f424 commit b0376b6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export class TraceExplorerPlaceholderWidget extends ReactWidget {

state = {
loading: false,
serverStatus: false
serverStatus: false,
tracesOpened: false
};

@inject(CommandService) protected readonly commandService!: CommandService;
Expand All @@ -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 (
<ReactExplorerPlaceholderWidget
tracesOpen={false} // If we can see this component, there are no opened traces.
tracesOpen={tracesOpened}
serverOn={serverStatus}
handleStartServer={this.handleStartServer}
loading={loading}
Expand Down Expand Up @@ -66,10 +65,8 @@ export class TraceExplorerPlaceholderWidget extends ReactWidget {
this.update();
}

protected handleOnServerStatusChange = (status: boolean): void => 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand All @@ -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();
}
}
}

0 comments on commit b0376b6

Please sign in to comment.