diff --git a/src/Explorer/ContextMenuButtonFactory.ts b/src/Explorer/ContextMenuButtonFactory.ts index 7f670d85a..deb55ef5c 100644 --- a/src/Explorer/ContextMenuButtonFactory.ts +++ b/src/Explorer/ContextMenuButtonFactory.ts @@ -55,7 +55,7 @@ export class ResourceTreeContextMenuButtonFactory { selectedCollection: ViewModels.Collection ): TreeNodeMenuItem[] { const items: TreeNodeMenuItem[] = []; - if (container.isPreferredApiDocumentDB() || container.isPreferredApiGraph()) { + if (userContext.apiType === "SQL" || container.isPreferredApiGraph()) { items.push({ iconSrc: AddSqlQueryIcon, onClick: () => selectedCollection && selectedCollection.onNewQueryClick(selectedCollection, null), @@ -80,7 +80,7 @@ export class ResourceTreeContextMenuButtonFactory { }); } - if (container.isPreferredApiDocumentDB() || container.isPreferredApiGraph()) { + if (userContext.apiType === "SQL" || container.isPreferredApiGraph()) { items.push({ iconSrc: AddStoredProcedureIcon, onClick: () => { diff --git a/src/Explorer/Controls/Settings/SettingsSubComponents/SubSettingsComponent.test.tsx b/src/Explorer/Controls/Settings/SettingsSubComponents/SubSettingsComponent.test.tsx index 9e6b3368b..ac36a4e60 100644 --- a/src/Explorer/Controls/Settings/SettingsSubComponents/SubSettingsComponent.test.tsx +++ b/src/Explorer/Controls/Settings/SettingsSubComponents/SubSettingsComponent.test.tsx @@ -1,14 +1,12 @@ import { shallow } from "enzyme"; -import React from "react"; -import { SubSettingsComponent, SubSettingsComponentProps } from "./SubSettingsComponent"; -import { container, collection } from "../TestUtils"; -import { TtlType, GeospatialConfigType, ChangeFeedPolicyState, TtlOnNoDefault, TtlOn, TtlOff } from "../SettingsUtils"; import ko from "knockout"; +import React from "react"; import Explorer from "../../../Explorer"; +import { ChangeFeedPolicyState, GeospatialConfigType, TtlOff, TtlOn, TtlOnNoDefault, TtlType } from "../SettingsUtils"; +import { collection, container } from "../TestUtils"; +import { SubSettingsComponent, SubSettingsComponentProps } from "./SubSettingsComponent"; describe("SubSettingsComponent", () => { - container.isPreferredApiDocumentDB = ko.computed(() => true); - const baseProps: SubSettingsComponentProps = { collection: collection, container: container, diff --git a/src/Explorer/Controls/Settings/SettingsSubComponents/SubSettingsComponent.tsx b/src/Explorer/Controls/Settings/SettingsSubComponents/SubSettingsComponent.tsx index 1f8133a35..124dcbbd2 100644 --- a/src/Explorer/Controls/Settings/SettingsSubComponents/SubSettingsComponent.tsx +++ b/src/Explorer/Controls/Settings/SettingsSubComponents/SubSettingsComponent.tsx @@ -1,28 +1,29 @@ +import { ChoiceGroup, IChoiceGroupOption, Label, MessageBar, Stack, Text, TextField } from "office-ui-fabric-react"; import * as React from "react"; import * as ViewModels from "../../../../Contracts/ViewModels"; -import { - GeospatialConfigType, - TtlType, - ChangeFeedPolicyState, - isDirty, - IsComponentDirtyResult, - TtlOn, - TtlOff, - TtlOnNoDefault, - getSanitizedInputValue, -} from "../SettingsUtils"; +import { userContext } from "../../../../UserContext"; import Explorer from "../../../Explorer"; import { Int32 } from "../../../Panes/Tables/Validators/EntityPropertyValidationCommon"; -import { Label, Text, TextField, Stack, IChoiceGroupOption, ChoiceGroup, MessageBar } from "office-ui-fabric-react"; import { - getTextFieldStyles, changeFeedPolicyToolTip, + getChoiceGroupStyles, + getTextFieldStyles, + messageBarStyles, subComponentStackProps, titleAndInputStackProps, - getChoiceGroupStyles, ttlWarning, - messageBarStyles, } from "../SettingsRenderUtils"; +import { + ChangeFeedPolicyState, + GeospatialConfigType, + getSanitizedInputValue, + IsComponentDirtyResult, + isDirty, + TtlOff, + TtlOn, + TtlOnNoDefault, + TtlType, +} from "../SettingsUtils"; import { ToolTipLabelComponent } from "./ToolTipLabelComponent"; export interface SubSettingsComponentProps { @@ -68,7 +69,7 @@ export class SubSettingsComponent extends React.Component { explorerStub.databases = ko.observableArray([database]); explorerStub.isPreferredApiGraph = ko.computed(() => false); explorerStub.isPreferredApiMongoDB = ko.computed(() => false); - explorerStub.isPreferredApiDocumentDB = ko.computed(() => false); explorerStub.isPreferredApiTable = ko.computed(() => false); explorerStub.isPreferredApiCassandra = ko.computed(() => false); explorerStub.canExceedMaximumValue = ko.computed(() => false); @@ -31,7 +31,7 @@ describe("ContainerSampleGenerator", () => { it("should insert documents for sql API account", async () => { const sampleCollectionId = "SampleCollection"; const sampleDatabaseId = "SampleDB"; - + updateUserContext({}); const sampleData = { databaseId: sampleDatabaseId, offerThroughput: 400, @@ -66,7 +66,7 @@ describe("ContainerSampleGenerator", () => { database.findCollectionWithId = () => collection; const explorerStub = createExplorerStub(database); - explorerStub.isPreferredApiDocumentDB = ko.computed(() => true); + const generator = await ContainerSampleGenerator.createSampleGeneratorAsync(explorerStub); generator.setData(sampleData); @@ -125,31 +125,46 @@ describe("ContainerSampleGenerator", () => { }); it("should not create any sample for Mongo API account", async () => { - const experience = "not supported api"; + const experience = "Sample generation not supported for this API Mongo"; const explorerStub = createExplorerStub(undefined); - explorerStub.isPreferredApiMongoDB = ko.computed(() => true); - explorerStub.defaultExperience = ko.observable(experience); + updateUserContext({ + databaseAccount: { + properties: { + capabilities: [{ name: "EnableMongo" }], + }, + } as DatabaseAccount, + }); // Rejects with error that contains experience expect(ContainerSampleGenerator.createSampleGeneratorAsync(explorerStub)).rejects.toMatch(experience); }); it("should not create any sample for Table API account", async () => { - const experience = "not supported api"; + const experience = "Sample generation not supported for this API Tables"; const explorerStub = createExplorerStub(undefined); - explorerStub.isPreferredApiTable = ko.computed(() => true); - explorerStub.defaultExperience = ko.observable(experience); + updateUserContext({ + databaseAccount: { + properties: { + capabilities: [{ name: "EnableTable" }], + }, + } as DatabaseAccount, + }); // Rejects with error that contains experience await expect(ContainerSampleGenerator.createSampleGeneratorAsync(explorerStub)).rejects.toMatch(experience); }); it("should not create any sample for Cassandra API account", async () => { - const experience = "not supported api"; + const experience = "Sample generation not supported for this API Cassandra"; const explorerStub = createExplorerStub(undefined); - explorerStub.isPreferredApiCassandra = ko.computed(() => true); - explorerStub.defaultExperience = ko.observable(experience); + updateUserContext({ + databaseAccount: { + properties: { + capabilities: [{ name: "EnableCassandra" }], + }, + } as DatabaseAccount, + }); // Rejects with error that contains experience await expect(ContainerSampleGenerator.createSampleGeneratorAsync(explorerStub)).rejects.toMatch(experience); }); diff --git a/src/Explorer/DataSamples/ContainerSampleGenerator.ts b/src/Explorer/DataSamples/ContainerSampleGenerator.ts index 6c1270a83..9e7c83fed 100644 --- a/src/Explorer/DataSamples/ContainerSampleGenerator.ts +++ b/src/Explorer/DataSamples/ContainerSampleGenerator.ts @@ -1,12 +1,12 @@ -import * as DataModels from "../../Contracts/DataModels"; -import * as ViewModels from "../../Contracts/ViewModels"; -import GraphTab from ".././Tabs/GraphTab"; -import { GremlinClient } from "../Graph/GraphExplorerComponent/GremlinClient"; -import * as NotificationConsoleUtils from "../../Utils/NotificationConsoleUtils"; -import Explorer from "../Explorer"; import { createCollection } from "../../Common/dataAccess/createCollection"; import { createDocument } from "../../Common/dataAccess/createDocument"; +import * as DataModels from "../../Contracts/DataModels"; +import * as ViewModels from "../../Contracts/ViewModels"; import { userContext } from "../../UserContext"; +import * as NotificationConsoleUtils from "../../Utils/NotificationConsoleUtils"; +import GraphTab from ".././Tabs/GraphTab"; +import Explorer from "../Explorer"; +import { GremlinClient } from "../Graph/GraphExplorerComponent/GremlinClient"; interface SampleDataFile extends DataModels.CreateCollectionParams { data: any[]; @@ -23,16 +23,16 @@ export class ContainerSampleGenerator { public static async createSampleGeneratorAsync(container: Explorer): Promise { const generator = new ContainerSampleGenerator(container); let dataFileContent: any; - if (container.isPreferredApiGraph()) { + if (userContext.apiType === "Gremlin") { dataFileContent = await import( /* webpackChunkName: "gremlinSampleJsonData" */ "../../../sampleData/gremlinSampleData.json" ); - } else if (container.isPreferredApiDocumentDB()) { + } else if (userContext.apiType === "SQL") { dataFileContent = await import( /* webpackChunkName: "sqlSampleJsonData" */ "../../../sampleData/sqlSampleData.json" ); } else { - return Promise.reject(`Sample generation not supported for this API ${container.defaultExperience()}`); + return Promise.reject(`Sample generation not supported for this API ${userContext.apiType}`); } generator.setData(dataFileContent); diff --git a/src/Explorer/DataSamples/DataSamplesUtil.ts b/src/Explorer/DataSamples/DataSamplesUtil.ts index aa3d01253..284192c0e 100644 --- a/src/Explorer/DataSamples/DataSamplesUtil.ts +++ b/src/Explorer/DataSamples/DataSamplesUtil.ts @@ -1,4 +1,5 @@ import * as ViewModels from "../../Contracts/ViewModels"; +import { userContext } from "../../UserContext"; import * as NotificationConsoleUtils from "../../Utils/NotificationConsoleUtils"; import Explorer from "../Explorer"; import { ConsoleDataType } from "../Menus/NotificationConsole/NotificationConsoleComponent"; @@ -56,6 +57,6 @@ export class DataSamplesUtil { } public isSampleContainerCreationSupported(): boolean { - return this.container.isPreferredApiDocumentDB() || this.container.isPreferredApiGraph(); + return userContext.apiType === "SQL" || this.container.isPreferredApiGraph(); } } diff --git a/src/Explorer/Explorer.tsx b/src/Explorer/Explorer.tsx index d49379ca4..6883ab29c 100644 --- a/src/Explorer/Explorer.tsx +++ b/src/Explorer/Explorer.tsx @@ -116,11 +116,6 @@ export default class Explorer { * Use userContext.apiType instead * */ public defaultExperience: ko.Observable; - /** - * @deprecated - * Compare a string with userContext.apiType instead: userContext.apiType === "SQL" - * */ - public isPreferredApiDocumentDB: ko.Computed; /** * @deprecated * Compare a string with userContext.apiType instead: userContext.apiType === "Cassandra" @@ -419,11 +414,6 @@ export default class Explorer { }); }); - this.isPreferredApiDocumentDB = ko.computed(() => { - const defaultExperience = (this.defaultExperience && this.defaultExperience()) || ""; - return defaultExperience.toLowerCase() === Constants.DefaultAccountExperience.DocumentDB.toLowerCase(); - }); - this.isPreferredApiCassandra = ko.computed(() => { const defaultExperience = (this.defaultExperience && this.defaultExperience()) || ""; return defaultExperience.toLowerCase() === Constants.DefaultAccountExperience.Cassandra.toLowerCase(); diff --git a/src/Explorer/Menus/CommandBar/CommandBarComponentAdapter.tsx b/src/Explorer/Menus/CommandBar/CommandBarComponentAdapter.tsx index 1afce01fb..c80e0bf70 100644 --- a/src/Explorer/Menus/CommandBar/CommandBarComponentAdapter.tsx +++ b/src/Explorer/Menus/CommandBar/CommandBarComponentAdapter.tsx @@ -4,15 +4,15 @@ * and update any knockout observables passed from the parent. */ import * as ko from "knockout"; +import { CommandBar, ICommandBarItemProps } from "office-ui-fabric-react/lib/CommandBar"; import * as React from "react"; import { ReactAdapter } from "../../../Bindings/ReactBindingHandler"; -import * as ViewModels from "../../../Contracts/ViewModels"; -import * as CommandBarComponentButtonFactory from "./CommandBarComponentButtonFactory"; -import { CommandBar, ICommandBarItemProps } from "office-ui-fabric-react/lib/CommandBar"; import { StyleConstants } from "../../../Common/Constants"; -import * as CommandBarUtil from "./CommandBarUtil"; -import Explorer from "../../Explorer"; +import * as ViewModels from "../../../Contracts/ViewModels"; import { CommandButtonComponentProps } from "../../Controls/CommandButton/CommandButtonComponent"; +import Explorer from "../../Explorer"; +import * as CommandBarComponentButtonFactory from "./CommandBarComponentButtonFactory"; +import * as CommandBarUtil from "./CommandBarUtil"; export class CommandBarComponentAdapter implements ReactAdapter { public parameters: ko.Observable; @@ -31,7 +31,6 @@ export class CommandBarComponentAdapter implements ReactAdapter { const toWatch = [ container.isPreferredApiTable, container.isPreferredApiMongoDB, - container.isPreferredApiDocumentDB, container.isPreferredApiCassandra, container.isPreferredApiGraph, container.deleteCollectionText, diff --git a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.test.ts b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.test.ts index 450f79d26..a4874f0e3 100644 --- a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.test.ts +++ b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.test.ts @@ -337,7 +337,6 @@ describe("CommandBarComponentButtonFactory tests", () => { beforeAll(() => { mockExplorer = {} as Explorer; mockExplorer.addCollectionText = ko.observable("mockText"); - mockExplorer.isPreferredApiDocumentDB = ko.computed(() => true); mockExplorer.isDatabaseNodeOrNoneSelected = () => true; mockExplorer.isResourceTokenCollectionNodeSelected = ko.computed(() => true); mockExplorer.isServerlessEnabled = ko.computed(() => false); diff --git a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.tsx b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.tsx index fcb380fe4..7ba6f8645 100644 --- a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.tsx +++ b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.tsx @@ -90,15 +90,15 @@ export function createStaticCommandBarButtons(container: Explorer): CommandButto buttons.push(createDivider()); } - const isSqlQuerySupported = container.isPreferredApiDocumentDB() || container.isPreferredApiGraph(); + const isSqlQuerySupported = userContext.apiType === "SQL" || container.isPreferredApiGraph(); if (isSqlQuerySupported) { const newSqlQueryBtn = createNewSQLQueryButton(container); buttons.push(newSqlQueryBtn); } const isSupportedOpenQueryApi = - container.isPreferredApiDocumentDB() || container.isPreferredApiMongoDB() || container.isPreferredApiGraph(); - const isSupportedOpenQueryFromDiskApi = container.isPreferredApiDocumentDB() || container.isPreferredApiGraph(); + userContext.apiType === "SQL" || container.isPreferredApiMongoDB() || container.isPreferredApiGraph(); + const isSupportedOpenQueryFromDiskApi = userContext.apiType === "SQL" || container.isPreferredApiGraph(); if (isSupportedOpenQueryApi && container.selectedNode() && container.findSelectedCollection()) { const openQueryBtn = createOpenQueryButton(container); openQueryBtn.children = [createOpenQueryButton(container), createOpenQueryFromDiskButton(container)]; @@ -217,7 +217,7 @@ export function createDivider(): CommandButtonComponentProps { } function areScriptsSupported(container: Explorer): boolean { - return container.isPreferredApiDocumentDB() || container.isPreferredApiGraph(); + return userContext.apiType === "SQL" || container.isPreferredApiGraph(); } function createNewCollectionGroup(container: Explorer): CommandButtonComponentProps { @@ -289,7 +289,7 @@ function createNewDatabase(container: Explorer): CommandButtonComponentProps { } function createNewSQLQueryButton(container: Explorer): CommandButtonComponentProps { - if (container.isPreferredApiDocumentDB() || container.isPreferredApiGraph()) { + if (userContext.apiType === "SQL" || container.isPreferredApiGraph()) { const label = "New SQL Query"; return { iconSrc: AddSqlQueryIcon, diff --git a/src/Explorer/Panes/AddCollectionPane.ts b/src/Explorer/Panes/AddCollectionPane.ts index 611a1a95c..68303780d 100644 --- a/src/Explorer/Panes/AddCollectionPane.ts +++ b/src/Explorer/Panes/AddCollectionPane.ts @@ -591,7 +591,7 @@ export default class AddCollectionPane extends ContextualPaneBase { return false; } - if (this.container.isPreferredApiDocumentDB()) { + if (userContext.apiType === "SQL") { return true; } diff --git a/src/Explorer/Panes/SettingsPane/__snapshots__/index.test.tsx.snap b/src/Explorer/Panes/SettingsPane/__snapshots__/index.test.tsx.snap index e98c45c59..5ff1069fc 100644 --- a/src/Explorer/Panes/SettingsPane/__snapshots__/index.test.tsx.snap +++ b/src/Explorer/Panes/SettingsPane/__snapshots__/index.test.tsx.snap @@ -624,7 +624,6 @@ exports[`Settings Pane should render Default properly 1`] = ` "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], "isPreferredApiCassandra": [Function], - "isPreferredApiDocumentDB": [Function], "isPreferredApiGraph": [Function], "isPreferredApiMongoDB": [Function], "isPreferredApiTable": [Function], @@ -762,6 +761,41 @@ exports[`Settings Pane should render Default properly 1`] = `
+
+
+
+ Page options + + Choose Custom to specify a fixed amount of query results to show, or choose Unlimited to show as many query results per page. + +
+ +
+
+
@@ -1477,7 +1511,6 @@ exports[`Settings Pane should render Gremlin properly 1`] = ` "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], "isPreferredApiCassandra": [Function], - "isPreferredApiDocumentDB": [Function], "isPreferredApiGraph": [Function], "isPreferredApiMongoDB": [Function], "isPreferredApiTable": [Function], diff --git a/src/Explorer/Panes/UploadItemsPane/__snapshots__/index.test.tsx.snap b/src/Explorer/Panes/UploadItemsPane/__snapshots__/index.test.tsx.snap index f7b978379..730283b1e 100644 --- a/src/Explorer/Panes/UploadItemsPane/__snapshots__/index.test.tsx.snap +++ b/src/Explorer/Panes/UploadItemsPane/__snapshots__/index.test.tsx.snap @@ -624,7 +624,6 @@ exports[`Upload Items Pane should render Default properly 1`] = ` "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], "isPreferredApiCassandra": [Function], - "isPreferredApiDocumentDB": [Function], "isPreferredApiGraph": [Function], "isPreferredApiMongoDB": [Function], "isPreferredApiTable": [Function], diff --git a/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap b/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap index b8a9c0dec..10241dd3c 100644 --- a/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap +++ b/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap @@ -627,7 +627,6 @@ exports[`Delete Database Confirmation Pane submit() Should call delete database "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], "isPreferredApiCassandra": [Function], - "isPreferredApiDocumentDB": [Function], "isPreferredApiGraph": [Function], "isPreferredApiMongoDB": [Function], "isPreferredApiTable": [Function], diff --git a/src/Explorer/SplashScreen/SplashScreen.tsx b/src/Explorer/SplashScreen/SplashScreen.tsx index e5debb883..541e6094f 100644 --- a/src/Explorer/SplashScreen/SplashScreen.tsx +++ b/src/Explorer/SplashScreen/SplashScreen.tsx @@ -227,7 +227,7 @@ export class SplashScreen extends React.Component { } if (!this.container.isDatabaseNodeOrNoneSelected()) { - if (this.container.isPreferredApiDocumentDB() || this.container.isPreferredApiGraph()) { + if (userContext.apiType === "SQL" || this.container.isPreferredApiGraph()) { items.push({ iconSrc: NewQueryIcon, onClick: () => { diff --git a/src/Explorer/Tabs/QueryTab.test.ts b/src/Explorer/Tabs/QueryTab.test.ts index b9a6cf042..2e588a99d 100644 --- a/src/Explorer/Tabs/QueryTab.test.ts +++ b/src/Explorer/Tabs/QueryTab.test.ts @@ -1,9 +1,10 @@ import * as ko from "knockout"; -import * as Constants from "../../Common/Constants"; +import { DatabaseAccount } from "../../Contracts/DataModels"; import * as ViewModels from "../../Contracts/ViewModels"; +import { updateUserContext } from "../../UserContext"; +import { CommandButtonComponentProps } from "../Controls/CommandButton/CommandButtonComponent"; import Explorer from "../Explorer"; import QueryTab from "./QueryTab"; -import { CommandButtonComponentProps } from "../Controls/CommandButton/CommandButtonComponent"; describe("Query Tab", () => { function getNewQueryTabForContainer(container: Explorer): QueryTab { @@ -52,13 +53,19 @@ describe("Query Tab", () => { }); it("should be true for accounts using SQL API", () => { - explorer.defaultExperience(Constants.DefaultAccountExperience.DocumentDB.toLowerCase()); + updateUserContext({}); const queryTab = getNewQueryTabForContainer(explorer); expect(queryTab.isQueryMetricsEnabled()).toBe(true); }); it("should be false for accounts using other APIs", () => { - explorer.defaultExperience(Constants.DefaultAccountExperience.Graph.toLowerCase()); + updateUserContext({ + databaseAccount: { + properties: { + capabilities: [{ name: "EnableGremlin" }], + }, + } as DatabaseAccount, + }); const queryTab = getNewQueryTabForContainer(explorer); expect(queryTab.isQueryMetricsEnabled()).toBe(false); }); @@ -72,13 +79,19 @@ describe("Query Tab", () => { }); it("should be visible when using a supported API", () => { - explorer.defaultExperience(Constants.DefaultAccountExperience.DocumentDB); + updateUserContext({}); const queryTab = getNewQueryTabForContainer(explorer); expect(queryTab.saveQueryButton.visible()).toBe(true); }); it("should not be visible when using an unsupported API", () => { - explorer.defaultExperience(Constants.DefaultAccountExperience.MongoDB); + updateUserContext({ + databaseAccount: { + properties: { + capabilities: [{ name: "EnableMongo" }], + }, + } as DatabaseAccount, + }); const queryTab = getNewQueryTabForContainer(explorer); expect(queryTab.saveQueryButton.visible()).toBe(false); }); diff --git a/src/Explorer/Tabs/QueryTab.ts b/src/Explorer/Tabs/QueryTab.ts index a11de7e16..fc1132242 100644 --- a/src/Explorer/Tabs/QueryTab.ts +++ b/src/Explorer/Tabs/QueryTab.ts @@ -13,6 +13,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 * as QueryUtils from "../../Utils/QueryUtils"; import { CommandButtonComponentProps } from "../Controls/CommandButton/CommandButtonComponent"; import template from "./QueryTab.html"; @@ -95,9 +96,7 @@ export default class QueryTab extends TabsBase implements ViewModels.WaitsForTem this.aggregatedQueryMetrics(this._aggregateQueryMetrics(metrics)) ); this.isQueryMetricsEnabled = ko.computed(() => { - return ( - (this.collection && this.collection.container && this.collection.container.isPreferredApiDocumentDB()) || false - ); + return userContext.apiType === "SQL" || false; }); this.activityId = ko.observable(); this.roundTrips = ko.observable(); @@ -117,7 +116,7 @@ export default class QueryTab extends TabsBase implements ViewModels.WaitsForTem this._isSaveQueriesEnabled = ko.computed(() => { const container = this.collection && this.collection.container; - return (container && (container.isPreferredApiDocumentDB() || container.isPreferredApiGraph())) || false; + return userContext.apiType === "SQL" || userContext.apiType === "Gremlin"; }); this.maybeSubQuery = ko.computed(function () { diff --git a/src/Explorer/Tree/Collection.test.ts b/src/Explorer/Tree/Collection.test.ts index ff7090dba..7ee9f890d 100644 --- a/src/Explorer/Tree/Collection.test.ts +++ b/src/Explorer/Tree/Collection.test.ts @@ -1,8 +1,7 @@ -import * as DataModels from "../../Contracts/DataModels"; import * as ko from "knockout"; -import * as ViewModels from "../../Contracts/ViewModels"; -import Collection from "./Collection"; +import * as DataModels from "../../Contracts/DataModels"; import Explorer from "../Explorer"; +import Collection from "./Collection"; jest.mock("monaco-editor"); describe("Collection", () => { @@ -41,12 +40,7 @@ describe("Collection", () => { mockContainer.isDatabaseNodeOrNoneSelected = () => { return false; }; - mockContainer.isPreferredApiDocumentDB = ko.computed(() => { - return true; - }); - mockContainer.isPreferredApiGraph = ko.computed(() => { - return false; - }); + mockContainer.deleteCollectionText = ko.observable("delete collection"); return generateCollection(mockContainer, "abc", data, {} as DataModels.Offer); diff --git a/src/Explorer/Tree/Collection.ts b/src/Explorer/Tree/Collection.ts index 49945b22c..e3f0830ed 100644 --- a/src/Explorer/Tree/Collection.ts +++ b/src/Explorer/Tree/Collection.ts @@ -196,7 +196,7 @@ export default class Collection implements ViewModels.Collection { .map((node) => node); }); - const showScriptsMenus: boolean = container.isPreferredApiDocumentDB() || container.isPreferredApiGraph(); + const showScriptsMenus: boolean = userContext.apiType === "SQL" || userContext.apiType === "Gremlin"; this.showStoredProcedures = ko.observable(showScriptsMenus); this.showTriggers = ko.observable(showScriptsMenus); this.showUserDefinedFunctions = ko.observable(showScriptsMenus); diff --git a/src/Explorer/Tree/ResourceTreeAdapter.tsx b/src/Explorer/Tree/ResourceTreeAdapter.tsx index 47b5d45c3..13ba398ce 100644 --- a/src/Explorer/Tree/ResourceTreeAdapter.tsx +++ b/src/Explorer/Tree/ResourceTreeAdapter.tsx @@ -253,7 +253,7 @@ export class ResourceTreeAdapter implements ReactAdapter { * @param container */ private static showScriptNodes(container: Explorer): boolean { - return container.isPreferredApiDocumentDB() || container.isPreferredApiGraph(); + return userContext.apiType === "SQL" || container.isPreferredApiGraph(); } private buildCollectionNode(database: ViewModels.Database, collection: ViewModels.Collection): TreeNode { diff --git a/src/RouteHandlers/TabRouteHandler.ts b/src/RouteHandlers/TabRouteHandler.ts index 9cb2d8ad8..784a84601 100644 --- a/src/RouteHandlers/TabRouteHandler.ts +++ b/src/RouteHandlers/TabRouteHandler.ts @@ -5,6 +5,7 @@ import * as Constants from "../Common/Constants"; import * as ViewModels from "../Contracts/ViewModels"; import ScriptTabBase from "../Explorer/Tabs/ScriptTabBase"; import TabsBase from "../Explorer/Tabs/TabsBase"; +import { userContext } from "../UserContext"; export class TabRouteHandler { private _tabRouter: any; @@ -134,10 +135,7 @@ export class TabRouteHandler { databaseId, collectionId ); - collection && - collection.container && - collection.container.isPreferredApiDocumentDB() && - collection.onDocumentDBDocumentsClick(); + userContext.apiType === "SQL" && collection.onDocumentDBDocumentsClick(); }); } diff --git a/src/UserContext.ts b/src/UserContext.ts index d27c130af..46dfb4f0a 100644 --- a/src/UserContext.ts +++ b/src/UserContext.ts @@ -36,6 +36,7 @@ const features = extractFeatures(); const { enableSDKoperations: useSDKOperations } = features; const userContext: UserContext = { + apiType: "SQL", hasWriteAccess: true, isTryCosmosDBSubscription: false, portalEnv: "prod",