From 9d411c57b0a9da3344f6d31c5b8340582f48dcb7 Mon Sep 17 00:00:00 2001 From: Hardikkumar Nai <80053762+hardiknai-techm@users.noreply.github.com> Date: Thu, 22 Apr 2021 03:11:08 +0530 Subject: [PATCH] Remove Explorer.isPreferredApiTable (#656) Co-authored-by: Steve Faulkner --- .../SubSettingsComponent.tsx | 2 +- .../SettingsComponent.test.tsx.snap | 4 -- .../ContainerSampleGenerator.test.ts | 1 - src/Explorer/Explorer.tsx | 13 +----- .../CommandBar/CommandBarComponentAdapter.tsx | 1 - .../CommandBarComponentButtonFactory.test.ts | 42 ++++++++++++++++--- .../CommandBarComponentButtonFactory.tsx | 2 +- src/Explorer/Panes/AddCollectionPane.ts | 10 ++--- .../__snapshots__/SettingsPane.test.tsx.snap | 2 - .../Panes/Tables/EditTableEntityPane.ts | 2 +- .../UploadItemsPane.test.tsx.snap | 1 - ...eteDatabaseConfirmationPanel.test.tsx.snap | 1 - src/Explorer/Tabs/QueryTablesTab.ts | 2 +- src/Explorer/Tree/Collection.ts | 4 +- src/RouteHandlers/TabRouteHandler.ts | 2 +- 15 files changed, 50 insertions(+), 39 deletions(-) diff --git a/src/Explorer/Controls/Settings/SettingsSubComponents/SubSettingsComponent.tsx b/src/Explorer/Controls/Settings/SettingsSubComponents/SubSettingsComponent.tsx index 5f05edd75..14947f81c 100644 --- a/src/Explorer/Controls/Settings/SettingsSubComponents/SubSettingsComponent.tsx +++ b/src/Explorer/Controls/Settings/SettingsSubComponents/SubSettingsComponent.tsx @@ -321,7 +321,7 @@ export class SubSettingsComponent extends React.Component { if ( userContext.apiType === "Cassandra" || - this.props.container.isPreferredApiTable() || + userContext.apiType === "Tables" || !this.props.collection.partitionKeyProperty || (this.props.container.isPreferredApiMongoDB() && this.props.collection.partitionKey.systemKey) ) { diff --git a/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap b/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap index 893360470..c3778fdf3 100644 --- a/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap +++ b/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap @@ -561,7 +561,6 @@ exports[`SettingsComponent renders 1`] = ` "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], "isPreferredApiMongoDB": [Function], - "isPreferredApiTable": [Function], "isPublishNotebookPaneEnabled": [Function], "isResourceTokenCollectionNodeSelected": [Function], "isRightPanelV2Enabled": [Function], @@ -1222,7 +1221,6 @@ exports[`SettingsComponent renders 1`] = ` "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], "isPreferredApiMongoDB": [Function], - "isPreferredApiTable": [Function], "isPublishNotebookPaneEnabled": [Function], "isResourceTokenCollectionNodeSelected": [Function], "isRightPanelV2Enabled": [Function], @@ -1896,7 +1894,6 @@ exports[`SettingsComponent renders 1`] = ` "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], "isPreferredApiMongoDB": [Function], - "isPreferredApiTable": [Function], "isPublishNotebookPaneEnabled": [Function], "isResourceTokenCollectionNodeSelected": [Function], "isRightPanelV2Enabled": [Function], @@ -2557,7 +2554,6 @@ exports[`SettingsComponent renders 1`] = ` "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], "isPreferredApiMongoDB": [Function], - "isPreferredApiTable": [Function], "isPublishNotebookPaneEnabled": [Function], "isResourceTokenCollectionNodeSelected": [Function], "isRightPanelV2Enabled": [Function], diff --git a/src/Explorer/DataSamples/ContainerSampleGenerator.test.ts b/src/Explorer/DataSamples/ContainerSampleGenerator.test.ts index 60308be0a..3b81ff56a 100644 --- a/src/Explorer/DataSamples/ContainerSampleGenerator.test.ts +++ b/src/Explorer/DataSamples/ContainerSampleGenerator.test.ts @@ -15,7 +15,6 @@ describe("ContainerSampleGenerator", () => { const explorerStub = {} as Explorer; explorerStub.databases = ko.observableArray([database]); explorerStub.isPreferredApiMongoDB = ko.computed(() => false); - explorerStub.isPreferredApiTable = 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 42e3f2fbf..1341474eb 100644 --- a/src/Explorer/Explorer.tsx +++ b/src/Explorer/Explorer.tsx @@ -124,12 +124,6 @@ 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 === "Tables" - * */ - public isPreferredApiTable: ko.Computed; public isFixedCollectionWithSharedThroughputSupported: ko.Computed; /** * @deprecated @@ -402,11 +396,6 @@ export default class Explorer { }); }); - this.isPreferredApiTable = ko.computed(() => { - const defaultExperience = (this.defaultExperience && this.defaultExperience()) || ""; - return defaultExperience.toLowerCase() === Constants.DefaultAccountExperience.Table.toLowerCase(); - }); - this.isFixedCollectionWithSharedThroughputSupported = ko.computed(() => { if (userContext.features.enableFixedCollectionWithSharedThroughput) { return true; @@ -499,7 +488,7 @@ export default class Explorer { }); this.addCollectionPane = new AddCollectionPane({ - isPreferredApiTable: ko.computed(() => this.isPreferredApiTable()), + isPreferredApiTable: ko.computed(() => userContext.apiType === "Tables"), id: "addcollectionpane", visible: ko.observable(false), diff --git a/src/Explorer/Menus/CommandBar/CommandBarComponentAdapter.tsx b/src/Explorer/Menus/CommandBar/CommandBarComponentAdapter.tsx index d93407c22..917470dd4 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.isPreferredApiTable, container.isPreferredApiMongoDB, container.deleteCollectionText, container.deleteDatabaseText, diff --git a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.test.ts b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.test.ts index 12deb7569..33fa59e0e 100644 --- a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.test.ts +++ b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.test.ts @@ -16,7 +16,13 @@ describe("CommandBarComponentButtonFactory tests", () => { beforeAll(() => { mockExplorer = {} as Explorer; mockExplorer.addCollectionText = ko.observable("mockText"); - mockExplorer.isPreferredApiTable = ko.computed(() => true); + updateUserContext({ + databaseAccount: { + properties: { + capabilities: [{ name: "EnableTable" }], + }, + } as DatabaseAccount, + }); mockExplorer.isPreferredApiMongoDB = ko.computed(() => false); mockExplorer.isSparkEnabled = ko.observable(true); mockExplorer.isSynapseLinkUpdating = ko.observable(false); @@ -54,7 +60,13 @@ describe("CommandBarComponentButtonFactory tests", () => { beforeAll(() => { mockExplorer = {} as Explorer; mockExplorer.addCollectionText = ko.observable("mockText"); - mockExplorer.isPreferredApiTable = ko.computed(() => true); + updateUserContext({ + databaseAccount: { + properties: { + capabilities: [{ name: "EnableTable" }], + }, + } as DatabaseAccount, + }); mockExplorer.isPreferredApiMongoDB = ko.computed(() => false); mockExplorer.isSynapseLinkUpdating = ko.observable(false); mockExplorer.isSparkEnabled = ko.observable(true); @@ -117,7 +129,13 @@ describe("CommandBarComponentButtonFactory tests", () => { beforeAll(() => { mockExplorer = {} as Explorer; mockExplorer.addCollectionText = ko.observable("mockText"); - mockExplorer.isPreferredApiTable = ko.computed(() => true); + updateUserContext({ + databaseAccount: { + properties: { + capabilities: [{ name: "EnableTable" }], + }, + } as DatabaseAccount, + }); mockExplorer.isSparkEnabled = ko.observable(true); mockExplorer.isSynapseLinkUpdating = ko.observable(false); @@ -195,8 +213,15 @@ describe("CommandBarComponentButtonFactory tests", () => { beforeAll(() => { mockExplorer = {} as Explorer; + mockExplorer.addDatabaseText = ko.observable("mockText"); mockExplorer.addCollectionText = ko.observable("mockText"); - mockExplorer.isPreferredApiTable = ko.computed(() => true); + updateUserContext({ + databaseAccount: { + properties: { + capabilities: [{ name: "EnableTable" }], + }, + } as DatabaseAccount, + }); mockExplorer.isPreferredApiMongoDB = ko.computed(() => false); mockExplorer.isSynapseLinkUpdating = ko.observable(false); mockExplorer.isSparkEnabled = ko.observable(true); @@ -226,6 +251,7 @@ describe("CommandBarComponentButtonFactory tests", () => { }, } as DatabaseAccount, }); + console.log(mockExplorer); const buttons = CommandBarComponentButtonFactory.createStaticCommandBarButtons(mockExplorer); const openCassandraShellBtn = buttons.find((button) => button.commandButtonLabel === openCassandraShellBtnLabel); expect(openCassandraShellBtn).toBeUndefined(); @@ -288,7 +314,13 @@ describe("CommandBarComponentButtonFactory tests", () => { beforeAll(() => { mockExplorer = {} as Explorer; mockExplorer.addCollectionText = ko.observable("mockText"); - mockExplorer.isPreferredApiTable = ko.computed(() => true); + updateUserContext({ + databaseAccount: { + properties: { + capabilities: [{ name: "EnableTable" }], + }, + } as DatabaseAccount, + }); mockExplorer.isPreferredApiMongoDB = ko.computed(() => false); mockExplorer.isSynapseLinkUpdating = ko.observable(false); diff --git a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.tsx b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.tsx index b59e0f526..3f3533f66 100644 --- a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.tsx +++ b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.tsx @@ -47,7 +47,7 @@ export function createStaticCommandBarButtons(container: Explorer): CommandButto buttons.push(addSynapseLink); } - if (!container.isPreferredApiTable()) { + if (userContext.apiType !== "Tables") { newCollectionBtn.children = [createNewCollectionGroup(container)]; const newDatabaseBtn = createNewDatabase(container); newCollectionBtn.children.push(newDatabaseBtn); diff --git a/src/Explorer/Panes/AddCollectionPane.ts b/src/Explorer/Panes/AddCollectionPane.ts index e20786d55..ba2f93884 100644 --- a/src/Explorer/Panes/AddCollectionPane.ts +++ b/src/Explorer/Panes/AddCollectionPane.ts @@ -331,7 +331,7 @@ export default class AddCollectionPane extends ContextualPaneBase { if (currentCollections >= maxCollections) { let typeOfContainer = "collection"; - if (userContext.apiType === "Gremlin" || this.container.isPreferredApiTable()) { + if (userContext.apiType === "Gremlin" || userContext.apiType === "Tables") { typeOfContainer = "container"; } @@ -392,7 +392,7 @@ export default class AddCollectionPane extends ContextualPaneBase { }); this.partitionKeyVisible = ko.computed(() => { - if (this.container == null || !!this.container.isPreferredApiTable()) { + if (this.container == null || userContext.apiType === "Tables") { return false; } @@ -757,7 +757,7 @@ export default class AddCollectionPane extends ContextualPaneBase { return; } - if (!!this.container.isPreferredApiTable()) { + if (userContext.apiType === "Tables") { // Table require fixed Database: TablesDB, and fixed Partition Key: /'$pk' this.databaseId(SharedConstants.CollectionCreation.TablesAPIDefaultDatabase); this.partitionKey("/'$pk'"); @@ -954,7 +954,7 @@ export default class AddCollectionPane extends ContextualPaneBase { } public isNonTableApi = (): boolean => { - return !this.container.isPreferredApiTable(); + return userContext.apiType !== "Tables"; }; public isUnlimitedStorageSelected = (): boolean => { @@ -1028,7 +1028,7 @@ export default class AddCollectionPane extends ContextualPaneBase { private _setFocus() { // Autofocus is enabled on AddCollectionPane based on the preferred API - if (this.container.isPreferredApiTable()) { + if (userContext.apiType === "Tables") { const focusTableId = document.getElementById("containerId"); focusTableId && focusTableId.focus(); return; diff --git a/src/Explorer/Panes/SettingsPane/__snapshots__/SettingsPane.test.tsx.snap b/src/Explorer/Panes/SettingsPane/__snapshots__/SettingsPane.test.tsx.snap index 456e08b1c..953d44ccf 100644 --- a/src/Explorer/Panes/SettingsPane/__snapshots__/SettingsPane.test.tsx.snap +++ b/src/Explorer/Panes/SettingsPane/__snapshots__/SettingsPane.test.tsx.snap @@ -537,7 +537,6 @@ exports[`Settings Pane should render Default properly 1`] = ` "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], "isPreferredApiMongoDB": [Function], - "isPreferredApiTable": [Function], "isPublishNotebookPaneEnabled": [Function], "isResourceTokenCollectionNodeSelected": [Function], "isRightPanelV2Enabled": [Function], @@ -1321,7 +1320,6 @@ exports[`Settings Pane should render Gremlin properly 1`] = ` "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], "isPreferredApiMongoDB": [Function], - "isPreferredApiTable": [Function], "isPublishNotebookPaneEnabled": [Function], "isResourceTokenCollectionNodeSelected": [Function], "isRightPanelV2Enabled": [Function], diff --git a/src/Explorer/Panes/Tables/EditTableEntityPane.ts b/src/Explorer/Panes/Tables/EditTableEntityPane.ts index a4f178feb..5b69fcd35 100644 --- a/src/Explorer/Panes/Tables/EditTableEntityPane.ts +++ b/src/Explorer/Panes/Tables/EditTableEntityPane.ts @@ -69,7 +69,7 @@ export default class EditTableEntityPane extends TableEntityPane { public open() { this.displayedAttributes(this.constructDisplayedAttributes(this.originEntity)); - if (this.container.isPreferredApiTable()) { + if (userContext.apiType === "Tables") { this.originalDocument = TableEntityProcessor.convertEntitiesToDocuments( [this.originEntity], this.tableViewModel.queryTablesTab.collection diff --git a/src/Explorer/Panes/UploadItemsPane/__snapshots__/UploadItemsPane.test.tsx.snap b/src/Explorer/Panes/UploadItemsPane/__snapshots__/UploadItemsPane.test.tsx.snap index 03397b4a8..22e91a515 100644 --- a/src/Explorer/Panes/UploadItemsPane/__snapshots__/UploadItemsPane.test.tsx.snap +++ b/src/Explorer/Panes/UploadItemsPane/__snapshots__/UploadItemsPane.test.tsx.snap @@ -537,7 +537,6 @@ exports[`Upload Items Pane should render Default properly 1`] = ` "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], "isPreferredApiMongoDB": [Function], - "isPreferredApiTable": [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 ca0674169..505c81973 100644 --- a/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap +++ b/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap @@ -540,7 +540,6 @@ exports[`Delete Database Confirmation Pane submit() Should call delete database "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], "isPreferredApiMongoDB": [Function], - "isPreferredApiTable": [Function], "isPublishNotebookPaneEnabled": [Function], "isResourceTokenCollectionNodeSelected": [Function], "isRightPanelV2Enabled": [Function], diff --git a/src/Explorer/Tabs/QueryTablesTab.ts b/src/Explorer/Tabs/QueryTablesTab.ts index 2f8bc77ad..9da085a81 100644 --- a/src/Explorer/Tabs/QueryTablesTab.ts +++ b/src/Explorer/Tabs/QueryTablesTab.ts @@ -47,7 +47,7 @@ export default class QueryTablesTab extends TabsBase { this.tableEntityListViewModel().queryTablesTab = this; this.queryViewModel(new QueryViewModel(this)); const sampleQuerySubscription = this.tableEntityListViewModel().items.subscribe(() => { - if (this.tableEntityListViewModel().items().length > 0 && this.container.isPreferredApiTable()) { + if (this.tableEntityListViewModel().items().length > 0 && userContext.apiType === "Tables") { this.queryViewModel().queryBuilderViewModel().setExample(); } sampleQuerySubscription.dispose(); diff --git a/src/Explorer/Tree/Collection.ts b/src/Explorer/Tree/Collection.ts index 09c58bbc0..ed525adfe 100644 --- a/src/Explorer/Tree/Collection.ts +++ b/src/Explorer/Tree/Collection.ts @@ -1069,7 +1069,7 @@ export default class Collection implements ViewModels.Collection { * Top-level method that will open the correct tab type depending on account API */ public openTab(): void { - if (this.container.isPreferredApiTable()) { + if (userContext.apiType === "Tables") { this.onTableEntitiesClick(); return; } else if (userContext.apiType === "Cassandra") { @@ -1090,7 +1090,7 @@ export default class Collection implements ViewModels.Collection { * Get correct collection label depending on account API */ public getLabel(): string { - if (this.container.isPreferredApiTable()) { + if (userContext.apiType === "Tables") { return "Entities"; } else if (userContext.apiType === "Cassandra") { return "Rows"; diff --git a/src/RouteHandlers/TabRouteHandler.ts b/src/RouteHandlers/TabRouteHandler.ts index 19a453c38..f20606cae 100644 --- a/src/RouteHandlers/TabRouteHandler.ts +++ b/src/RouteHandlers/TabRouteHandler.ts @@ -147,7 +147,7 @@ export class TabRouteHandler { ); collection && collection.container && - (collection.container.isPreferredApiTable() || userContext.apiType === "Cassandra") && + (userContext.apiType === "Tables" || userContext.apiType === "Cassandra") && collection.onTableEntitiesClick(); }); }