From a52a15600513a0e3e8d5779f5337041962385448 Mon Sep 17 00:00:00 2001 From: Hardikkumar Nai <80053762+hardiknai-techm@users.noreply.github.com> Date: Fri, 14 May 2021 22:35:00 +0530 Subject: [PATCH] Remove Old Add Database Pane Code (#784) Co-authored-by: Steve Faulkner --- src/Explorer/ComponentRegisterer.ts | 2 - .../SettingsComponent.test.tsx.snap | 172 ------- src/Explorer/Explorer.tsx | 38 +- .../CommandBar/CommandBarComponentAdapter.tsx | 1 - .../CommandBarComponentButtonFactory.test.ts | 2 - .../CommandBarComponentButtonFactory.tsx | 3 +- src/Explorer/Panes/AddDatabasePane.html | 174 ------- src/Explorer/Panes/AddDatabasePane.test.ts | 105 ---- src/Explorer/Panes/AddDatabasePane.ts | 452 ------------------ .../GitHubReposPanel.test.tsx.snap | 43 -- src/Explorer/Panes/PaneComponents.ts | 10 - .../StringInputPane.test.tsx.snap | 43 -- ...eteDatabaseConfirmationPanel.test.tsx.snap | 43 -- src/Explorer/SplashScreen/SplashScreen.tsx | 3 +- src/Main.tsx | 1 - 15 files changed, 12 insertions(+), 1080 deletions(-) delete mode 100644 src/Explorer/Panes/AddDatabasePane.html delete mode 100644 src/Explorer/Panes/AddDatabasePane.test.ts delete mode 100644 src/Explorer/Panes/AddDatabasePane.ts diff --git a/src/Explorer/ComponentRegisterer.ts b/src/Explorer/ComponentRegisterer.ts index 4dc4c8923..9a49fd643 100644 --- a/src/Explorer/ComponentRegisterer.ts +++ b/src/Explorer/ComponentRegisterer.ts @@ -13,6 +13,4 @@ ko.components.register("dynamic-list", DynamicListComponent); ko.components.register("throughput-input-autopilot-v3", ThroughputInputComponentAutoPilotV3); // Panes - -ko.components.register("add-database-pane", new PaneComponents.AddDatabasePaneComponent()); ko.components.register("cassandra-add-collection-pane", new PaneComponents.CassandraAddCollectionPaneComponent()); diff --git a/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap b/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap index 6b841cdb8..7a23e0a3a 100644 --- a/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap +++ b/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap @@ -35,49 +35,6 @@ exports[`SettingsComponent renders 1`] = ` "_refreshSparkEnabledStateForAccount": [Function], "_resetNotebookWorkspace": [Function], "addCollectionText": [Function], - "addDatabasePane": AddDatabasePane { - "autoPilotUsageCost": [Function], - "canConfigureThroughput": [Function], - "canExceedMaximumValue": [Function], - "canRequestSupport": [Function], - "container": [Circular], - "costsVisible": [Function], - "databaseCreateNewShared": [Function], - "databaseId": [Function], - "databaseIdLabel": [Function], - "databaseIdPlaceHolder": [Function], - "databaseIdTooltipText": [Function], - "databaseLevelThroughputTooltipText": [Function], - "firstFieldHasFocus": [Function], - "formErrors": [Function], - "formErrorsDetails": [Function], - "freeTierExceedThroughputTooltip": [Function], - "id": "adddatabasepane", - "isAutoPilotSelected": [Function], - "isExecuting": [Function], - "isFreeTierAccount": [Function], - "isTemplateReady": [Function], - "maxAutoPilotThroughputSet": [Function], - "maxThroughputRU": [Function], - "maxThroughputRUText": [Function], - "minThroughputRU": [Function], - "onMoreDetailsKeyPress": [Function], - "requestUnitsUsageCost": [Function], - "ruToolTipText": [Function], - "showUpsellMessage": [Function], - "throughput": [Function], - "throughputRangeText": [Function], - "throughputSpendAck": [Function], - "throughputSpendAckText": [Function], - "throughputSpendAckVisible": [Function], - "title": [Function], - "upsellAnchorText": [Function], - "upsellAnchorUrl": [Function], - "upsellMessage": [Function], - "upsellMessageAriaLabel": [Function], - "visible": [Function], - }, - "addDatabaseText": [Function], "arcadiaToken": [Function], "canExceedMaximumValue": [Function], "canSaveQueries": [Function], @@ -1016,49 +973,6 @@ exports[`SettingsComponent renders 1`] = ` "_refreshSparkEnabledStateForAccount": [Function], "_resetNotebookWorkspace": [Function], "addCollectionText": [Function], - "addDatabasePane": AddDatabasePane { - "autoPilotUsageCost": [Function], - "canConfigureThroughput": [Function], - "canExceedMaximumValue": [Function], - "canRequestSupport": [Function], - "container": [Circular], - "costsVisible": [Function], - "databaseCreateNewShared": [Function], - "databaseId": [Function], - "databaseIdLabel": [Function], - "databaseIdPlaceHolder": [Function], - "databaseIdTooltipText": [Function], - "databaseLevelThroughputTooltipText": [Function], - "firstFieldHasFocus": [Function], - "formErrors": [Function], - "formErrorsDetails": [Function], - "freeTierExceedThroughputTooltip": [Function], - "id": "adddatabasepane", - "isAutoPilotSelected": [Function], - "isExecuting": [Function], - "isFreeTierAccount": [Function], - "isTemplateReady": [Function], - "maxAutoPilotThroughputSet": [Function], - "maxThroughputRU": [Function], - "maxThroughputRUText": [Function], - "minThroughputRU": [Function], - "onMoreDetailsKeyPress": [Function], - "requestUnitsUsageCost": [Function], - "ruToolTipText": [Function], - "showUpsellMessage": [Function], - "throughput": [Function], - "throughputRangeText": [Function], - "throughputSpendAck": [Function], - "throughputSpendAckText": [Function], - "throughputSpendAckVisible": [Function], - "title": [Function], - "upsellAnchorText": [Function], - "upsellAnchorUrl": [Function], - "upsellMessage": [Function], - "upsellMessageAriaLabel": [Function], - "visible": [Function], - }, - "addDatabaseText": [Function], "arcadiaToken": [Function], "canExceedMaximumValue": [Function], "canSaveQueries": [Function], @@ -2010,49 +1924,6 @@ exports[`SettingsComponent renders 1`] = ` "_refreshSparkEnabledStateForAccount": [Function], "_resetNotebookWorkspace": [Function], "addCollectionText": [Function], - "addDatabasePane": AddDatabasePane { - "autoPilotUsageCost": [Function], - "canConfigureThroughput": [Function], - "canExceedMaximumValue": [Function], - "canRequestSupport": [Function], - "container": [Circular], - "costsVisible": [Function], - "databaseCreateNewShared": [Function], - "databaseId": [Function], - "databaseIdLabel": [Function], - "databaseIdPlaceHolder": [Function], - "databaseIdTooltipText": [Function], - "databaseLevelThroughputTooltipText": [Function], - "firstFieldHasFocus": [Function], - "formErrors": [Function], - "formErrorsDetails": [Function], - "freeTierExceedThroughputTooltip": [Function], - "id": "adddatabasepane", - "isAutoPilotSelected": [Function], - "isExecuting": [Function], - "isFreeTierAccount": [Function], - "isTemplateReady": [Function], - "maxAutoPilotThroughputSet": [Function], - "maxThroughputRU": [Function], - "maxThroughputRUText": [Function], - "minThroughputRU": [Function], - "onMoreDetailsKeyPress": [Function], - "requestUnitsUsageCost": [Function], - "ruToolTipText": [Function], - "showUpsellMessage": [Function], - "throughput": [Function], - "throughputRangeText": [Function], - "throughputSpendAck": [Function], - "throughputSpendAckText": [Function], - "throughputSpendAckVisible": [Function], - "title": [Function], - "upsellAnchorText": [Function], - "upsellAnchorUrl": [Function], - "upsellMessage": [Function], - "upsellMessageAriaLabel": [Function], - "visible": [Function], - }, - "addDatabaseText": [Function], "arcadiaToken": [Function], "canExceedMaximumValue": [Function], "canSaveQueries": [Function], @@ -2991,49 +2862,6 @@ exports[`SettingsComponent renders 1`] = ` "_refreshSparkEnabledStateForAccount": [Function], "_resetNotebookWorkspace": [Function], "addCollectionText": [Function], - "addDatabasePane": AddDatabasePane { - "autoPilotUsageCost": [Function], - "canConfigureThroughput": [Function], - "canExceedMaximumValue": [Function], - "canRequestSupport": [Function], - "container": [Circular], - "costsVisible": [Function], - "databaseCreateNewShared": [Function], - "databaseId": [Function], - "databaseIdLabel": [Function], - "databaseIdPlaceHolder": [Function], - "databaseIdTooltipText": [Function], - "databaseLevelThroughputTooltipText": [Function], - "firstFieldHasFocus": [Function], - "formErrors": [Function], - "formErrorsDetails": [Function], - "freeTierExceedThroughputTooltip": [Function], - "id": "adddatabasepane", - "isAutoPilotSelected": [Function], - "isExecuting": [Function], - "isFreeTierAccount": [Function], - "isTemplateReady": [Function], - "maxAutoPilotThroughputSet": [Function], - "maxThroughputRU": [Function], - "maxThroughputRUText": [Function], - "minThroughputRU": [Function], - "onMoreDetailsKeyPress": [Function], - "requestUnitsUsageCost": [Function], - "ruToolTipText": [Function], - "showUpsellMessage": [Function], - "throughput": [Function], - "throughputRangeText": [Function], - "throughputSpendAck": [Function], - "throughputSpendAckText": [Function], - "throughputSpendAckVisible": [Function], - "title": [Function], - "upsellAnchorText": [Function], - "upsellAnchorUrl": [Function], - "upsellMessage": [Function], - "upsellMessageAriaLabel": [Function], - "visible": [Function], - }, - "addDatabaseText": [Function], "arcadiaToken": [Function], "canExceedMaximumValue": [Function], "canSaveQueries": [Function], diff --git a/src/Explorer/Explorer.tsx b/src/Explorer/Explorer.tsx index de0d8402e..0643f90a7 100644 --- a/src/Explorer/Explorer.tsx +++ b/src/Explorer/Explorer.tsx @@ -52,7 +52,6 @@ import type NotebookManager from "./Notebook/NotebookManager"; import type { NotebookPaneContent } from "./Notebook/NotebookManager"; import { NotebookUtil } from "./Notebook/NotebookUtil"; import { AddCollectionPanel } from "./Panes/AddCollectionPanel"; -import AddDatabasePane from "./Panes/AddDatabasePane"; import { AddDatabasePanel } from "./Panes/AddDatabasePanel/AddDatabasePanel"; import { BrowseQueriesPane } from "./Panes/BrowseQueriesPane/BrowseQueriesPane"; import CassandraAddCollectionPane from "./Panes/CassandraAddCollectionPane"; @@ -101,7 +100,6 @@ export interface ExplorerParams { export default class Explorer { public addCollectionText: ko.Observable; - public addDatabaseText: ko.Observable; public collectionTitle: ko.Observable; public deleteCollectionText: ko.Observable; public deleteDatabaseText: ko.Observable; @@ -149,7 +147,6 @@ export default class Explorer { public tabsManager: TabsManager; // Contextual panes - public addDatabasePane: AddDatabasePane; public cassandraAddCollectionPane: CassandraAddCollectionPane; private gitHubClient: GitHubClient; public gitHubOAuthService: GitHubOAuthService; @@ -208,7 +205,6 @@ export default class Explorer { dataExplorerArea: Constants.Areas.ResourceTree, }); this.addCollectionText = ko.observable("New Collection"); - this.addDatabaseText = ko.observable("New Database"); this.collectionTitle = ko.observable("Collections"); this.collectionTreeNodeAltText = ko.observable("Collection"); this.deleteCollectionText = ko.observable("Delete Collection"); @@ -401,13 +397,6 @@ export default class Explorer { } }); - this.addDatabasePane = new AddDatabasePane({ - id: "adddatabasepane", - visible: ko.observable(false), - - container: this, - }); - this.cassandraAddCollectionPane = new CassandraAddCollectionPane({ id: "cassandraaddcollectionpane", visible: ko.observable(false), @@ -423,7 +412,6 @@ export default class Explorer { } }); - this.addDatabaseText.subscribe((addDatabaseText: string) => this.addDatabasePane.title(addDatabaseText)); this.isTabsContentExpanded = ko.observable(false); document.addEventListener( @@ -441,7 +429,6 @@ export default class Explorer { switch (userContext.apiType) { case "SQL": this.addCollectionText("New Container"); - this.addDatabaseText("New Database"); this.collectionTitle("SQL API"); this.collectionTreeNodeAltText("Container"); this.deleteCollectionText("Delete Container"); @@ -450,7 +437,6 @@ export default class Explorer { break; case "Mongo": this.addCollectionText("New Collection"); - this.addDatabaseText("New Database"); this.collectionTitle("Collections"); this.collectionTreeNodeAltText("Collection"); this.deleteCollectionText("Delete Collection"); @@ -459,7 +445,6 @@ export default class Explorer { break; case "Gremlin": this.addCollectionText("New Graph"); - this.addDatabaseText("New Database"); this.deleteCollectionText("Delete Graph"); this.deleteDatabaseText("Delete Database"); this.collectionTitle("Gremlin API"); @@ -468,7 +453,6 @@ export default class Explorer { break; case "Tables": this.addCollectionText("New Table"); - this.addDatabaseText("New Database"); this.deleteCollectionText("Delete Table"); this.deleteDatabaseText("Delete Database"); this.collectionTitle("Azure Table API"); @@ -478,7 +462,6 @@ export default class Explorer { break; case "Cassandra": this.addCollectionText("New Table"); - this.addDatabaseText("New Keyspace"); this.deleteCollectionText("Delete Table"); this.deleteDatabaseText("Delete Keyspace"); this.collectionTitle("Cassandra API"); @@ -1949,19 +1932,14 @@ export default class Explorer { ); } public openAddDatabasePane(): void { - if (userContext.features.enableKOPanel) { - this.addDatabasePane.open(); - document.getElementById("linkAddDatabase").focus(); - } else { - this.openSidePanel( - "Add " + getDatabaseName(), - this.expandConsole()} - closePanel={this.closeSidePanel} - /> - ); - } + this.openSidePanel( + "New " + getDatabaseName(), + this.expandConsole()} + closePanel={this.closeSidePanel} + /> + ); } public openBrowseQueriesPanel(): void { diff --git a/src/Explorer/Menus/CommandBar/CommandBarComponentAdapter.tsx b/src/Explorer/Menus/CommandBar/CommandBarComponentAdapter.tsx index 520cdd372..269466866 100644 --- a/src/Explorer/Menus/CommandBar/CommandBarComponentAdapter.tsx +++ b/src/Explorer/Menus/CommandBar/CommandBarComponentAdapter.tsx @@ -33,7 +33,6 @@ export class CommandBarComponentAdapter implements ReactAdapter { container.deleteCollectionText, container.deleteDatabaseText, container.addCollectionText, - container.addDatabaseText, container.isDatabaseNodeOrNoneSelected, container.isDatabaseNodeSelected, container.isNoneSelected, diff --git a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.test.ts b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.test.ts index b692bdd38..268f149b7 100644 --- a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.test.ts +++ b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.test.ts @@ -126,7 +126,6 @@ describe("CommandBarComponentButtonFactory tests", () => { beforeAll(() => { mockExplorer = {} as Explorer; - mockExplorer.addDatabaseText = ko.observable("mockText"); mockExplorer.addCollectionText = ko.observable("mockText"); updateUserContext({ databaseAccount: { @@ -221,7 +220,6 @@ describe("CommandBarComponentButtonFactory tests", () => { beforeAll(() => { mockExplorer = {} as Explorer; - mockExplorer.addDatabaseText = ko.observable("mockText"); mockExplorer.addCollectionText = ko.observable("mockText"); updateUserContext({ databaseAccount: { diff --git a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.tsx b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.tsx index b5040d8a6..da8b4251d 100644 --- a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.tsx +++ b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.tsx @@ -22,6 +22,7 @@ import * as Constants from "../../../Common/Constants"; import { configContext, Platform } from "../../../ConfigContext"; import * as ViewModels from "../../../Contracts/ViewModels"; import { userContext } from "../../../UserContext"; +import { getDatabaseName } from "../../../Utils/APITypeUtils"; import { CommandButtonComponentProps } from "../../Controls/CommandButton/CommandButtonComponent"; import Explorer from "../../Explorer"; import { OpenFullScreen } from "../../OpenFullScreen"; @@ -261,7 +262,7 @@ function createOpenSynapseLinkDialogButton(container: Explorer): CommandButtonCo } function createNewDatabase(container: Explorer): CommandButtonComponentProps { - const label = container.addDatabaseText(); + const label = "New " + getDatabaseName(); return { iconSrc: AddDatabaseIcon, iconAlt: label, diff --git a/src/Explorer/Panes/AddDatabasePane.html b/src/Explorer/Panes/AddDatabasePane.html deleted file mode 100644 index 2a598ade6..000000000 --- a/src/Explorer/Panes/AddDatabasePane.html +++ /dev/null @@ -1,174 +0,0 @@ -
-
-
- -
-
- -
-
- - -
- -
- -
-
- - diff --git a/src/Explorer/Panes/AddDatabasePane.test.ts b/src/Explorer/Panes/AddDatabasePane.test.ts deleted file mode 100644 index 4368fc5d0..000000000 --- a/src/Explorer/Panes/AddDatabasePane.test.ts +++ /dev/null @@ -1,105 +0,0 @@ -import * as Constants from "../../Common/Constants"; -import { DatabaseAccount } from "../../Contracts/DataModels"; -import { SubscriptionType } from "../../Contracts/SubscriptionType"; -import { updateUserContext } from "../../UserContext"; -import Explorer from "../Explorer"; -import AddDatabasePane from "./AddDatabasePane"; - -const mockDatabaseAccount: DatabaseAccount = { - id: "mock", - kind: "DocumentDB", - location: "", - name: "mock", - properties: { - documentEndpoint: "", - cassandraEndpoint: "", - gremlinEndpoint: "", - tableEndpoint: "", - enableFreeTier: false, - }, - type: undefined, -}; - -const mockFreeTierDatabaseAccount: DatabaseAccount = { - id: "mock", - kind: "DocumentDB", - location: "", - name: "mock", - properties: { - documentEndpoint: "", - cassandraEndpoint: "", - gremlinEndpoint: "", - tableEndpoint: "", - enableFreeTier: true, - }, - type: undefined, -}; - -describe("Add Database Pane", () => { - describe("getSharedThroughputDefault()", () => { - it("should be true if subscription type is Benefits", () => { - updateUserContext({ - subscriptionType: SubscriptionType.Benefits, - }); - const explorer = new Explorer(); - const addDatabasePane = explorer.addDatabasePane as AddDatabasePane; - expect(addDatabasePane.getSharedThroughputDefault()).toBe(true); - }); - - it("should be false if subscription type is EA", () => { - updateUserContext({ - subscriptionType: SubscriptionType.EA, - }); - const explorer = new Explorer(); - const addDatabasePane = explorer.addDatabasePane as AddDatabasePane; - expect(addDatabasePane.getSharedThroughputDefault()).toBe(false); - }); - - it("should be true if subscription type is Free", () => { - updateUserContext({ - subscriptionType: SubscriptionType.Free, - }); - const explorer = new Explorer(); - const addDatabasePane = explorer.addDatabasePane as AddDatabasePane; - expect(addDatabasePane.getSharedThroughputDefault()).toBe(true); - }); - - it("should be true if subscription type is Internal", () => { - updateUserContext({ - subscriptionType: SubscriptionType.Internal, - }); - const explorer = new Explorer(); - const addDatabasePane = explorer.addDatabasePane as AddDatabasePane; - expect(addDatabasePane.getSharedThroughputDefault()).toBe(true); - }); - - it("should be true if subscription type is PAYG", () => { - updateUserContext({ - subscriptionType: SubscriptionType.PAYG, - }); - const explorer = new Explorer(); - const addDatabasePane = explorer.addDatabasePane as AddDatabasePane; - expect(addDatabasePane.getSharedThroughputDefault()).toBe(true); - }); - - it("should display free tier text in upsell messaging", () => { - updateUserContext({ databaseAccount: mockFreeTierDatabaseAccount }); - const explorer = new Explorer(); - const addDatabasePane = explorer.addDatabasePane as AddDatabasePane; - expect(addDatabasePane.isFreeTierAccount()).toBe(true); - expect(addDatabasePane.upsellMessage()).toContain("With free tier"); - expect(addDatabasePane.upsellAnchorUrl()).toBe(Constants.Urls.freeTierInformation); - expect(addDatabasePane.upsellAnchorText()).toBe("Learn more"); - }); - - it("should display standard texr in upsell messaging", () => { - updateUserContext({ databaseAccount: mockDatabaseAccount }); - const explorer = new Explorer(); - const addDatabasePane = explorer.addDatabasePane as AddDatabasePane; - expect(addDatabasePane.isFreeTierAccount()).toBe(false); - expect(addDatabasePane.upsellMessage()).toContain("Start at"); - expect(addDatabasePane.upsellAnchorUrl()).toBe(Constants.Urls.cosmosPricing); - expect(addDatabasePane.upsellAnchorText()).toBe("More details"); - }); - }); -}); diff --git a/src/Explorer/Panes/AddDatabasePane.ts b/src/Explorer/Panes/AddDatabasePane.ts deleted file mode 100644 index d07efff58..000000000 --- a/src/Explorer/Panes/AddDatabasePane.ts +++ /dev/null @@ -1,452 +0,0 @@ -import * as ko from "knockout"; -import * as Constants from "../../Common/Constants"; -import { createDatabase } from "../../Common/dataAccess/createDatabase"; -import editable from "../../Common/EditableUtility"; -import { getErrorMessage, getErrorStack } from "../../Common/ErrorHandlingUtils"; -import { configContext, Platform } from "../../ConfigContext"; -import * as DataModels from "../../Contracts/DataModels"; -import { SubscriptionType } from "../../Contracts/SubscriptionType"; -import * as ViewModels from "../../Contracts/ViewModels"; -import * as SharedConstants from "../../Shared/Constants"; -import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants"; -import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; -import { userContext } from "../../UserContext"; -import * as AutoPilotUtils from "../../Utils/AutoPilotUtils"; -import * as PricingUtils from "../../Utils/PricingUtils"; -import { ContextualPaneBase } from "./ContextualPaneBase"; - -export default class AddDatabasePane extends ContextualPaneBase { - public defaultExperience: ko.Computed; - public databaseIdLabel: ko.Computed; - public databaseIdPlaceHolder: ko.Computed; - public databaseId: ko.Observable; - public databaseIdTooltipText: ko.Computed; - public databaseLevelThroughputTooltipText: ko.Computed; - public databaseCreateNewShared: ko.Observable; - public formErrorsDetails: ko.Observable; - public throughput: ViewModels.Editable; - public maxThroughputRU: ko.Observable; - public minThroughputRU: ko.Observable; - public maxThroughputRUText: ko.PureComputed; - public throughputRangeText: ko.Computed; - public throughputSpendAckText: ko.Observable; - public throughputSpendAck: ko.Observable; - public throughputSpendAckVisible: ko.Computed; - public requestUnitsUsageCost: ko.Computed; - public canRequestSupport: ko.PureComputed; - public costsVisible: ko.PureComputed; - public upsellMessage: ko.PureComputed; - public upsellMessageAriaLabel: ko.PureComputed; - public upsellAnchorUrl: ko.PureComputed; - public upsellAnchorText: ko.PureComputed; - public isAutoPilotSelected: ko.Observable; - public maxAutoPilotThroughputSet: ko.Observable; - public autoPilotUsageCost: ko.Computed; - public canExceedMaximumValue: ko.PureComputed; - public ruToolTipText: ko.Computed; - public freeTierExceedThroughputTooltip: ko.Computed; - public isFreeTierAccount: ko.Computed; - public canConfigureThroughput: ko.PureComputed; - public showUpsellMessage: ko.PureComputed; - - constructor(options: ViewModels.PaneOptions) { - super(options); - this.title((this.container && this.container.addDatabaseText()) || "New Database"); - this.databaseId = ko.observable(); - this.ruToolTipText = ko.pureComputed(() => PricingUtils.getRuToolTipText()); - this.canConfigureThroughput = ko.pureComputed(() => !this.container.isServerlessEnabled()); - - this.canExceedMaximumValue = ko.pureComputed(() => this.container.canExceedMaximumValue()); - - // TODO 388844: get defaults from parent frame - this.databaseCreateNewShared = ko.observable(this.getSharedThroughputDefault()); - - this.databaseIdLabel = ko.computed(() => - userContext.apiType === "Cassandra" ? "Keyspace id" : "Database id" - ); - - this.databaseIdPlaceHolder = ko.computed(() => - userContext.apiType === "Cassandra" ? "Type a new keyspace id" : "Type a new database id" - ); - - this.databaseIdTooltipText = ko.computed(() => { - const isCassandraAccount: boolean = userContext.apiType === "Cassandra"; - return `A ${isCassandraAccount ? "keyspace" : "database"} is a logical container of one or more ${ - isCassandraAccount ? "tables" : "collections" - }`; - }); - this.databaseLevelThroughputTooltipText = ko.computed(() => { - const isCassandraAccount: boolean = userContext.apiType === "Cassandra"; - const databaseLabel: string = isCassandraAccount ? "keyspace" : "database"; - const collectionsLabel: string = isCassandraAccount ? "tables" : "collections"; - return `Provisioned throughput at the ${databaseLabel} level will be shared across all ${collectionsLabel} within the ${databaseLabel}.`; - }); - - this.throughput = editable.observable(); - this.maxThroughputRU = ko.observable(); - this.minThroughputRU = ko.observable(); - this.throughputSpendAckText = ko.observable(); - this.throughputSpendAck = ko.observable(false); - this.isAutoPilotSelected = ko.observable(false); - this.maxAutoPilotThroughputSet = ko.observable(AutoPilotUtils.minAutoPilotThroughput); - this.autoPilotUsageCost = ko.pureComputed(() => { - const autoPilot = this._isAutoPilotSelectedAndWhatTier(); - if (!autoPilot) { - return ""; - } - return PricingUtils.getAutoPilotV3SpendHtml(autoPilot.maxThroughput, true /* isDatabaseThroughput */); - }); - this.throughputRangeText = ko.pureComputed(() => { - if (this.isAutoPilotSelected()) { - return AutoPilotUtils.getAutoPilotHeaderText(); - } - return `Throughput (${this.minThroughputRU().toLocaleString()} - ${this.maxThroughputRU().toLocaleString()} RU/s)`; - }); - - this.requestUnitsUsageCost = ko.computed(() => { - const offerThroughput: number = this.throughput(); - if ( - offerThroughput < this.minThroughputRU() || - (offerThroughput > this.maxThroughputRU() && !this.canExceedMaximumValue()) - ) { - return ""; - } - - const { databaseAccount: account } = userContext; - if (!account) { - return ""; - } - - const regions = account?.properties?.readLocations?.length || 1; - const multimaster = account?.properties?.enableMultipleWriteLocations || false; - - let estimatedSpendAcknowledge: string; - let estimatedSpend: string; - if (!this.isAutoPilotSelected()) { - estimatedSpend = PricingUtils.getEstimatedSpendHtml( - offerThroughput, - userContext.portalEnv, - regions, - multimaster - ); - estimatedSpendAcknowledge = PricingUtils.getEstimatedSpendAcknowledgeString( - offerThroughput, - userContext.portalEnv, - regions, - multimaster, - this.isAutoPilotSelected() - ); - } else { - estimatedSpend = PricingUtils.getEstimatedAutoscaleSpendHtml( - this.maxAutoPilotThroughputSet(), - userContext.portalEnv, - regions, - multimaster - ); - estimatedSpendAcknowledge = PricingUtils.getEstimatedSpendAcknowledgeString( - this.maxAutoPilotThroughputSet(), - userContext.portalEnv, - regions, - multimaster, - this.isAutoPilotSelected() - ); - } - // TODO: change throughputSpendAckText to be a computed value, instead of having this side effect - this.throughputSpendAckText(estimatedSpendAcknowledge); - return estimatedSpend; - }); - - this.canRequestSupport = ko.pureComputed(() => { - if ( - configContext.platform !== Platform.Emulator && - !userContext.isTryCosmosDBSubscription && - configContext.platform !== Platform.Portal - ) { - const offerThroughput: number = this.throughput(); - return offerThroughput <= 100000; - } - - return false; - }); - - this.isFreeTierAccount = ko.computed(() => { - return userContext?.databaseAccount?.properties?.enableFreeTier; - }); - - this.showUpsellMessage = ko.pureComputed(() => { - if (this.container.isServerlessEnabled()) { - return false; - } - - if (this.isFreeTierAccount()) { - return this.databaseCreateNewShared(); - } - - return true; - }); - - this.maxThroughputRUText = ko.pureComputed(() => { - return this.maxThroughputRU().toLocaleString(); - }); - - this.costsVisible = ko.pureComputed(() => { - return configContext.platform !== Platform.Emulator; - }); - - this.throughputSpendAckVisible = ko.pureComputed(() => { - const autoscaleThroughput = this.maxAutoPilotThroughputSet() * 1; - if (this.isAutoPilotSelected()) { - return autoscaleThroughput > SharedConstants.CollectionCreation.DefaultCollectionRUs100K; - } - - const selectedThroughput: number = this.throughput(); - const maxRU: number = this.maxThroughputRU && this.maxThroughputRU(); - - const isMaxRUGreaterThanDefault: boolean = maxRU > SharedConstants.CollectionCreation.DefaultCollectionRUs100K; - const isThroughputSetGreaterThanDefault: boolean = - selectedThroughput > SharedConstants.CollectionCreation.DefaultCollectionRUs100K; - - if (this.canExceedMaximumValue()) { - return isThroughputSetGreaterThanDefault; - } - - return isThroughputSetGreaterThanDefault && isMaxRUGreaterThanDefault; - }); - - this.databaseCreateNewShared.subscribe((useShared: boolean) => { - this._updateThroughputLimitByDatabase(); - }); - - this.resetData(); - - this.freeTierExceedThroughputTooltip = ko.pureComputed(() => - this.isFreeTierAccount() && !this.container.isFirstResourceCreated() - ? "The first 400 RU/s in this account are free. Billing will apply to any throughput beyond 400 RU/s." - : "" - ); - - this.upsellMessage = ko.pureComputed(() => { - return PricingUtils.getUpsellMessage( - userContext.portalEnv, - this.isFreeTierAccount(), - this.container.isFirstResourceCreated(), - false - ); - }); - - this.upsellMessageAriaLabel = ko.pureComputed(() => { - return `${this.upsellMessage()}. Click ${this.isFreeTierAccount() ? "to learn more" : "for more details"}`; - }); - - this.upsellAnchorUrl = ko.pureComputed(() => { - return this.isFreeTierAccount() ? Constants.Urls.freeTierInformation : Constants.Urls.cosmosPricing; - }); - - this.upsellAnchorText = ko.pureComputed(() => { - return this.isFreeTierAccount() ? "Learn more" : "More details"; - }); - } - - public onMoreDetailsKeyPress = (source: any, event: KeyboardEvent): boolean => { - if (event.keyCode === Constants.KeyCodes.Space || event.keyCode === Constants.KeyCodes.Enter) { - this.showErrorDetails(); - return false; - } - return true; - }; - - public open() { - super.open(); - this.resetData(); - const addDatabasePaneOpenMessage = { - subscriptionType: userContext.subscriptionType, - subscriptionQuotaId: userContext.quotaId, - defaultsCheck: { - throughput: this.throughput(), - flight: userContext.addCollectionFlight, - }, - dataExplorerArea: Constants.Areas.ContextualPane, - }; - const focusElement = document.getElementById("database-id"); - focusElement && focusElement.focus(); - TelemetryProcessor.trace(Action.CreateDatabase, ActionModifiers.Open, addDatabasePaneOpenMessage); - } - - public submit() { - if (!this._isValid()) { - return; - } - - const offerThroughput: number = this._computeOfferThroughput(); - - const addDatabasePaneStartMessage = { - database: ko.toJS({ - id: this.databaseId(), - shared: this.databaseCreateNewShared(), - }), - offerThroughput, - subscriptionType: userContext.subscriptionType, - subscriptionQuotaId: userContext.quotaId, - defaultsCheck: { - flight: userContext.addCollectionFlight, - }, - dataExplorerArea: Constants.Areas.ContextualPane, - }; - const startKey: number = TelemetryProcessor.traceStart(Action.CreateDatabase, addDatabasePaneStartMessage); - this.formErrors(""); - this.isExecuting(true); - - const createDatabaseParams: DataModels.CreateDatabaseParams = { - databaseId: addDatabasePaneStartMessage.database.id, - databaseLevelThroughput: addDatabasePaneStartMessage.database.shared, - }; - - if (this.isAutoPilotSelected()) { - createDatabaseParams.autoPilotMaxThroughput = this.maxAutoPilotThroughputSet(); - } else { - createDatabaseParams.offerThroughput = addDatabasePaneStartMessage.offerThroughput; - } - - createDatabase(createDatabaseParams).then( - (database: DataModels.Database) => { - this._onCreateDatabaseSuccess(offerThroughput, startKey); - }, - (error: any) => { - this._onCreateDatabaseFailure(error, offerThroughput, startKey); - } - ); - } - - public resetData() { - this.databaseId(""); - this.databaseCreateNewShared(this.getSharedThroughputDefault()); - this.isAutoPilotSelected(this.container.isAutoscaleDefaultEnabled()); - this.maxAutoPilotThroughputSet(AutoPilotUtils.minAutoPilotThroughput); - this._updateThroughputLimitByDatabase(); - this.throughputSpendAck(false); - super.resetData(); - } - - public getSharedThroughputDefault(): boolean { - const { subscriptionType } = userContext; - - if (subscriptionType === SubscriptionType.EA || this.container.isServerlessEnabled()) { - return false; - } - - return true; - } - - private _onCreateDatabaseSuccess(offerThroughput: number, startKey: number): void { - this.isExecuting(false); - this.close(); - this.container.refreshAllDatabases(); - const addDatabasePaneSuccessMessage = { - database: ko.toJS({ - id: this.databaseId(), - shared: this.databaseCreateNewShared(), - }), - offerThroughput: offerThroughput, - subscriptionType: userContext.subscriptionType, - subscriptionQuotaId: userContext.quotaId, - defaultsCheck: { - flight: userContext.addCollectionFlight, - }, - dataExplorerArea: Constants.Areas.ContextualPane, - }; - TelemetryProcessor.traceSuccess(Action.CreateDatabase, addDatabasePaneSuccessMessage, startKey); - this.resetData(); - } - - private _onCreateDatabaseFailure(error: any, offerThroughput: number, startKey: number): void { - this.isExecuting(false); - const errorMessage = getErrorMessage(error); - this.formErrors(errorMessage); - this.formErrorsDetails(errorMessage); - const addDatabasePaneFailedMessage = { - database: ko.toJS({ - id: this.databaseId(), - shared: this.databaseCreateNewShared(), - }), - offerThroughput: offerThroughput, - subscriptionType: userContext.subscriptionType, - subscriptionQuotaId: userContext.quotaId, - defaultsCheck: { - flight: userContext.addCollectionFlight, - }, - dataExplorerArea: Constants.Areas.ContextualPane, - error: errorMessage, - errorStack: getErrorStack(error), - }; - TelemetryProcessor.traceFailure(Action.CreateDatabase, addDatabasePaneFailedMessage, startKey); - } - - private _getThroughput(): number { - const throughput: number = this.throughput(); - return isNaN(throughput) ? 0 : Number(throughput); - } - - private _computeOfferThroughput(): number { - if (!this.canConfigureThroughput()) { - return undefined; - } - - if (this.isAutoPilotSelected()) { - return undefined; - } - - return this._getThroughput(); - } - - private _isValid(): boolean { - // TODO add feature flag that disables validation for customers with custom accounts - if (this.isAutoPilotSelected()) { - const autoPilot = this._isAutoPilotSelectedAndWhatTier(); - if ( - !autoPilot || - !autoPilot.maxThroughput || - !AutoPilotUtils.isValidAutoPilotThroughput(autoPilot.maxThroughput) - ) { - this.formErrors( - `Please enter a value greater than ${AutoPilotUtils.minAutoPilotThroughput} for autopilot throughput` - ); - return false; - } - } - const throughput = this._getThroughput(); - - if (throughput > SharedConstants.CollectionCreation.DefaultCollectionRUs100K && !this.throughputSpendAck()) { - this.formErrors(`Please acknowledge the estimated daily spend.`); - return false; - } - - const autoscaleThroughput = this.maxAutoPilotThroughputSet() * 1; - - if ( - this.isAutoPilotSelected() && - autoscaleThroughput > SharedConstants.CollectionCreation.DefaultCollectionRUs100K && - !this.throughputSpendAck() - ) { - this.formErrors(`Please acknowledge the estimated monthly spend.`); - return false; - } - - return true; - } - - private _isAutoPilotSelectedAndWhatTier(): DataModels.AutoPilotCreationSettings { - if (this.isAutoPilotSelected() && this.maxAutoPilotThroughputSet()) { - return { - maxThroughput: this.maxAutoPilotThroughputSet() * 1, - }; - } - return undefined; - } - - private _updateThroughputLimitByDatabase() { - const throughputDefaults = this.container.collectionCreationDefaults.throughput; - this.throughput(throughputDefaults.shared); - this.maxThroughputRU(throughputDefaults.unlimitedmax); - this.minThroughputRU(throughputDefaults.unlimitedmin); - } -} diff --git a/src/Explorer/Panes/GitHubReposPanel/__snapshots__/GitHubReposPanel.test.tsx.snap b/src/Explorer/Panes/GitHubReposPanel/__snapshots__/GitHubReposPanel.test.tsx.snap index 9be73eb7e..3ddac360f 100644 --- a/src/Explorer/Panes/GitHubReposPanel/__snapshots__/GitHubReposPanel.test.tsx.snap +++ b/src/Explorer/Panes/GitHubReposPanel/__snapshots__/GitHubReposPanel.test.tsx.snap @@ -24,49 +24,6 @@ exports[`GitHub Repos Panel should render Default properly 1`] = ` "_refreshSparkEnabledStateForAccount": [Function], "_resetNotebookWorkspace": [Function], "addCollectionText": [Function], - "addDatabasePane": AddDatabasePane { - "autoPilotUsageCost": [Function], - "canConfigureThroughput": [Function], - "canExceedMaximumValue": [Function], - "canRequestSupport": [Function], - "container": [Circular], - "costsVisible": [Function], - "databaseCreateNewShared": [Function], - "databaseId": [Function], - "databaseIdLabel": [Function], - "databaseIdPlaceHolder": [Function], - "databaseIdTooltipText": [Function], - "databaseLevelThroughputTooltipText": [Function], - "firstFieldHasFocus": [Function], - "formErrors": [Function], - "formErrorsDetails": [Function], - "freeTierExceedThroughputTooltip": [Function], - "id": "adddatabasepane", - "isAutoPilotSelected": [Function], - "isExecuting": [Function], - "isFreeTierAccount": [Function], - "isTemplateReady": [Function], - "maxAutoPilotThroughputSet": [Function], - "maxThroughputRU": [Function], - "maxThroughputRUText": [Function], - "minThroughputRU": [Function], - "onMoreDetailsKeyPress": [Function], - "requestUnitsUsageCost": [Function], - "ruToolTipText": [Function], - "showUpsellMessage": [Function], - "throughput": [Function], - "throughputRangeText": [Function], - "throughputSpendAck": [Function], - "throughputSpendAckText": [Function], - "throughputSpendAckVisible": [Function], - "title": [Function], - "upsellAnchorText": [Function], - "upsellAnchorUrl": [Function], - "upsellMessage": [Function], - "upsellMessageAriaLabel": [Function], - "visible": [Function], - }, - "addDatabaseText": [Function], "arcadiaToken": [Function], "canExceedMaximumValue": [Function], "canSaveQueries": [Function], diff --git a/src/Explorer/Panes/PaneComponents.ts b/src/Explorer/Panes/PaneComponents.ts index 655981948..81163e94a 100644 --- a/src/Explorer/Panes/PaneComponents.ts +++ b/src/Explorer/Panes/PaneComponents.ts @@ -1,4 +1,3 @@ -import AddDatabasePaneTemplate from "./AddDatabasePane.html"; import CassandraAddCollectionPaneTemplate from "./CassandraAddCollectionPane.html"; export class PaneComponent { constructor(data: any) { @@ -6,15 +5,6 @@ export class PaneComponent { } } -export class AddDatabasePaneComponent { - constructor() { - return { - viewModel: PaneComponent, - template: AddDatabasePaneTemplate, - }; - } -} - export class CassandraAddCollectionPaneComponent { constructor() { return { diff --git a/src/Explorer/Panes/StringInputPane/__snapshots__/StringInputPane.test.tsx.snap b/src/Explorer/Panes/StringInputPane/__snapshots__/StringInputPane.test.tsx.snap index 3244fa044..2bec097e8 100644 --- a/src/Explorer/Panes/StringInputPane/__snapshots__/StringInputPane.test.tsx.snap +++ b/src/Explorer/Panes/StringInputPane/__snapshots__/StringInputPane.test.tsx.snap @@ -14,49 +14,6 @@ exports[`StringInput Pane should render Create new directory properly 1`] = ` "_refreshSparkEnabledStateForAccount": [Function], "_resetNotebookWorkspace": [Function], "addCollectionText": [Function], - "addDatabasePane": AddDatabasePane { - "autoPilotUsageCost": [Function], - "canConfigureThroughput": [Function], - "canExceedMaximumValue": [Function], - "canRequestSupport": [Function], - "container": [Circular], - "costsVisible": [Function], - "databaseCreateNewShared": [Function], - "databaseId": [Function], - "databaseIdLabel": [Function], - "databaseIdPlaceHolder": [Function], - "databaseIdTooltipText": [Function], - "databaseLevelThroughputTooltipText": [Function], - "firstFieldHasFocus": [Function], - "formErrors": [Function], - "formErrorsDetails": [Function], - "freeTierExceedThroughputTooltip": [Function], - "id": "adddatabasepane", - "isAutoPilotSelected": [Function], - "isExecuting": [Function], - "isFreeTierAccount": [Function], - "isTemplateReady": [Function], - "maxAutoPilotThroughputSet": [Function], - "maxThroughputRU": [Function], - "maxThroughputRUText": [Function], - "minThroughputRU": [Function], - "onMoreDetailsKeyPress": [Function], - "requestUnitsUsageCost": [Function], - "ruToolTipText": [Function], - "showUpsellMessage": [Function], - "throughput": [Function], - "throughputRangeText": [Function], - "throughputSpendAck": [Function], - "throughputSpendAckText": [Function], - "throughputSpendAckVisible": [Function], - "title": [Function], - "upsellAnchorText": [Function], - "upsellAnchorUrl": [Function], - "upsellMessage": [Function], - "upsellMessageAriaLabel": [Function], - "visible": [Function], - }, - "addDatabaseText": [Function], "arcadiaToken": [Function], "canExceedMaximumValue": [Function], "canSaveQueries": [Function], diff --git a/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap b/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap index ccce25b5b..8cbd0e904 100644 --- a/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap +++ b/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap @@ -12,49 +12,6 @@ exports[`Delete Database Confirmation Pane submit() Should call delete database "_refreshSparkEnabledStateForAccount": [Function], "_resetNotebookWorkspace": [Function], "addCollectionText": [Function], - "addDatabasePane": AddDatabasePane { - "autoPilotUsageCost": [Function], - "canConfigureThroughput": [Function], - "canExceedMaximumValue": [Function], - "canRequestSupport": [Function], - "container": [Circular], - "costsVisible": [Function], - "databaseCreateNewShared": [Function], - "databaseId": [Function], - "databaseIdLabel": [Function], - "databaseIdPlaceHolder": [Function], - "databaseIdTooltipText": [Function], - "databaseLevelThroughputTooltipText": [Function], - "firstFieldHasFocus": [Function], - "formErrors": [Function], - "formErrorsDetails": [Function], - "freeTierExceedThroughputTooltip": [Function], - "id": "adddatabasepane", - "isAutoPilotSelected": [Function], - "isExecuting": [Function], - "isFreeTierAccount": [Function], - "isTemplateReady": [Function], - "maxAutoPilotThroughputSet": [Function], - "maxThroughputRU": [Function], - "maxThroughputRUText": [Function], - "minThroughputRU": [Function], - "onMoreDetailsKeyPress": [Function], - "requestUnitsUsageCost": [Function], - "ruToolTipText": [Function], - "showUpsellMessage": [Function], - "throughput": [Function], - "throughputRangeText": [Function], - "throughputSpendAck": [Function], - "throughputSpendAckText": [Function], - "throughputSpendAckVisible": [Function], - "title": [Function], - "upsellAnchorText": [Function], - "upsellAnchorUrl": [Function], - "upsellMessage": [Function], - "upsellMessageAriaLabel": [Function], - "visible": [Function], - }, - "addDatabaseText": [Function], "arcadiaToken": [Function], "canExceedMaximumValue": [Function], "canSaveQueries": [Function], diff --git a/src/Explorer/SplashScreen/SplashScreen.tsx b/src/Explorer/SplashScreen/SplashScreen.tsx index b6bc67b29..34211d821 100644 --- a/src/Explorer/SplashScreen/SplashScreen.tsx +++ b/src/Explorer/SplashScreen/SplashScreen.tsx @@ -17,6 +17,7 @@ import { AuthType } from "../../AuthType"; import * as Constants from "../../Common/Constants"; import * as ViewModels from "../../Contracts/ViewModels"; import { userContext } from "../../UserContext"; +import { getDatabaseName } from "../../Utils/APITypeUtils"; import { FeaturePanelLauncher } from "../Controls/FeaturePanel/FeaturePanelLauncher"; import { DataSamplesUtil } from "../DataSamples/DataSamplesUtil"; import Explorer from "../Explorer"; @@ -290,7 +291,7 @@ export class SplashScreen extends React.Component { } else { items.push({ iconSrc: AddDatabaseIcon, - title: this.container.addDatabaseText(), + title: "New " + getDatabaseName(), description: null, onClick: () => this.container.openAddDatabasePane(), }); diff --git a/src/Main.tsx b/src/Main.tsx index 76bab54c2..c4c3be41c 100644 --- a/src/Main.tsx +++ b/src/Main.tsx @@ -154,7 +154,6 @@ const App: React.FunctionComponent = () => { closePanel={closeSidePanel} isConsoleExpanded={isNotificationConsoleExpanded} /> -
{showDialog && }