diff --git a/src/Explorer/ContextMenuButtonFactory.ts b/src/Explorer/ContextMenuButtonFactory.ts index 42e23de6c..8337ec700 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 (userContext.apiType === "SQL" || container.isPreferredApiGraph()) { + if (userContext.apiType === "SQL" || userContext.apiType === "Gremlin") { items.push({ iconSrc: AddSqlQueryIcon, onClick: () => selectedCollection && selectedCollection.onNewQueryClick(selectedCollection, null), @@ -80,7 +80,7 @@ export class ResourceTreeContextMenuButtonFactory { }); } - if (userContext.apiType === "SQL" || container.isPreferredApiGraph()) { + if (userContext.apiType === "SQL" || userContext.apiType === "Gremlin") { items.push({ iconSrc: AddStoredProcedureIcon, onClick: () => { diff --git a/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap b/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap index 1b9c96a0e..db1ece0ab 100644 --- a/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap +++ b/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap @@ -647,7 +647,6 @@ exports[`SettingsComponent renders 1`] = ` "isMongoIndexingEnabled": [Function], "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], - "isPreferredApiGraph": [Function], "isPreferredApiMongoDB": [Function], "isPreferredApiTable": [Function], "isPublishNotebookPaneEnabled": [Function], @@ -1410,7 +1409,6 @@ exports[`SettingsComponent renders 1`] = ` "isMongoIndexingEnabled": [Function], "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], - "isPreferredApiGraph": [Function], "isPreferredApiMongoDB": [Function], "isPreferredApiTable": [Function], "isPublishNotebookPaneEnabled": [Function], @@ -2186,7 +2184,6 @@ exports[`SettingsComponent renders 1`] = ` "isMongoIndexingEnabled": [Function], "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], - "isPreferredApiGraph": [Function], "isPreferredApiMongoDB": [Function], "isPreferredApiTable": [Function], "isPublishNotebookPaneEnabled": [Function], @@ -2949,7 +2946,6 @@ exports[`SettingsComponent renders 1`] = ` "isMongoIndexingEnabled": [Function], "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], - "isPreferredApiGraph": [Function], "isPreferredApiMongoDB": [Function], "isPreferredApiTable": [Function], "isPublishNotebookPaneEnabled": [Function], diff --git a/src/Explorer/DataSamples/ContainerSampleGenerator.test.ts b/src/Explorer/DataSamples/ContainerSampleGenerator.test.ts index d59df695f..60308be0a 100644 --- a/src/Explorer/DataSamples/ContainerSampleGenerator.test.ts +++ b/src/Explorer/DataSamples/ContainerSampleGenerator.test.ts @@ -14,7 +14,6 @@ describe("ContainerSampleGenerator", () => { const createExplorerStub = (database: ViewModels.Database): Explorer => { const explorerStub = {} as Explorer; explorerStub.databases = ko.observableArray([database]); - explorerStub.isPreferredApiGraph = ko.computed(() => false); explorerStub.isPreferredApiMongoDB = ko.computed(() => false); explorerStub.isPreferredApiTable = ko.computed(() => false); explorerStub.canExceedMaximumValue = ko.computed(() => false); @@ -115,7 +114,13 @@ describe("ContainerSampleGenerator", () => { collection.databaseId = database.id(); const explorerStub = createExplorerStub(database); - explorerStub.isPreferredApiGraph = ko.computed(() => true); + updateUserContext({ + databaseAccount: { + properties: { + capabilities: [{ name: "EnableGremlin" }], + }, + } as DatabaseAccount, + }); const generator = await ContainerSampleGenerator.createSampleGeneratorAsync(explorerStub); generator.setData(sampleData); diff --git a/src/Explorer/DataSamples/ContainerSampleGenerator.ts b/src/Explorer/DataSamples/ContainerSampleGenerator.ts index 9e7c83fed..7d6b42453 100644 --- a/src/Explorer/DataSamples/ContainerSampleGenerator.ts +++ b/src/Explorer/DataSamples/ContainerSampleGenerator.ts @@ -73,7 +73,7 @@ export class ContainerSampleGenerator { } const promises: Q.Promise[] = []; - if (this.container.isPreferredApiGraph()) { + if (userContext.apiType === "Gremlin") { // For Gremlin, all queries are executed sequentially, because some queries might be dependent on other queries // (e.g. adding edge requires vertices to be present) const queries: string[] = this.sampleDataFile.data; diff --git a/src/Explorer/DataSamples/DataSamplesUtil.ts b/src/Explorer/DataSamples/DataSamplesUtil.ts index 284192c0e..809964352 100644 --- a/src/Explorer/DataSamples/DataSamplesUtil.ts +++ b/src/Explorer/DataSamples/DataSamplesUtil.ts @@ -57,6 +57,6 @@ export class DataSamplesUtil { } public isSampleContainerCreationSupported(): boolean { - return userContext.apiType === "SQL" || this.container.isPreferredApiGraph(); + return userContext.apiType === "SQL" || userContext.apiType === "Gremlin"; } } diff --git a/src/Explorer/Explorer.tsx b/src/Explorer/Explorer.tsx index e2465b6ce..474efdff2 100644 --- a/src/Explorer/Explorer.tsx +++ b/src/Explorer/Explorer.tsx @@ -121,11 +121,7 @@ export default class Explorer { * Compare a string with userContext.apiType instead: userContext.apiType === "Mongo" * */ public isPreferredApiMongoDB: ko.Computed; - /** - * @deprecated - * Compare a string with userContext.apiType instead: userContext.apiType === "Gremlin" - * */ - public isPreferredApiGraph: ko.Computed; + /** * @deprecated * Compare a string with userContext.apiType instead: userContext.apiType === "Tables" @@ -409,11 +405,6 @@ export default class Explorer { }); }); - this.isPreferredApiGraph = ko.computed(() => { - const defaultExperience = (this.defaultExperience && this.defaultExperience()) || ""; - return defaultExperience.toLowerCase() === Constants.DefaultAccountExperience.Graph.toLowerCase(); - }); - this.isPreferredApiTable = ko.computed(() => { const defaultExperience = (this.defaultExperience && this.defaultExperience()) || ""; return defaultExperience.toLowerCase() === Constants.DefaultAccountExperience.Table.toLowerCase(); @@ -477,7 +468,9 @@ export default class Explorer { this.isHostedDataExplorerEnabled = ko.computed( () => - configContext.platform === Platform.Portal && !this.isRunningOnNationalCloud() && !this.isPreferredApiGraph() + configContext.platform === Platform.Portal && + !this.isRunningOnNationalCloud() && + userContext.apiType !== "Gremlin" ); this.isRightPanelV2Enabled = ko.computed(() => userContext.features.enableRightPanelV2); this.selectedDatabaseId = ko.computed(() => { diff --git a/src/Explorer/Menus/CommandBar/CommandBarComponentAdapter.tsx b/src/Explorer/Menus/CommandBar/CommandBarComponentAdapter.tsx index 95b693429..65ff5e176 100644 --- a/src/Explorer/Menus/CommandBar/CommandBarComponentAdapter.tsx +++ b/src/Explorer/Menus/CommandBar/CommandBarComponentAdapter.tsx @@ -31,7 +31,6 @@ export class CommandBarComponentAdapter implements ReactAdapter { const toWatch = [ container.isPreferredApiTable, container.isPreferredApiMongoDB, - container.isPreferredApiGraph, container.deleteCollectionText, container.deleteDatabaseText, container.addCollectionText, diff --git a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.tsx b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.tsx index b8eca3193..5bf8c5885 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 = userContext.apiType === "SQL" || container.isPreferredApiGraph(); + const isSqlQuerySupported = userContext.apiType === "SQL" || userContext.apiType === "Gremlin"; if (isSqlQuerySupported) { const newSqlQueryBtn = createNewSQLQueryButton(container); buttons.push(newSqlQueryBtn); } const isSupportedOpenQueryApi = - userContext.apiType === "SQL" || container.isPreferredApiMongoDB() || container.isPreferredApiGraph(); - const isSupportedOpenQueryFromDiskApi = userContext.apiType === "SQL" || container.isPreferredApiGraph(); + userContext.apiType === "SQL" || container.isPreferredApiMongoDB() || userContext.apiType === "Gremlin"; + const isSupportedOpenQueryFromDiskApi = userContext.apiType === "SQL" || userContext.apiType === "Gremlin"; if (isSupportedOpenQueryApi && container.selectedNode() && container.findSelectedCollection()) { const openQueryBtn = createOpenQueryButton(container); openQueryBtn.children = [createOpenQueryButton(container), createOpenQueryFromDiskButton(container)]; @@ -107,7 +107,7 @@ export function createStaticCommandBarButtons(container: Explorer): CommandButto buttons.push(createOpenQueryFromDiskButton(container)); } - if (areScriptsSupported(container)) { + if (areScriptsSupported()) { const label = "New Stored Procedure"; const newStoredProcedureBtn: CommandButtonComponentProps = { iconSrc: AddStoredProcedureIcon, @@ -216,8 +216,8 @@ export function createDivider(): CommandButtonComponentProps { }; } -function areScriptsSupported(container: Explorer): boolean { - return userContext.apiType === "SQL" || container.isPreferredApiGraph(); +function areScriptsSupported(): boolean { + return userContext.apiType === "SQL" || userContext.apiType === "Gremlin"; } function createNewCollectionGroup(container: Explorer): CommandButtonComponentProps { @@ -325,8 +325,7 @@ function createNewSQLQueryButton(container: Explorer): CommandButtonComponentPro export function createScriptCommandButtons(container: Explorer): CommandButtonComponentProps[] { const buttons: CommandButtonComponentProps[] = []; - const shouldEnableScriptsCommands: boolean = - !container.isDatabaseNodeOrNoneSelected() && areScriptsSupported(container); + const shouldEnableScriptsCommands: boolean = !container.isDatabaseNodeOrNoneSelected() && areScriptsSupported(); if (shouldEnableScriptsCommands) { const label = "New Stored Procedure"; diff --git a/src/Explorer/Panes/AddCollectionPane.test.ts b/src/Explorer/Panes/AddCollectionPane.test.ts index 98fc2890d..887f8c5bb 100644 --- a/src/Explorer/Panes/AddCollectionPane.test.ts +++ b/src/Explorer/Panes/AddCollectionPane.test.ts @@ -1,7 +1,8 @@ import * as Constants from "../../Common/Constants"; -import AddCollectionPane from "./AddCollectionPane"; -import Explorer from "../Explorer"; import { DatabaseAccount } from "../../Contracts/DataModels"; +import { updateUserContext } from "../../UserContext"; +import Explorer from "../Explorer"; +import AddCollectionPane from "./AddCollectionPane"; describe("Add Collection Pane", () => { describe("isValid()", () => { @@ -50,7 +51,14 @@ describe("Add Collection Pane", () => { }); it("should be false if graph API and partition key is /id or /label", () => { - explorer.defaultExperience(Constants.DefaultAccountExperience.Graph.toLowerCase()); + updateUserContext({ + databaseAccount: { + properties: { + capabilities: [{ name: "EnableGremlin" }], + }, + } as DatabaseAccount, + }); + const addCollectionPane = explorer.addCollectionPane as AddCollectionPane; addCollectionPane.partitionKey("/id"); expect(addCollectionPane.isValid()).toBe(false); @@ -60,7 +68,13 @@ describe("Add Collection Pane", () => { }); it("should be true for any non-graph API with /id or /label partition key", () => { - explorer.defaultExperience(Constants.DefaultAccountExperience.DocumentDB.toLowerCase()); + updateUserContext({ + databaseAccount: { + properties: { + capabilities: [{ name: "EnableCassandra" }], + }, + } as DatabaseAccount, + }); const addCollectionPane = explorer.addCollectionPane as AddCollectionPane; addCollectionPane.partitionKey("/id"); diff --git a/src/Explorer/Panes/AddCollectionPane.ts b/src/Explorer/Panes/AddCollectionPane.ts index 383cecefa..1cddb72b1 100644 --- a/src/Explorer/Panes/AddCollectionPane.ts +++ b/src/Explorer/Panes/AddCollectionPane.ts @@ -127,13 +127,13 @@ export default class AddCollectionPane extends ContextualPaneBase { }); this.partitionKey.extend({ rateLimit: 100 }); this.partitionKeyPattern = ko.pureComputed(() => { - if (this.container && this.container.isPreferredApiGraph()) { + if (userContext.apiType === "Gremlin") { return "^/[^/]*"; } return ".*"; }); this.partitionKeyTitle = ko.pureComputed(() => { - if (this.container && this.container.isPreferredApiGraph()) { + if (userContext.apiType === "Gremlin") { return "May not use composite partition key"; } return ""; @@ -331,7 +331,7 @@ export default class AddCollectionPane extends ContextualPaneBase { if (currentCollections >= maxCollections) { let typeOfContainer = "collection"; - if (this.container.isPreferredApiGraph() || this.container.isPreferredApiTable()) { + if (userContext.apiType === "Gremlin" || this.container.isPreferredApiTable()) { typeOfContainer = "container"; } @@ -368,7 +368,7 @@ export default class AddCollectionPane extends ContextualPaneBase { return "e.g., address.zipCode"; } - if (this.container && !!this.container.isPreferredApiGraph()) { + if (userContext.apiType === "Gremlin") { return "e.g., /address"; } @@ -384,17 +384,11 @@ export default class AddCollectionPane extends ContextualPaneBase { }); this.uniqueKeysVisible = ko.pureComputed(() => { - if ( - this.container == null || - !!this.container.isPreferredApiMongoDB() || - !!this.container.isPreferredApiTable() || - userContext.apiType === "Cassandra" || - !!this.container.isPreferredApiGraph() - ) { - return false; + if (userContext.apiType === "SQL") { + return true; } - return true; + return false; }); this.partitionKeyVisible = ko.computed(() => { @@ -1011,7 +1005,7 @@ export default class AddCollectionPane extends ContextualPaneBase { return false; } - if (this.container.isPreferredApiGraph() && (this.partitionKey() === "/id" || this.partitionKey() === "/label")) { + if (userContext.apiType === "Gremlin" && (this.partitionKey() === "/id" || this.partitionKey() === "/label")) { this.formErrors("/id and /label as partition keys are not allowed for graph."); return false; } diff --git a/src/Explorer/Panes/SettingsPane/__snapshots__/index.test.tsx.snap b/src/Explorer/Panes/SettingsPane/__snapshots__/index.test.tsx.snap index a2f6f62c3..0cf982b10 100644 --- a/src/Explorer/Panes/SettingsPane/__snapshots__/index.test.tsx.snap +++ b/src/Explorer/Panes/SettingsPane/__snapshots__/index.test.tsx.snap @@ -623,7 +623,6 @@ exports[`Settings Pane should render Default properly 1`] = ` "isMongoIndexingEnabled": [Function], "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], - "isPreferredApiGraph": [Function], "isPreferredApiMongoDB": [Function], "isPreferredApiTable": [Function], "isPublishNotebookPaneEnabled": [Function], @@ -1509,7 +1508,6 @@ exports[`Settings Pane should render Gremlin properly 1`] = ` "isMongoIndexingEnabled": [Function], "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], - "isPreferredApiGraph": [Function], "isPreferredApiMongoDB": [Function], "isPreferredApiTable": [Function], "isPublishNotebookPaneEnabled": [Function], diff --git a/src/Explorer/Panes/UploadItemsPane/__snapshots__/index.test.tsx.snap b/src/Explorer/Panes/UploadItemsPane/__snapshots__/index.test.tsx.snap index c9f942b3f..64fee8529 100644 --- a/src/Explorer/Panes/UploadItemsPane/__snapshots__/index.test.tsx.snap +++ b/src/Explorer/Panes/UploadItemsPane/__snapshots__/index.test.tsx.snap @@ -623,7 +623,6 @@ exports[`Upload Items Pane should render Default properly 1`] = ` "isMongoIndexingEnabled": [Function], "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], - "isPreferredApiGraph": [Function], "isPreferredApiMongoDB": [Function], "isPreferredApiTable": [Function], "isPublishNotebookPaneEnabled": [Function], diff --git a/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap b/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap index 49215da65..69fa8c792 100644 --- a/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap +++ b/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap @@ -626,7 +626,6 @@ exports[`Delete Database Confirmation Pane submit() Should call delete database "isMongoIndexingEnabled": [Function], "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], - "isPreferredApiGraph": [Function], "isPreferredApiMongoDB": [Function], "isPreferredApiTable": [Function], "isPublishNotebookPaneEnabled": [Function], diff --git a/src/Explorer/SplashScreen/SplashScreen.tsx b/src/Explorer/SplashScreen/SplashScreen.tsx index 43fec912f..85186f5c6 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 (userContext.apiType === "SQL" || this.container.isPreferredApiGraph()) { + if (userContext.apiType === "SQL" || userContext.apiType === "Gremlin") { items.push({ iconSrc: NewQueryIcon, onClick: () => { diff --git a/src/Explorer/Tree/Collection.ts b/src/Explorer/Tree/Collection.ts index 58cffa72b..a876989e8 100644 --- a/src/Explorer/Tree/Collection.ts +++ b/src/Explorer/Tree/Collection.ts @@ -1087,7 +1087,7 @@ export default class Collection implements ViewModels.Collection { } else if (userContext.apiType === "Cassandra") { this.onTableEntitiesClick(); return; - } else if (this.container.isPreferredApiGraph()) { + } else if (userContext.apiType === "Gremlin") { this.onGraphDocumentsClick(); return; } else if (this.container.isPreferredApiMongoDB()) { @@ -1106,7 +1106,7 @@ export default class Collection implements ViewModels.Collection { return "Entities"; } else if (userContext.apiType === "Cassandra") { return "Rows"; - } else if (this.container.isPreferredApiGraph()) { + } else if (userContext.apiType === "Gremlin") { return "Graph"; } else if (this.container.isPreferredApiMongoDB()) { return "Documents"; diff --git a/src/Explorer/Tree/ResourceTreeAdapter.tsx b/src/Explorer/Tree/ResourceTreeAdapter.tsx index 9397675ad..b3f928497 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 userContext.apiType === "SQL" || container.isPreferredApiGraph(); + return userContext.apiType === "SQL" || userContext.apiType === "Gremlin"; } private buildCollectionNode(database: ViewModels.Database, collection: ViewModels.Collection): TreeNode { diff --git a/src/RouteHandlers/TabRouteHandler.ts b/src/RouteHandlers/TabRouteHandler.ts index fd2e38f1c..19a453c38 100644 --- a/src/RouteHandlers/TabRouteHandler.ts +++ b/src/RouteHandlers/TabRouteHandler.ts @@ -158,10 +158,7 @@ export class TabRouteHandler { databaseId, collectionId ); - collection && - collection.container && - collection.container.isPreferredApiGraph() && - collection.onGraphDocumentsClick(); + userContext.apiType === "Gremlin" && collection.onGraphDocumentsClick(); }); }