From 006230262c28fcd59aee5c23b7915e46e732fdaf Mon Sep 17 00:00:00 2001 From: Steve Faulkner Date: Thu, 10 Jun 2021 16:16:43 -0700 Subject: [PATCH] Remvoe Explorer.isServerlessEnabled (#883) --- .../SettingsComponent.test.tsx.snap | 4 ---- src/Explorer/Explorer.tsx | 8 -------- .../CommandBarComponentButtonFactory.test.ts | 18 +++++++++--------- .../CommandBarComponentButtonFactory.tsx | 3 ++- .../CassandraAddCollectionPane.tsx | 5 +++-- .../GitHubReposPanel.test.tsx.snap | 1 - .../StringInputPane.test.tsx.snap | 1 - ...leteDatabaseConfirmationPanel.test.tsx.snap | 1 - src/Explorer/Tree/Collection.ts | 3 ++- src/Explorer/Tree/Database.ts | 3 ++- src/Explorer/Tree/ResourceTreeAdapter.tsx | 5 +++-- 11 files changed, 21 insertions(+), 31 deletions(-) diff --git a/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap b/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap index 18c2e4c7c..fb1761d1e 100644 --- a/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap +++ b/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap @@ -39,7 +39,6 @@ exports[`SettingsComponent renders 1`] = ` "isNotebooksEnabledForAccount": [Function], "isResourceTokenCollectionNodeSelected": [Function], "isSchemaEnabled": [Function], - "isServerlessEnabled": [Function], "isShellEnabled": [Function], "isSynapseLinkUpdating": [Function], "isTabsContentExpanded": [Function], @@ -108,7 +107,6 @@ exports[`SettingsComponent renders 1`] = ` "isNotebooksEnabledForAccount": [Function], "isResourceTokenCollectionNodeSelected": [Function], "isSchemaEnabled": [Function], - "isServerlessEnabled": [Function], "isShellEnabled": [Function], "isSynapseLinkUpdating": [Function], "isTabsContentExpanded": [Function], @@ -190,7 +188,6 @@ exports[`SettingsComponent renders 1`] = ` "isNotebooksEnabledForAccount": [Function], "isResourceTokenCollectionNodeSelected": [Function], "isSchemaEnabled": [Function], - "isServerlessEnabled": [Function], "isShellEnabled": [Function], "isSynapseLinkUpdating": [Function], "isTabsContentExpanded": [Function], @@ -259,7 +256,6 @@ exports[`SettingsComponent renders 1`] = ` "isNotebooksEnabledForAccount": [Function], "isResourceTokenCollectionNodeSelected": [Function], "isSchemaEnabled": [Function], - "isServerlessEnabled": [Function], "isShellEnabled": [Function], "isSynapseLinkUpdating": [Function], "isTabsContentExpanded": [Function], diff --git a/src/Explorer/Explorer.tsx b/src/Explorer/Explorer.tsx index b9d06287d..3119bce96 100644 --- a/src/Explorer/Explorer.tsx +++ b/src/Explorer/Explorer.tsx @@ -86,7 +86,6 @@ export interface ExplorerParams { export default class Explorer { public isFixedCollectionWithSharedThroughputSupported: ko.Computed; - public isServerlessEnabled: ko.Computed; public isAccountReady: ko.Observable; public canSaveQueries: ko.Computed; public queriesClient: QueriesClient; @@ -230,13 +229,6 @@ export default class Explorer { return isCapabilityEnabled("EnableMongo"); }); - this.isServerlessEnabled = ko.computed( - () => - userContext.databaseAccount?.properties?.capabilities?.find( - (item) => item.name === Constants.CapabilityNames.EnableServerless - ) !== undefined - ); - this.isHostedDataExplorerEnabled = ko.computed( () => configContext.platform === Platform.Portal && diff --git a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.test.ts b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.test.ts index 5af290993..824aebdb8 100644 --- a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.test.ts +++ b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.test.ts @@ -31,8 +31,6 @@ describe("CommandBarComponentButtonFactory tests", () => { }); 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 @@ -41,8 +39,13 @@ describe("CommandBarComponentButtonFactory tests", () => { }); it("Account is serverless - button should be hidden", () => { - mockExplorer.isServerlessEnabled = ko.computed(() => true); - + updateUserContext({ + databaseAccount: { + properties: { + capabilities: [{ name: "EnableServerless" }], + }, + } as DatabaseAccount, + }); const buttons = CommandBarComponentButtonFactory.createStaticCommandBarButtons(mockExplorer); const enableAzureSynapseLinkBtn = buttons.find( (button) => button.commandButtonLabel === enableAzureSynapseLinkBtnLabel @@ -67,7 +70,6 @@ describe("CommandBarComponentButtonFactory tests", () => { mockExplorer.isSynapseLinkUpdating = ko.observable(false); mockExplorer.isDatabaseNodeOrNoneSelected = () => true; - mockExplorer.isServerlessEnabled = ko.computed(() => false); }); it("Notebooks is already enabled - button should be hidden", () => { @@ -132,7 +134,7 @@ describe("CommandBarComponentButtonFactory tests", () => { mockExplorer.isSynapseLinkUpdating = ko.observable(false); mockExplorer.isDatabaseNodeOrNoneSelected = () => true; - mockExplorer.isServerlessEnabled = ko.computed(() => false); + mockExplorer.isShellEnabled = ko.observable(true); }); @@ -230,7 +232,6 @@ describe("CommandBarComponentButtonFactory tests", () => { mockExplorer.isSynapseLinkUpdating = ko.observable(false); mockExplorer.isDatabaseNodeOrNoneSelected = () => true; - mockExplorer.isServerlessEnabled = ko.computed(() => false); }); beforeEach(() => { @@ -324,7 +325,6 @@ describe("CommandBarComponentButtonFactory tests", () => { mockExplorer.isRunningOnNationalCloud = ko.observable(false); mockExplorer.notebookManager = new NotebookManager(); mockExplorer.notebookManager.gitHubOAuthService = new GitHubOAuthService(undefined); - mockExplorer.isServerlessEnabled = ko.computed(() => false); }); beforeEach(() => { @@ -372,7 +372,7 @@ describe("CommandBarComponentButtonFactory tests", () => { mockExplorer = {} as Explorer; mockExplorer.isDatabaseNodeOrNoneSelected = () => true; mockExplorer.isResourceTokenCollectionNodeSelected = ko.computed(() => true); - mockExplorer.isServerlessEnabled = ko.computed(() => false); + updateUserContext({ authType: AuthType.ResourceToken, }); diff --git a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.tsx b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.tsx index 2545b6ff7..1ee629b49 100644 --- a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.tsx +++ b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.tsx @@ -24,6 +24,7 @@ import * as ViewModels from "../../../Contracts/ViewModels"; import { useSidePanel } from "../../../hooks/useSidePanel"; import { userContext } from "../../../UserContext"; import { getCollectionName, getDatabaseName } from "../../../Utils/APITypeUtils"; +import { isServerlessAccount } from "../../../Utils/CapabilityUtils"; import { CommandButtonComponentProps } from "../../Controls/CommandButton/CommandButtonComponent"; import Explorer from "../../Explorer"; import { OpenFullScreen } from "../../OpenFullScreen"; @@ -235,7 +236,7 @@ function createOpenSynapseLinkDialogButton(container: Explorer): CommandButtonCo return undefined; } - if (container.isServerlessEnabled()) { + if (isServerlessAccount()) { return undefined; } diff --git a/src/Explorer/Panes/CassandraAddCollectionPane/CassandraAddCollectionPane.tsx b/src/Explorer/Panes/CassandraAddCollectionPane/CassandraAddCollectionPane.tsx index bef852942..48d846632 100644 --- a/src/Explorer/Panes/CassandraAddCollectionPane/CassandraAddCollectionPane.tsx +++ b/src/Explorer/Panes/CassandraAddCollectionPane/CassandraAddCollectionPane.tsx @@ -13,6 +13,7 @@ import { Action, ActionModifiers } from "../../../Shared/Telemetry/TelemetryCons import * as TelemetryProcessor from "../../../Shared/Telemetry/TelemetryProcessor"; import { userContext } from "../../../UserContext"; import * as AutoPilotUtils from "../../../Utils/AutoPilotUtils"; +import { isServerlessAccount } from "../../../Utils/CapabilityUtils"; import { ThroughputInput } from "../../Controls/ThroughputInput/ThroughputInput"; import Explorer from "../../Explorer"; import { CassandraAPIDataClient } from "../../Tables/TableDataClient"; @@ -75,7 +76,7 @@ export const CassandraAddCollectionPane: FunctionComponent(); @@ -107,7 +108,7 @@ export const CassandraAddCollectionPane: FunctionComponent { - if (!container.isServerlessEnabled()) { + if (!isServerlessAccount()) { setIsAutoPilotSelected(userContext.features.autoscaleDefault); } diff --git a/src/Explorer/Panes/GitHubReposPanel/__snapshots__/GitHubReposPanel.test.tsx.snap b/src/Explorer/Panes/GitHubReposPanel/__snapshots__/GitHubReposPanel.test.tsx.snap index d1ff91907..8d6d78c14 100644 --- a/src/Explorer/Panes/GitHubReposPanel/__snapshots__/GitHubReposPanel.test.tsx.snap +++ b/src/Explorer/Panes/GitHubReposPanel/__snapshots__/GitHubReposPanel.test.tsx.snap @@ -28,7 +28,6 @@ exports[`GitHub Repos Panel should render Default properly 1`] = ` "isNotebooksEnabledForAccount": [Function], "isResourceTokenCollectionNodeSelected": [Function], "isSchemaEnabled": [Function], - "isServerlessEnabled": [Function], "isShellEnabled": [Function], "isSynapseLinkUpdating": [Function], "isTabsContentExpanded": [Function], diff --git a/src/Explorer/Panes/StringInputPane/__snapshots__/StringInputPane.test.tsx.snap b/src/Explorer/Panes/StringInputPane/__snapshots__/StringInputPane.test.tsx.snap index c619b8cfb..090e3a56e 100644 --- a/src/Explorer/Panes/StringInputPane/__snapshots__/StringInputPane.test.tsx.snap +++ b/src/Explorer/Panes/StringInputPane/__snapshots__/StringInputPane.test.tsx.snap @@ -18,7 +18,6 @@ exports[`StringInput Pane should render Create new directory properly 1`] = ` "isNotebooksEnabledForAccount": [Function], "isResourceTokenCollectionNodeSelected": [Function], "isSchemaEnabled": [Function], - "isServerlessEnabled": [Function], "isShellEnabled": [Function], "isSynapseLinkUpdating": [Function], "isTabsContentExpanded": [Function], diff --git a/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap b/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap index 4975db9a9..ab19afbce 100644 --- a/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap +++ b/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap @@ -19,7 +19,6 @@ exports[`Delete Database Confirmation Pane submit() Should call delete database "isResourceTokenCollectionNodeSelected": [Function], "isSchemaEnabled": [Function], "isSelectedDatabaseShared": [Function], - "isServerlessEnabled": [Function], "isShellEnabled": [Function], "isSynapseLinkUpdating": [Function], "isTabsContentExpanded": [Function], diff --git a/src/Explorer/Tree/Collection.ts b/src/Explorer/Tree/Collection.ts index ac3cc06ca..1731e18c6 100644 --- a/src/Explorer/Tree/Collection.ts +++ b/src/Explorer/Tree/Collection.ts @@ -19,6 +19,7 @@ import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstan import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; import { userContext } from "../../UserContext"; import { SqlTriggerResource } from "../../Utils/arm/generatedClients/cosmos/types"; +import { isServerlessAccount } from "../../Utils/CapabilityUtils"; import { logConsoleInfo } from "../../Utils/NotificationConsoleUtils"; import Explorer from "../Explorer"; import { useCommandBar } from "../Menus/CommandBar/CommandBarComponentAdapter"; @@ -1147,7 +1148,7 @@ export default class Collection implements ViewModels.Collection { } public async loadOffer(): Promise { - if (!this.isOfferRead && !this.container.isServerlessEnabled() && !this.offer()) { + if (!this.isOfferRead && !isServerlessAccount() && !this.offer()) { const startKey: number = TelemetryProcessor.traceStart(Action.LoadOffers, { databaseName: this.databaseId, collectionName: this.id(), diff --git a/src/Explorer/Tree/Database.ts b/src/Explorer/Tree/Database.ts index 1730b48a3..8c926cd56 100644 --- a/src/Explorer/Tree/Database.ts +++ b/src/Explorer/Tree/Database.ts @@ -13,6 +13,7 @@ import { IJunoResponse, JunoClient } from "../../Juno/JunoClient"; import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants"; import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; import { userContext } from "../../UserContext"; +import { isServerlessAccount } from "../../Utils/CapabilityUtils"; import { logConsoleError } from "../../Utils/NotificationConsoleUtils"; import Explorer from "../Explorer"; import { DatabaseSettingsTabV2 } from "../Tabs/SettingsTabV2"; @@ -215,7 +216,7 @@ export default class Database implements ViewModels.Database { } public async loadOffer(): Promise { - if (!this.isOfferRead && !this.container.isServerlessEnabled() && !this.offer()) { + if (!this.isOfferRead && !isServerlessAccount() && !this.offer()) { const params: DataModels.ReadDatabaseOfferParams = { databaseId: this.id(), databaseResourceId: this.self, diff --git a/src/Explorer/Tree/ResourceTreeAdapter.tsx b/src/Explorer/Tree/ResourceTreeAdapter.tsx index 7a8633209..61620d85a 100644 --- a/src/Explorer/Tree/ResourceTreeAdapter.tsx +++ b/src/Explorer/Tree/ResourceTreeAdapter.tsx @@ -22,6 +22,7 @@ import { LocalStorageUtility, StorageKey } from "../../Shared/StorageUtility"; import { Action, ActionModifiers, Source } from "../../Shared/Telemetry/TelemetryConstants"; import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; import { userContext } from "../../UserContext"; +import { isServerlessAccount } from "../../Utils/CapabilityUtils"; import * as GitHubUtils from "../../Utils/GitHubUtils"; import { ResourceTreeContextMenuButtonFactory } from "../ContextMenuButtonFactory"; import { AccordionComponent, AccordionItemComponent } from "../Controls/Accordion/AccordionComponent"; @@ -286,9 +287,9 @@ export class ResourceTreeAdapter implements ReactAdapter { }); } - if (userContext.apiType !== "Cassandra" || !this.container.isServerlessEnabled()) { + if (userContext.apiType !== "Cassandra" || !isServerlessAccount()) { children.push({ - label: database.isDatabaseShared() || this.container.isServerlessEnabled() ? "Settings" : "Scale & Settings", + label: database.isDatabaseShared() || isServerlessAccount() ? "Settings" : "Scale & Settings", onClick: collection.onSettingsClick.bind(collection), isSelected: () => this.isDataNodeSelected(collection.databaseId, collection.id(), [ViewModels.CollectionTabKind.Settings]),