From 03ea265bab6e10ec63566813808e0e524965caca Mon Sep 17 00:00:00 2001 From: Anthony Dresser Date: Tue, 18 Sep 2018 17:56:37 -0700 Subject: [PATCH] Hide tabs on reexecute (#2624) * add logic to hide tabs when a query rerun is executed * remove double entry in the map --- src/sql/base/browser/ui/panel/panel.ts | 23 +++++++++++++++++++ src/sql/parts/query/editor/actions.ts | 1 - .../parts/query/editor/queryResultsView.ts | 23 +++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/sql/base/browser/ui/panel/panel.ts b/src/sql/base/browser/ui/panel/panel.ts index d997547390..73d8af93fc 100644 --- a/src/sql/base/browser/ui/panel/panel.ts +++ b/src/sql/base/browser/ui/panel/panel.ts @@ -61,6 +61,8 @@ export class TabbedPanel extends Disposable implements IThemable { private _onTabChange = new Emitter(); public onTabChange: Event = this._onTabChange.event; + private tabHistory: string[] = []; + constructor(private container: HTMLElement, private options: IPanelOptions = defaultOptions) { super(); this.$parent = this._register($('.tabbedPanel')); @@ -152,6 +154,7 @@ export class TabbedPanel extends Disposable implements IThemable { } this._shownTab = id; + this.tabHistory.push(id); this.$body.clearChildren(); let tab = this._tabMap.get(this._shownTab); this.$body.attr('aria-labelledby', tab.identifier); @@ -173,6 +176,26 @@ export class TabbedPanel extends Disposable implements IThemable { } this._tabMap.get(tab).header.destroy(); this._tabMap.delete(tab); + if (this._shownTab === tab) { + this._shownTab = undefined; + while (this._shownTab === undefined && this.tabHistory.length > 0) { + let lastTab = this.tabHistory.shift(); + if (this._tabMap.get(lastTab)) { + this.showTab(lastTab); + } + } + + // this shouldn't happen but just in case + if (this._shownTab === undefined && this._tabMap.size > 0) { + this.showTab(this._tabMap.keys().next().value); + } + } + + if (!this.options.showHeaderWhenSingleView && this._tabMap.size === 1 && this._headerVisible) { + this.$header.offDOM(); + this._headerVisible = false; + this.layout(this._currentDimensions); + } } public style(styles: IPanelStyles): void { diff --git a/src/sql/parts/query/editor/actions.ts b/src/sql/parts/query/editor/actions.ts index ac8ba1fdaa..0db77835e9 100644 --- a/src/sql/parts/query/editor/actions.ts +++ b/src/sql/parts/query/editor/actions.ts @@ -223,5 +223,4 @@ export class ShowQueryPlanAction extends Action { return TPromise.as(false); } } - } diff --git a/src/sql/parts/query/editor/queryResultsView.ts b/src/sql/parts/query/editor/queryResultsView.ts index 53bcfbb14c..942846cd20 100644 --- a/src/sql/parts/query/editor/queryResultsView.ts +++ b/src/sql/parts/query/editor/queryResultsView.ts @@ -18,6 +18,7 @@ import { PanelViewlet } from 'vs/workbench/browser/parts/views/panelViewlet'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import * as DOM from 'vs/base/browser/dom'; import { once, anyEvent } from 'vs/base/common/event'; +import { IDisposable, dispose } from 'vs/base/common/lifecycle'; class ResultsView implements IPanelView { private panelViewlet: PanelViewlet; @@ -155,6 +156,8 @@ export class QueryResultsView { private chartTab: ChartTab; private qpTab: QueryPlanTab; + private runnerDisposables: IDisposable[]; + constructor( container: HTMLElement, @IInstantiationService instantiationService: IInstantiationService, @@ -177,12 +180,20 @@ export class QueryResultsView { public set input(input: QueryResultsInput) { this._input = input; + dispose(this.runnerDisposables); + this.runnerDisposables = []; this.resultsTab.view.state = this.input.state; this.qpTab.view.state = this.input.state.queryPlanState; this.chartTab.view.state = this.input.state.chartState; let queryRunner = this.queryModelService._getQueryInfo(input.uri).queryRunner; this.resultsTab.queryRunner = queryRunner; this.chartTab.queryRunner = queryRunner; + this.runnerDisposables.push(queryRunner.onQueryStart(e => { + this.hideChart(); + this.hidePlan(); + this.input.state.visibleTabs = new Set(); + this.input.state.activeTab = this.resultsTab.identifier; + })); if (this.input.state.visibleTabs.has(this.chartTab.identifier)) { if (!this._panelView.contains(this.chartTab)) { this._panelView.pushTab(this.chartTab); @@ -220,6 +231,12 @@ export class QueryResultsView { this.chartTab.chart(dataId); } + public hideChart() { + if (this._panelView.contains(this.chartTab)) { + this._panelView.removeTab(this.chartTab.identifier); + } + } + public showPlan(xml: string) { this.input.state.visibleTabs.add(this.qpTab.identifier); if (!this._panelView.contains(this.qpTab)) { @@ -229,4 +246,10 @@ export class QueryResultsView { this._panelView.showTab(this.qpTab.identifier); this.qpTab.view.showPlan(xml); } + + public hidePlan() { + if (this._panelView.contains(this.qpTab)) { + this._panelView.removeTab(this.qpTab.identifier); + } + } }