From 8c792fd147884f9aef4b267d3534613adf8ccb60 Mon Sep 17 00:00:00 2001 From: Tanuj Mittal Date: Fri, 31 Jul 2020 15:31:21 -0700 Subject: [PATCH] Hide Azure Synapse Link button for Serverless accounts (#121) --- .../CommandBar/CommandBarComponentAdapter.tsx | 3 +- .../CommandBarComponentButtonFactory.test.ts | 46 +++++++++++++++++++ .../CommandBarComponentButtonFactory.ts | 5 ++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/Explorer/Menus/CommandBar/CommandBarComponentAdapter.tsx b/src/Explorer/Menus/CommandBar/CommandBarComponentAdapter.tsx index 463de1281..9ad9b482b 100644 --- a/src/Explorer/Menus/CommandBar/CommandBarComponentAdapter.tsx +++ b/src/Explorer/Menus/CommandBar/CommandBarComponentAdapter.tsx @@ -45,7 +45,8 @@ export class CommandBarComponentAdapter implements ReactAdapter { container.isHostedDataExplorerEnabled, container.isSynapseLinkUpdating, container.databaseAccount, - this.isNotebookTabActive + this.isNotebookTabActive, + container.isServerlessEnabled ]; ko.computed(() => ko.toJSON(toWatch)).subscribe(() => this.triggerRender()); diff --git a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.test.ts b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.test.ts index 8a7f94d1d..61b853a0a 100644 --- a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.test.ts +++ b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.test.ts @@ -7,6 +7,47 @@ import Explorer from "../../Explorer"; describe("CommandBarComponentButtonFactory tests", () => { let mockExplorer: Explorer; + describe("Enable Azure Synapse Link Button", () => { + const enableAzureSynapseLinkBtnLabel = "Enable Azure Synapse Link (Preview)"; + + beforeAll(() => { + mockExplorer = {} as Explorer; + mockExplorer.addCollectionText = ko.observable("mockText"); + mockExplorer.isAuthWithResourceToken = ko.observable(false); + mockExplorer.isPreferredApiTable = ko.computed(() => true); + mockExplorer.isPreferredApiMongoDB = ko.computed(() => false); + mockExplorer.isPreferredApiCassandra = ko.computed(() => false); + mockExplorer.isSparkEnabled = ko.observable(true); + mockExplorer.isSynapseLinkUpdating = ko.observable(false); + mockExplorer.isGalleryPublishEnabled = ko.computed(() => false); + mockExplorer.hasAutoPilotV2FeatureFlag = ko.computed(() => true); + mockExplorer.isDatabaseNodeOrNoneSelected = () => true; + mockExplorer.isNotebookEnabled = ko.observable(false); + mockExplorer.isNotebooksEnabledForAccount = ko.observable(false); + mockExplorer.isRunningOnNationalCloud = () => false; + }); + + it("Account is not serverless - button should be visible", () => { + mockExplorer.isServerlessEnabled = ko.computed(() => false); + + const buttons = CommandBarComponentButtonFactory.createStaticCommandBarButtons(mockExplorer); + const enableAzureSynapseLinkBtn = buttons.find( + button => button.commandButtonLabel === enableAzureSynapseLinkBtnLabel + ); + expect(enableAzureSynapseLinkBtn).toBeDefined(); + }); + + it("Account is serverless - button should be hidden", () => { + mockExplorer.isServerlessEnabled = ko.computed(() => true); + + const buttons = CommandBarComponentButtonFactory.createStaticCommandBarButtons(mockExplorer); + const enableAzureSynapseLinkBtn = buttons.find( + button => button.commandButtonLabel === enableAzureSynapseLinkBtnLabel + ); + expect(enableAzureSynapseLinkBtn).toBeUndefined(); + }); + }); + describe("Enable notebook button", () => { const enableNotebookBtnLabel = "Enable Notebooks (Preview)"; @@ -23,6 +64,7 @@ describe("CommandBarComponentButtonFactory tests", () => { mockExplorer.isGalleryPublishEnabled = ko.computed(() => false); mockExplorer.hasAutoPilotV2FeatureFlag = ko.computed(() => true); mockExplorer.isDatabaseNodeOrNoneSelected = () => true; + mockExplorer.isServerlessEnabled = ko.computed(() => false); }); it("Notebooks is already enabled - button should be hidden", () => { @@ -86,6 +128,7 @@ describe("CommandBarComponentButtonFactory tests", () => { mockExplorer.isGalleryPublishEnabled = ko.computed(() => false); mockExplorer.hasAutoPilotV2FeatureFlag = ko.computed(() => true); mockExplorer.isDatabaseNodeOrNoneSelected = () => true; + mockExplorer.isServerlessEnabled = ko.computed(() => false); }); beforeEach(() => { @@ -167,6 +210,7 @@ describe("CommandBarComponentButtonFactory tests", () => { mockExplorer.isGalleryPublishEnabled = ko.computed(() => false); mockExplorer.hasAutoPilotV2FeatureFlag = ko.computed(() => true); mockExplorer.isDatabaseNodeOrNoneSelected = () => true; + mockExplorer.isServerlessEnabled = ko.computed(() => false); }); beforeEach(() => { @@ -254,6 +298,7 @@ describe("CommandBarComponentButtonFactory tests", () => { mockExplorer.isGalleryPublishEnabled = ko.computed(() => false); mockExplorer.notebookManager = new NotebookManager(); mockExplorer.notebookManager.gitHubOAuthService = new GitHubOAuthService(undefined); + mockExplorer.isServerlessEnabled = ko.computed(() => false); }); beforeEach(() => { @@ -305,6 +350,7 @@ describe("CommandBarComponentButtonFactory tests", () => { mockExplorer.isDatabaseNodeOrNoneSelected = () => true; mockExplorer.hasAutoPilotV2FeatureFlag = ko.computed(() => true); mockExplorer.isResourceTokenCollectionNodeSelected = ko.computed(() => true); + mockExplorer.isServerlessEnabled = ko.computed(() => false); }); it("should only show New SQL Query and Open Query buttons", () => { diff --git a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.ts b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.ts index 67daef835..24322e73d 100644 --- a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.ts +++ b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.ts @@ -246,6 +246,11 @@ export class CommandBarComponentButtonFactory { if (config.platform === Platform.Emulator) { return null; } + + if (container.isServerlessEnabled()) { + return null; + } + if ( container.databaseAccount && container.databaseAccount() &&