From 07fb58d5e15dbcf6d54254c35ee235cc5efe1a72 Mon Sep 17 00:00:00 2001 From: Kevin Cunnane Date: Fri, 29 Jun 2018 18:49:56 -0700 Subject: [PATCH] Fixes #1804 Dashboard Home tab should be overrideable for other connection providers (#1805) - Adds new isHomeTab property. If set, this indicates a tab should override the default home tab. --- .../common/dashboardPage.component.ts | 99 +++++++++++-------- .../common/dashboardTab.contribution.ts | 11 ++- .../dashboard/common/dashboardRegistry.ts | 1 + 3 files changed, 67 insertions(+), 44 deletions(-) diff --git a/src/sql/parts/dashboard/common/dashboardPage.component.ts b/src/sql/parts/dashboard/common/dashboardPage.component.ts index dece1f01f5..1e092655b2 100644 --- a/src/sql/parts/dashboard/common/dashboardPage.component.ts +++ b/src/sql/parts/dashboard/common/dashboardPage.component.ts @@ -133,23 +133,11 @@ export abstract class DashboardPage extends AngularDisposable implements IConfig this._tabsDispose.forEach(i => i.dispose()); this._tabsDispose = []; - // Create home tab - let homeTab: TabConfig = { - id: 'homeTab', - provider: Constants.anyProviderName, - publisher: undefined, - title: this.homeTabTitle, - container: { 'widgets-container': homeWidgets }, - context: this.context, - originalConfig: this._originalConfig, - editable: true, - canClose: false, - actions: [] - }; - this.addNewTab(homeTab); - let allTabs = dashboardHelper.filterConfigs(dashboardRegistry.tabs, this); + // Before separating tabs into pinned / shown, ensure that the home tab is always set up as expected + allTabs = this.setAndRemoveHomeTab(allTabs, homeWidgets); + // Load tab setting configs this._tabSettingConfigs = this.dashboardService.getSettings>([this.context, 'tabs'].join('.')); @@ -196,6 +184,32 @@ export abstract class DashboardPage extends AngularDisposable implements IConfig })); } + private setAndRemoveHomeTab(allTabs: IDashboardTab[], homeWidgets: WidgetConfig[]): IDashboardTab[] { + let homeTabConfig: TabConfig = { + id: 'homeTab', + provider: Constants.anyProviderName, + publisher: undefined, + title: this.homeTabTitle, + container: { 'widgets-container': homeWidgets }, + context: this.context, + originalConfig: this._originalConfig, + editable: true, + canClose: false, + actions: [] + }; + + let homeTabIndex = allTabs.findIndex((tab) => tab.isHomeTab === true); + if (homeTabIndex !== undefined && homeTabIndex > -1) { + // Have a tab: get its information and copy over to the home tab definition + let homeTab = allTabs.splice(homeTabIndex, 1)[0]; + let tabConfig = this.initTabComponents(homeTab); + homeTabConfig.id = tabConfig.id; + homeTabConfig.container = tabConfig.container; + } + this.addNewTab(homeTabConfig); + return allTabs; + } + private rewriteConfig(): void { let writeableConfig = objects.deepClone(this._tabSettingConfigs); @@ -205,35 +219,12 @@ export abstract class DashboardPage extends AngularDisposable implements IConfig private loadNewTabs(dashboardTabs: IDashboardTab[], openLastTab: boolean = false) { if (dashboardTabs && dashboardTabs.length > 0) { - let selectedTabs = dashboardTabs.map(v => { - let containerResult = dashboardHelper.getDashboardContainer(v.container); - if (!containerResult.result) { - return { id: v.id, title: v.title, container: { 'error-container': undefined }, alwaysShow: v.alwaysShow }; - } - - let key = Object.keys(containerResult.container)[0]; - if (key === WIDGETS_CONTAINER || key === GRID_CONTAINER) { - let configs = Object.values(containerResult.container)[0]; - this._configModifiers.forEach(cb => { - configs = cb.apply(this, [configs, this, this.context]); - }); - this._gridModifiers.forEach(cb => { - configs = cb.apply(this, [configs]); - }); - if (key === WIDGETS_CONTAINER) { - return { id: v.id, title: v.title, container: { 'widgets-container': configs }, alwaysShow: v.alwaysShow }; - - } else { - return { id: v.id, title: v.title, container: { 'grid-container': configs }, alwaysShow: v.alwaysShow }; - } - } - return { id: v.id, title: v.title, container: containerResult.container, alwaysShow: v.alwaysShow }; - }).map(v => { + let selectedTabs = dashboardTabs.map(v => this.initTabComponents(v)).map(v => { let actions = []; - let tabConfig = this._tabSettingConfigs.find(i => i.tabId === v.id); + let tabSettingConfig = this._tabSettingConfigs.find(i => i.tabId === v.id); let isPinned = false; - if (tabConfig) { - isPinned = tabConfig.isPinned; + if (tabSettingConfig) { + isPinned = tabSettingConfig.isPinned; } else if (v.alwaysShow) { isPinned = true; } @@ -258,6 +249,30 @@ export abstract class DashboardPage extends AngularDisposable implements IConfig } } + private initTabComponents(value: IDashboardTab): { id: string; title: string; container: object; alwaysShow: boolean; } { + let containerResult = dashboardHelper.getDashboardContainer(value.container); + if (!containerResult.result) { + return { id: value.id, title: value.title, container: { 'error-container': undefined }, alwaysShow: value.alwaysShow }; + } + let key = Object.keys(containerResult.container)[0]; + if (key === WIDGETS_CONTAINER || key === GRID_CONTAINER) { + let configs = Object.values(containerResult.container)[0]; + this._configModifiers.forEach(cb => { + configs = cb.apply(this, [configs, this, this.context]); + }); + this._gridModifiers.forEach(cb => { + configs = cb.apply(this, [configs]); + }); + if (key === WIDGETS_CONTAINER) { + return { id: value.id, title: value.title, container: { 'widgets-container': configs }, alwaysShow: value.alwaysShow }; + } + else { + return { id: value.id, title: value.title, container: { 'grid-container': configs }, alwaysShow: value.alwaysShow }; + } + } + return { id: value.id, title: value.title, container: containerResult.container, alwaysShow: value.alwaysShow }; + } + private getContentType(tab: TabConfig): string { return tab.container ? Object.keys(tab.container)[0] : ''; } diff --git a/src/sql/parts/dashboard/common/dashboardTab.contribution.ts b/src/sql/parts/dashboard/common/dashboardTab.contribution.ts index 64ef8d2102..f9fe389dd7 100644 --- a/src/sql/parts/dashboard/common/dashboardTab.contribution.ts +++ b/src/sql/parts/dashboard/common/dashboardTab.contribution.ts @@ -22,6 +22,7 @@ export interface IDashboardTabContrib { when?: string; description?: string; alwaysShow?: boolean; + isHomeTab?: boolean; } const tabSchema: IJSONSchema = { @@ -56,6 +57,10 @@ const tabSchema: IJSONSchema = { alwaysShow: { description: localize('sqlops.extension.contributes.dashboard.tab.alwaysShow', "Whether or not this tab should always be shown or only when the user adds it."), type: 'boolean' + }, + isHomeTab: { + description: localize('sqlops.extension.contributes.dashboard.tab.isHomeTab', "Whether or not this tab should be used as the Home tab for a connection type."), + type: 'boolean' } } }; @@ -74,7 +79,7 @@ const tabContributionSchema: IJSONSchema = { ExtensionsRegistry.registerExtensionPoint('dashboard.tabs', [], tabContributionSchema).setHandler(extensions => { function handleCommand(tab: IDashboardTabContrib, extension: IExtensionPointUser) { - let { description, container, provider, title, when, id, alwaysShow } = tab; + let { description, container, provider, title, when, id, alwaysShow, isHomeTab } = tab; // If always show is not specified, set it to true by default. if (!types.isBoolean(alwaysShow)) { @@ -98,6 +103,8 @@ ExtensionsRegistry.registerExtensionPoint