diff --git a/src/Common/QueriesClient.ts b/src/Common/QueriesClient.ts index b7146fdbf..9d89f89b0 100644 --- a/src/Common/QueriesClient.ts +++ b/src/Common/QueriesClient.ts @@ -5,16 +5,16 @@ import * as ViewModels from "../Contracts/ViewModels"; import Explorer from "../Explorer/Explorer"; import DocumentsTab from "../Explorer/Tabs/DocumentsTab"; import DocumentId from "../Explorer/Tree/DocumentId"; +import { userContext } from "../UserContext"; import * as NotificationConsoleUtils from "../Utils/NotificationConsoleUtils"; import * as QueryUtils from "../Utils/QueryUtils"; import { BackendDefaults, HttpStatusCodes, SavedQueries } from "./Constants"; -import { userContext } from "../UserContext"; -import { queryDocumentsPage } from "./dataAccess/queryDocumentsPage"; import { createCollection } from "./dataAccess/createCollection"; -import { handleError } from "./ErrorHandlingUtils"; import { createDocument } from "./dataAccess/createDocument"; import { deleteDocument } from "./dataAccess/deleteDocument"; import { queryDocuments } from "./dataAccess/queryDocuments"; +import { queryDocumentsPage } from "./dataAccess/queryDocumentsPage"; +import { handleError } from "./ErrorHandlingUtils"; export class QueriesClient { private static readonly PartitionKey: DataModels.PartitionKey = { @@ -211,7 +211,7 @@ export class QueriesClient { } private fetchQueriesQuery(): string { - if (this.container.isPreferredApiMongoDB()) { + if (userContext.apiType === "Mongo") { return QueriesClient.FetchMongoQuery; } return QueriesClient.FetchQuery; diff --git a/src/Explorer/ContextMenuButtonFactory.ts b/src/Explorer/ContextMenuButtonFactory.ts index 8337ec700..db950ad46 100644 --- a/src/Explorer/ContextMenuButtonFactory.ts +++ b/src/Explorer/ContextMenuButtonFactory.ts @@ -63,7 +63,7 @@ export class ResourceTreeContextMenuButtonFactory { }); } - if (container.isPreferredApiMongoDB()) { + if (userContext.apiType === "Mongo") { items.push({ iconSrc: AddSqlQueryIcon, onClick: () => selectedCollection && selectedCollection.onNewMongoQueryClick(selectedCollection, null), diff --git a/src/Explorer/Controls/Settings/SettingsComponent.tsx b/src/Explorer/Controls/Settings/SettingsComponent.tsx index 4c151eb51..ec1ee7727 100644 --- a/src/Explorer/Controls/Settings/SettingsComponent.tsx +++ b/src/Explorer/Controls/Settings/SettingsComponent.tsx @@ -136,15 +136,13 @@ export class SettingsComponent extends React.Component => { if ( - this.container.isPreferredApiMongoDB() && + userContext.apiType === "Mongo" && this.container.isEnableMongoCapabilityPresent() && this.container.databaseAccount() ) { @@ -1002,7 +1000,7 @@ export class SettingsComponent extends React.Component, }); - } else if (this.container.isPreferredApiMongoDB()) { + } else if (userContext.apiType === "Mongo") { const mongoIndexTabContext = this.getMongoIndexTabContent(mongoIndexingPolicyComponentProps); if (mongoIndexTabContext) { tabs.push({ diff --git a/src/Explorer/Controls/Settings/SettingsSubComponents/SubSettingsComponent.tsx b/src/Explorer/Controls/Settings/SettingsSubComponents/SubSettingsComponent.tsx index 14947f81c..4a73e93e6 100644 --- a/src/Explorer/Controls/Settings/SettingsSubComponents/SubSettingsComponent.tsx +++ b/src/Explorer/Controls/Settings/SettingsSubComponents/SubSettingsComponent.tsx @@ -323,7 +323,7 @@ export class SubSettingsComponent extends React.Component { const createExplorerStub = (database: ViewModels.Database): Explorer => { const explorerStub = {} as Explorer; explorerStub.databases = ko.observableArray([database]); - explorerStub.isPreferredApiMongoDB = ko.computed(() => false); explorerStub.canExceedMaximumValue = ko.computed(() => false); explorerStub.findDatabaseWithId = () => database; explorerStub.refreshAllDatabases = () => Q.resolve(); diff --git a/src/Explorer/Explorer.tsx b/src/Explorer/Explorer.tsx index 644f5980b..875c275db 100644 --- a/src/Explorer/Explorer.tsx +++ b/src/Explorer/Explorer.tsx @@ -118,11 +118,6 @@ export default class Explorer { * Use userContext.apiType instead * */ public defaultExperience: ko.Observable; - /** - * @deprecated - * Compare a string with userContext.apiType instead: userContext.apiType === "Mongo" - * */ - public isPreferredApiMongoDB: ko.Computed; public isFixedCollectionWithSharedThroughputSupported: ko.Computed; /** * @deprecated @@ -409,27 +404,6 @@ export default class Explorer { ) !== undefined ); - this.isPreferredApiMongoDB = ko.computed(() => { - const defaultExperience = (this.defaultExperience && this.defaultExperience()) || ""; - if (defaultExperience.toLowerCase() === Constants.DefaultAccountExperience.MongoDB.toLowerCase()) { - return true; - } - - if (defaultExperience.toLowerCase() === Constants.DefaultAccountExperience.ApiForMongoDB.toLowerCase()) { - return true; - } - - if ( - this.databaseAccount && - this.databaseAccount() && - this.databaseAccount().kind.toLowerCase() === Constants.AccountKind.MongoDB - ) { - return true; - } - - return false; - }); - this.isEnableMongoCapabilityPresent = ko.computed(() => { const capabilities = this.databaseAccount && this.databaseAccount()?.properties?.capabilities; if (!capabilities) { diff --git a/src/Explorer/Menus/CommandBar/CommandBarComponentAdapter.tsx b/src/Explorer/Menus/CommandBar/CommandBarComponentAdapter.tsx index 917470dd4..b45f5dc9d 100644 --- a/src/Explorer/Menus/CommandBar/CommandBarComponentAdapter.tsx +++ b/src/Explorer/Menus/CommandBar/CommandBarComponentAdapter.tsx @@ -29,7 +29,6 @@ export class CommandBarComponentAdapter implements ReactAdapter { // These are the parameters watched by the react binding that will trigger a renderComponent() if one of the ko mutates const toWatch = [ - container.isPreferredApiMongoDB, container.deleteCollectionText, container.deleteDatabaseText, container.addCollectionText, diff --git a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.test.ts b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.test.ts index 33fa59e0e..b692bdd38 100644 --- a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.test.ts +++ b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.test.ts @@ -23,7 +23,6 @@ describe("CommandBarComponentButtonFactory tests", () => { }, } as DatabaseAccount, }); - mockExplorer.isPreferredApiMongoDB = ko.computed(() => false); mockExplorer.isSparkEnabled = ko.observable(true); mockExplorer.isSynapseLinkUpdating = ko.observable(false); @@ -67,7 +66,6 @@ describe("CommandBarComponentButtonFactory tests", () => { }, } as DatabaseAccount, }); - mockExplorer.isPreferredApiMongoDB = ko.computed(() => false); mockExplorer.isSynapseLinkUpdating = ko.observable(false); mockExplorer.isSparkEnabled = ko.observable(true); mockExplorer.isSynapseLinkUpdating = ko.observable(false); @@ -128,6 +126,7 @@ describe("CommandBarComponentButtonFactory tests", () => { beforeAll(() => { mockExplorer = {} as Explorer; + mockExplorer.addDatabaseText = ko.observable("mockText"); mockExplorer.addCollectionText = ko.observable("mockText"); updateUserContext({ databaseAccount: { @@ -143,16 +142,25 @@ describe("CommandBarComponentButtonFactory tests", () => { mockExplorer.isServerlessEnabled = ko.computed(() => false); }); + afterAll(() => { + updateUserContext({ + apiType: "SQL", + }); + }); + beforeEach(() => { - mockExplorer.isPreferredApiMongoDB = ko.computed(() => true); + updateUserContext({ + apiType: "Mongo", + }); mockExplorer.isNotebookEnabled = ko.observable(false); mockExplorer.isNotebooksEnabledForAccount = ko.observable(false); mockExplorer.isRunningOnNationalCloud = ko.observable(false); }); it("Mongo Api not available - button should be hidden", () => { - mockExplorer.isPreferredApiMongoDB = ko.computed(() => false); - + updateUserContext({ + apiType: "SQL", + }); const buttons = CommandBarComponentButtonFactory.createStaticCommandBarButtons(mockExplorer); const openMongoShellBtn = buttons.find((button) => button.commandButtonLabel === openMongoShellBtnLabel); expect(openMongoShellBtn).toBeUndefined(); @@ -222,7 +230,6 @@ describe("CommandBarComponentButtonFactory tests", () => { }, } as DatabaseAccount, }); - mockExplorer.isPreferredApiMongoDB = ko.computed(() => false); mockExplorer.isSynapseLinkUpdating = ko.observable(false); mockExplorer.isSparkEnabled = ko.observable(true); @@ -321,7 +328,6 @@ describe("CommandBarComponentButtonFactory tests", () => { }, } as DatabaseAccount, }); - mockExplorer.isPreferredApiMongoDB = ko.computed(() => false); mockExplorer.isSynapseLinkUpdating = ko.observable(false); mockExplorer.isSparkEnabled = ko.observable(true); diff --git a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.tsx b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.tsx index 3f3533f66..151620d4a 100644 --- a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.tsx +++ b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.tsx @@ -70,7 +70,7 @@ export function createStaticCommandBarButtons(container: Explorer): CommandButto buttons.push(createEnableNotebooksButton(container)); } - if (container.isPreferredApiMongoDB()) { + if (userContext.apiType === "Mongo") { buttons.push(createOpenMongoTerminalButton(container)); } @@ -97,7 +97,7 @@ export function createStaticCommandBarButtons(container: Explorer): CommandButto } const isSupportedOpenQueryApi = - userContext.apiType === "SQL" || container.isPreferredApiMongoDB() || userContext.apiType === "Gremlin"; + userContext.apiType === "SQL" || userContext.apiType === "Mongo" || userContext.apiType === "Gremlin"; const isSupportedOpenQueryFromDiskApi = userContext.apiType === "SQL" || userContext.apiType === "Gremlin"; if (isSupportedOpenQueryApi && container.selectedNode() && container.findSelectedCollection()) { const openQueryBtn = createOpenQueryButton(container); @@ -133,7 +133,7 @@ export function createStaticCommandBarButtons(container: Explorer): CommandButto export function createContextCommandBarButtons(container: Explorer): CommandButtonComponentProps[] { const buttons: CommandButtonComponentProps[] = []; - if (!container.isDatabaseNodeOrNoneSelected() && container.isPreferredApiMongoDB()) { + if (!container.isDatabaseNodeOrNoneSelected() && userContext.apiType === "Mongo") { const label = "New Shell"; const newMongoShellBtn: CommandButtonComponentProps = { iconSrc: HostedTerminalIcon, @@ -145,7 +145,7 @@ export function createContextCommandBarButtons(container: Explorer): CommandButt commandButtonLabel: label, ariaLabel: label, hasPopup: true, - disabled: container.isDatabaseNodeOrNoneSelected() && container.isPreferredApiMongoDB(), + disabled: container.isDatabaseNodeOrNoneSelected() && userContext.apiType === "Mongo", }; buttons.push(newMongoShellBtn); } diff --git a/src/Explorer/Panes/AddCollectionPane.html b/src/Explorer/Panes/AddCollectionPane.html index 774915458..8f917cafd 100644 --- a/src/Explorer/Panes/AddCollectionPane.html +++ b/src/Explorer/Panes/AddCollectionPane.html @@ -251,10 +251,7 @@ -
+
* Storage capacity @@ -312,7 +309,7 @@
diff --git a/src/Explorer/Panes/AddCollectionPane.ts b/src/Explorer/Panes/AddCollectionPane.ts index ba2f93884..65e9e5f02 100644 --- a/src/Explorer/Panes/AddCollectionPane.ts +++ b/src/Explorer/Panes/AddCollectionPane.ts @@ -119,7 +119,7 @@ export default class AddCollectionPane extends ContextualPaneBase { this.isPreferredApiTable = options.isPreferredApiTable; this.partitionKey = ko.observable(); this.partitionKey.subscribe((newPartitionKey: string) => { - if (this.container.isPreferredApiMongoDB() || !newPartitionKey || newPartitionKey[0] === "/") { + if (userContext.apiType === "Mongo" || !newPartitionKey || newPartitionKey[0] === "/") { return; } @@ -354,7 +354,7 @@ export default class AddCollectionPane extends ContextualPaneBase { // TODO: Create derived classes for Tables and Mongo to replace the If statements below this.partitionKeyName = ko.computed(() => { - if (this.container && !!this.container.isPreferredApiMongoDB()) { + if (userContext.apiType === "Mongo") { return "Shard key"; } @@ -364,7 +364,7 @@ export default class AddCollectionPane extends ContextualPaneBase { this.lowerCasePartitionKeyName = ko.computed(() => this.partitionKeyName().toLowerCase()); this.partitionKeyPlaceholder = ko.computed(() => { - if (this.container && !!this.container.isPreferredApiMongoDB()) { + if (userContext.apiType === "Mongo") { return "e.g., address.zipCode"; } @@ -376,7 +376,7 @@ export default class AddCollectionPane extends ContextualPaneBase { }); this.uniqueKeysPlaceholder = ko.pureComputed(() => { - if (this.container && !!this.container.isPreferredApiMongoDB()) { + if (userContext.apiType === "Mongo") { return "Comma separated paths e.g. firstName,address.zipCode"; } @@ -396,11 +396,7 @@ export default class AddCollectionPane extends ContextualPaneBase { return false; } - if ( - this.container.isPreferredApiMongoDB() && - !this.isUnlimitedStorageSelected() && - this.databaseHasSharedOffer() - ) { + if (userContext.apiType === "Mongo" && !this.isUnlimitedStorageSelected() && this.databaseHasSharedOffer()) { return false; } @@ -589,7 +585,7 @@ export default class AddCollectionPane extends ContextualPaneBase { return true; } - if (this.container.isPreferredApiMongoDB()) { + if (userContext.apiType === "Mongo") { return true; } @@ -728,6 +724,10 @@ export default class AddCollectionPane extends ContextualPaneBase { } } + private isMongo(): boolean { + return userContext.apiType === "Mongo"; + } + private _onDatabasesChange(newDatabaseIds: ViewModels.Database[]) { this.databaseIds(newDatabaseIds?.map((database: ViewModels.Database) => database.id())); } @@ -810,7 +810,7 @@ export default class AddCollectionPane extends ContextualPaneBase { let indexingPolicy: DataModels.IndexingPolicy; let createMongoWildcardIndex: boolean; // todo - remove mongo indexing policy ticket # 616274 - if (this.container.isPreferredApiMongoDB() && this.container.isEnableMongoCapabilityPresent()) { + if (userContext.apiType === "Mongo" && this.container.isEnableMongoCapabilityPresent()) { createMongoWildcardIndex = this.shouldCreateMongoWildcardIndex(); } else if (this.showIndexingOptionsForSharedThroughput()) { if (this.useIndexingForSharedThroughput()) { @@ -1145,7 +1145,7 @@ export default class AddCollectionPane extends ContextualPaneBase { let transform = (value: string) => { return value; }; - if (this.container.isPreferredApiMongoDB()) { + if (userContext.apiType === "Mongo") { transform = (value: string) => { return this._convertShardKeyToPartitionKey(value); }; diff --git a/src/Explorer/Panes/SettingsPane/__snapshots__/SettingsPane.test.tsx.snap b/src/Explorer/Panes/SettingsPane/__snapshots__/SettingsPane.test.tsx.snap index 5915ca240..69f4ef1b7 100644 --- a/src/Explorer/Panes/SettingsPane/__snapshots__/SettingsPane.test.tsx.snap +++ b/src/Explorer/Panes/SettingsPane/__snapshots__/SettingsPane.test.tsx.snap @@ -434,7 +434,6 @@ exports[`Settings Pane should render Default properly 1`] = ` "isMongoIndexingEnabled": [Function], "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], - "isPreferredApiMongoDB": [Function], "isPublishNotebookPaneEnabled": [Function], "isResourceTokenCollectionNodeSelected": [Function], "isRightPanelV2Enabled": [Function], @@ -1073,7 +1072,6 @@ exports[`Settings Pane should render Gremlin properly 1`] = ` "isMongoIndexingEnabled": [Function], "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], - "isPreferredApiMongoDB": [Function], "isPublishNotebookPaneEnabled": [Function], "isResourceTokenCollectionNodeSelected": [Function], "isRightPanelV2Enabled": [Function], diff --git a/src/Explorer/Panes/StringInputPane/__snapshots__/StringInputPane.test.tsx.snap b/src/Explorer/Panes/StringInputPane/__snapshots__/StringInputPane.test.tsx.snap index e2ddc5c49..fbdc9fc80 100644 --- a/src/Explorer/Panes/StringInputPane/__snapshots__/StringInputPane.test.tsx.snap +++ b/src/Explorer/Panes/StringInputPane/__snapshots__/StringInputPane.test.tsx.snap @@ -437,7 +437,6 @@ exports[`StringInput Pane should render Create new directory properly 1`] = ` "isMongoIndexingEnabled": [Function], "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], - "isPreferredApiMongoDB": [Function], "isPublishNotebookPaneEnabled": [Function], "isResourceTokenCollectionNodeSelected": [Function], "isRightPanelV2Enabled": [Function], @@ -952,7 +951,6 @@ exports[`StringInput Pane should render Create new directory properly 1`] = ` "isMongoIndexingEnabled": [Function], "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], - "isPreferredApiMongoDB": [Function], "isPublishNotebookPaneEnabled": [Function], "isResourceTokenCollectionNodeSelected": [Function], "isRightPanelV2Enabled": [Function], diff --git a/src/Explorer/Panes/UploadItemsPane/__snapshots__/UploadItemsPane.test.tsx.snap b/src/Explorer/Panes/UploadItemsPane/__snapshots__/UploadItemsPane.test.tsx.snap index 9bb261343..fc59040bf 100644 --- a/src/Explorer/Panes/UploadItemsPane/__snapshots__/UploadItemsPane.test.tsx.snap +++ b/src/Explorer/Panes/UploadItemsPane/__snapshots__/UploadItemsPane.test.tsx.snap @@ -434,7 +434,6 @@ exports[`Upload Items Pane should render Default properly 1`] = ` "isMongoIndexingEnabled": [Function], "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], - "isPreferredApiMongoDB": [Function], "isPublishNotebookPaneEnabled": [Function], "isResourceTokenCollectionNodeSelected": [Function], "isRightPanelV2Enabled": [Function], diff --git a/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap b/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap index e4d8030b5..88da6e77a 100644 --- a/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap +++ b/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap @@ -437,7 +437,6 @@ exports[`Delete Database Confirmation Pane submit() Should call delete database "isMongoIndexingEnabled": [Function], "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], - "isPreferredApiMongoDB": [Function], "isPublishNotebookPaneEnabled": [Function], "isResourceTokenCollectionNodeSelected": [Function], "isRightPanelV2Enabled": [Function], diff --git a/src/Explorer/SplashScreen/SplashScreen.tsx b/src/Explorer/SplashScreen/SplashScreen.tsx index 85186f5c6..ca67d86dd 100644 --- a/src/Explorer/SplashScreen/SplashScreen.tsx +++ b/src/Explorer/SplashScreen/SplashScreen.tsx @@ -237,7 +237,7 @@ export class SplashScreen extends React.Component { title: "New SQL Query", description: null, }); - } else if (this.container.isPreferredApiMongoDB()) { + } else if (userContext.apiType === "Mongo") { items.push({ iconSrc: NewQueryIcon, onClick: () => { diff --git a/src/Explorer/Tabs/DocumentsTab.test.ts b/src/Explorer/Tabs/DocumentsTab.test.ts index 1d470f23a..8ebb6a8ad 100644 --- a/src/Explorer/Tabs/DocumentsTab.test.ts +++ b/src/Explorer/Tabs/DocumentsTab.test.ts @@ -1,10 +1,11 @@ import * as ko from "knockout"; -import * as ViewModels from "../../Contracts/ViewModels"; import * as Constants from "../../Common/Constants"; -import DocumentsTab from "./DocumentsTab"; +import * as ViewModels from "../../Contracts/ViewModels"; +import { updateUserContext } from "../../UserContext"; +import { CommandButtonComponentProps } from "../Controls/CommandButton/CommandButtonComponent"; import Explorer from "../Explorer"; import DocumentId from "../Tree/DocumentId"; -import { CommandButtonComponentProps } from "../Controls/CommandButton/CommandButtonComponent"; +import DocumentsTab from "./DocumentsTab"; describe("Documents tab", () => { describe("buildQuery", () => { @@ -25,7 +26,6 @@ describe("Documents tab", () => { describe("showPartitionKey", () => { const explorer = new Explorer(); - const mongoExplorer = new Explorer(); mongoExplorer.defaultExperience(Constants.DefaultAccountExperience.MongoDB); @@ -124,6 +124,9 @@ describe("Documents tab", () => { }); it("should be false for Mongo accounts with system partitionKey", () => { + updateUserContext({ + apiType: "Mongo", + }); const documentsTab = new DocumentsTab({ collection: mongoCollectionWithSystemPartitionKey, partitionKey: null, diff --git a/src/Explorer/Tabs/DocumentsTab.ts b/src/Explorer/Tabs/DocumentsTab.ts index 9f6cafcd4..1df03ae65 100644 --- a/src/Explorer/Tabs/DocumentsTab.ts +++ b/src/Explorer/Tabs/DocumentsTab.ts @@ -21,6 +21,7 @@ import * as DataModels from "../../Contracts/DataModels"; import * as ViewModels from "../../Contracts/ViewModels"; import { Action } from "../../Shared/Telemetry/TelemetryConstants"; import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; +import { userContext } from "../../UserContext"; import { logConsoleError } from "../../Utils/NotificationConsoleUtils"; import * as QueryUtils from "../../Utils/QueryUtils"; import { CommandButtonComponentProps } from "../Controls/CommandButton/CommandButtonComponent"; @@ -71,9 +72,7 @@ export default class DocumentsTab extends TabsBase { constructor(options: ViewModels.DocumentsTabOptions) { super(options); - this.isPreferredApiMongoDB = !!this.collection - ? this.collection.container.isPreferredApiMongoDB() - : options.isPreferredApiMongoDB; + this.isPreferredApiMongoDB = userContext.apiType === "Mongo" || options.isPreferredApiMongoDB; this.idHeader = this.isPreferredApiMongoDB ? "_id" : "id"; diff --git a/src/Explorer/Tree/Collection.test.ts b/src/Explorer/Tree/Collection.test.ts index d55342a0d..7e185ef4a 100644 --- a/src/Explorer/Tree/Collection.test.ts +++ b/src/Explorer/Tree/Collection.test.ts @@ -31,9 +31,6 @@ describe("Collection", () => { function generateMockCollectionWithDataModel(data: DataModels.Collection): Collection { const mockContainer = {} as Explorer; - mockContainer.isPreferredApiMongoDB = ko.computed(() => { - return false; - }); mockContainer.isDatabaseNodeOrNoneSelected = () => { return false; diff --git a/src/Explorer/Tree/Collection.ts b/src/Explorer/Tree/Collection.ts index 4335b56fe..6b129c053 100644 --- a/src/Explorer/Tree/Collection.ts +++ b/src/Explorer/Tree/Collection.ts @@ -127,16 +127,12 @@ export default class Collection implements ViewModels.Collection { this.partitionKey.paths[0]) || null; - if (!!container.isPreferredApiMongoDB() && this.partitionKeyProperty && ~this.partitionKeyProperty.indexOf(`"`)) { + if (userContext.apiType === "Mongo" && this.partitionKeyProperty && ~this.partitionKeyProperty.indexOf(`"`)) { this.partitionKeyProperty = this.partitionKeyProperty.replace(/["]+/g, ""); } // TODO #10738269 : Add this logic in a derived class for Mongo - if ( - !!container.isPreferredApiMongoDB() && - this.partitionKeyProperty && - this.partitionKeyProperty.indexOf("$v") > -1 - ) { + if (userContext.apiType === "Mongo" && this.partitionKeyProperty && this.partitionKeyProperty.indexOf("$v") > -1) { // From $v.shard.$v.key.$v > shard.key this.partitionKeyProperty = this.partitionKeyProperty.replace(/.\$v/g, "").replace(/\$v./g, ""); this.partitionKeyPropertyHeader = "/" + this.partitionKeyProperty; @@ -1123,7 +1119,7 @@ export default class Collection implements ViewModels.Collection { } else if (userContext.apiType === "Gremlin") { this.onGraphDocumentsClick(); return; - } else if (this.container.isPreferredApiMongoDB()) { + } else if (userContext.apiType === "Mongo") { this.onMongoDBDocumentsClick(); return; } @@ -1141,7 +1137,7 @@ export default class Collection implements ViewModels.Collection { return "Rows"; } else if (userContext.apiType === "Gremlin") { return "Graph"; - } else if (this.container.isPreferredApiMongoDB()) { + } else if (userContext.apiType === "Mongo") { return "Documents"; } diff --git a/src/RouteHandlers/TabRouteHandler.ts b/src/RouteHandlers/TabRouteHandler.ts index 06a8d03ef..6795fae8b 100644 --- a/src/RouteHandlers/TabRouteHandler.ts +++ b/src/RouteHandlers/TabRouteHandler.ts @@ -175,10 +175,7 @@ export class TabRouteHandler { databaseId, collectionId ); - collection && - collection.container && - collection.container.isPreferredApiMongoDB() && - collection.onMongoDBDocumentsClick(); + userContext.apiType === "Mongo" && collection.onMongoDBDocumentsClick(); }); } @@ -188,10 +185,7 @@ export class TabRouteHandler { databaseId, collectionId ); - collection && - collection.container && - collection.container.isPreferredApiMongoDB() && - collection.onSchemaAnalyzerClick(); + collection && userContext.apiType === "Mongo" && collection.onSchemaAnalyzerClick(); }); } @@ -228,10 +222,7 @@ export class TabRouteHandler { if (!!matchingTab) { matchingTab.onTabClick(); } else { - collection && - collection.container && - collection.container.isPreferredApiMongoDB() && - collection.onNewMongoQueryClick(collection, null); + userContext.apiType === "Mongo" && collection.onNewMongoQueryClick(collection, null); } }); } @@ -250,10 +241,7 @@ export class TabRouteHandler { if (!!matchingTab) { matchingTab.onTabClick(); } else { - collection && - collection.container && - collection.container.isPreferredApiMongoDB() && - collection.onNewMongoShellClick(); + userContext.apiType === "Mongo" && collection.onNewMongoShellClick(); } }); } diff --git a/src/UserContext.ts b/src/UserContext.ts index 46dfb4f0a..fc5a02d2c 100644 --- a/src/UserContext.ts +++ b/src/UserContext.ts @@ -21,7 +21,7 @@ interface UserContext { readonly quotaId?: string; // API Type is not yet provided by ARM. You need to manually inspect all the capabilities+kind so we abstract that logic in userContext // This is coming in a future Cosmos ARM API version as a prperty on databaseAccount - readonly apiType?: ApiType; + apiType?: ApiType; readonly isTryCosmosDBSubscription?: boolean; readonly portalEnv?: PortalEnv; readonly features: Features; @@ -47,8 +47,10 @@ const userContext: UserContext = { }; function updateUserContext(newContext: Partial): void { + if (newContext.databaseAccount) { + newContext.apiType = apiType(newContext.databaseAccount); + } Object.assign(userContext, newContext); - Object.assign(userContext, { apiType: apiType(userContext.databaseAccount) }); } function apiType(account: DatabaseAccount | undefined): ApiType {