From 63e13cdabe14ec01ec9645c4bc034bd904890187 Mon Sep 17 00:00:00 2001 From: Steve Faulkner Date: Tue, 30 Mar 2021 09:31:21 -0500 Subject: [PATCH] Remove Explorer.nonSystemDatabases (#538) * Remove Explorer.nonSystemDatabases * Fix tests --- .../SettingsComponent.test.tsx.snap | 8 --- .../ContainerSampleGenerator.test.ts | 8 +-- .../DataSamples/DataSamplesUtil.test.ts | 10 ++-- src/Explorer/DataSamples/DataSamplesUtil.ts | 6 +- src/Explorer/Explorer.tsx | 17 ------ .../Panes/CassandraAddCollectionPane.html | 2 +- .../Panes/CassandraAddCollectionPane.ts | 6 +- src/Explorer/Tree/ResourceTreeAdapter.test.ts | 6 +- src/Explorer/Tree/ResourceTreeAdapter.tsx | 59 +++++++++---------- src/hooks/useKnockoutExplorer.ts | 2 +- 10 files changed, 48 insertions(+), 76 deletions(-) diff --git a/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap b/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap index f9640bb5f..db5addf25 100644 --- a/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap +++ b/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap @@ -32,7 +32,6 @@ exports[`SettingsComponent renders 1`] = ` "_closeSynapseLinkModalDialog": [Function], "_isAfecFeatureRegistered": [Function], "_isInitializingNotebooks": false, - "_isSystemDatabasePredicate": [Function], "_panes": Array [ AddDatabasePane { "autoPilotUsageCost": [Function], @@ -974,7 +973,6 @@ exports[`SettingsComponent renders 1`] = ` "title": [Function], "visible": [Function], }, - "nonSystemDatabases": [Function], "notebookBasePath": [Function], "notebookServerInfo": [Function], "onRefreshDatabasesKeyPress": [Function], @@ -1228,7 +1226,6 @@ exports[`SettingsComponent renders 1`] = ` "_closeSynapseLinkModalDialog": [Function], "_isAfecFeatureRegistered": [Function], "_isInitializingNotebooks": false, - "_isSystemDatabasePredicate": [Function], "_panes": Array [ AddDatabasePane { "autoPilotUsageCost": [Function], @@ -2170,7 +2167,6 @@ exports[`SettingsComponent renders 1`] = ` "title": [Function], "visible": [Function], }, - "nonSystemDatabases": [Function], "notebookBasePath": [Function], "notebookServerInfo": [Function], "onRefreshDatabasesKeyPress": [Function], @@ -2437,7 +2433,6 @@ exports[`SettingsComponent renders 1`] = ` "_closeSynapseLinkModalDialog": [Function], "_isAfecFeatureRegistered": [Function], "_isInitializingNotebooks": false, - "_isSystemDatabasePredicate": [Function], "_panes": Array [ AddDatabasePane { "autoPilotUsageCost": [Function], @@ -3379,7 +3374,6 @@ exports[`SettingsComponent renders 1`] = ` "title": [Function], "visible": [Function], }, - "nonSystemDatabases": [Function], "notebookBasePath": [Function], "notebookServerInfo": [Function], "onRefreshDatabasesKeyPress": [Function], @@ -3633,7 +3627,6 @@ exports[`SettingsComponent renders 1`] = ` "_closeSynapseLinkModalDialog": [Function], "_isAfecFeatureRegistered": [Function], "_isInitializingNotebooks": false, - "_isSystemDatabasePredicate": [Function], "_panes": Array [ AddDatabasePane { "autoPilotUsageCost": [Function], @@ -4575,7 +4568,6 @@ exports[`SettingsComponent renders 1`] = ` "title": [Function], "visible": [Function], }, - "nonSystemDatabases": [Function], "notebookBasePath": [Function], "notebookServerInfo": [Function], "onRefreshDatabasesKeyPress": [Function], diff --git a/src/Explorer/DataSamples/ContainerSampleGenerator.test.ts b/src/Explorer/DataSamples/ContainerSampleGenerator.test.ts index ce917e840..13ec16270 100644 --- a/src/Explorer/DataSamples/ContainerSampleGenerator.test.ts +++ b/src/Explorer/DataSamples/ContainerSampleGenerator.test.ts @@ -2,17 +2,17 @@ jest.mock("../Graph/GraphExplorerComponent/GremlinClient"); jest.mock("../../Common/dataAccess/createCollection"); jest.mock("../../Common/dataAccess/createDocument"); import * as ko from "knockout"; -import * as ViewModels from "../../Contracts/ViewModels"; import Q from "q"; -import { ContainerSampleGenerator } from "./ContainerSampleGenerator"; import { createDocument } from "../../Common/dataAccess/createDocument"; -import Explorer from "../Explorer"; +import * as ViewModels from "../../Contracts/ViewModels"; import { updateUserContext } from "../../UserContext"; +import Explorer from "../Explorer"; +import { ContainerSampleGenerator } from "./ContainerSampleGenerator"; describe("ContainerSampleGenerator", () => { const createExplorerStub = (database: ViewModels.Database): Explorer => { const explorerStub = {} as Explorer; - explorerStub.nonSystemDatabases = ko.computed(() => [database]); + explorerStub.databases = ko.observableArray([database]); explorerStub.isPreferredApiGraph = ko.computed(() => false); explorerStub.isPreferredApiMongoDB = ko.computed(() => false); explorerStub.isPreferredApiDocumentDB = ko.computed(() => false); diff --git a/src/Explorer/DataSamples/DataSamplesUtil.test.ts b/src/Explorer/DataSamples/DataSamplesUtil.test.ts index 634354c8d..9a35158f5 100644 --- a/src/Explorer/DataSamples/DataSamplesUtil.test.ts +++ b/src/Explorer/DataSamples/DataSamplesUtil.test.ts @@ -1,9 +1,9 @@ -import { DataSamplesUtil } from "./DataSamplesUtil"; -import * as sinon from "sinon"; -import { ContainerSampleGenerator } from "./ContainerSampleGenerator"; import * as ko from "knockout"; +import * as sinon from "sinon"; +import { Collection, Database } from "../../Contracts/ViewModels"; import Explorer from "../Explorer"; -import { Database, Collection } from "../../Contracts/ViewModels"; +import { ContainerSampleGenerator } from "./ContainerSampleGenerator"; +import { DataSamplesUtil } from "./DataSamplesUtil"; describe("DataSampleUtils", () => { const sampleCollectionId = "sampleCollectionId"; @@ -16,7 +16,7 @@ describe("DataSampleUtils", () => { collections: ko.observableArray([collection]), } as Database; const explorer = {} as Explorer; - explorer.nonSystemDatabases = ko.computed(() => [database]); + explorer.databases = ko.observableArray([database]); explorer.showOkModalDialog = () => {}; const dataSamplesUtil = new DataSamplesUtil(explorer); diff --git a/src/Explorer/DataSamples/DataSamplesUtil.ts b/src/Explorer/DataSamples/DataSamplesUtil.ts index 81e191048..aa3d01253 100644 --- a/src/Explorer/DataSamples/DataSamplesUtil.ts +++ b/src/Explorer/DataSamples/DataSamplesUtil.ts @@ -1,8 +1,8 @@ import * as ViewModels from "../../Contracts/ViewModels"; -import { ContainerSampleGenerator } from "./ContainerSampleGenerator"; import * as NotificationConsoleUtils from "../../Utils/NotificationConsoleUtils"; -import { ConsoleDataType } from "../Menus/NotificationConsole/NotificationConsoleComponent"; import Explorer from "../Explorer"; +import { ConsoleDataType } from "../Menus/NotificationConsole/NotificationConsoleComponent"; +import { ContainerSampleGenerator } from "./ContainerSampleGenerator"; export class DataSamplesUtil { private static readonly DialogTitle = "Create Sample Container"; @@ -17,7 +17,7 @@ export class DataSamplesUtil { const databaseName = generator.getDatabaseId(); const containerName = generator.getCollectionId(); - if (this.hasContainer(databaseName, containerName, this.container.nonSystemDatabases())) { + if (this.hasContainer(databaseName, containerName, this.container.databases())) { const msg = `The container ${containerName} in database ${databaseName} already exists. Please delete it and retry.`; this.container.showOkModalDialog(DataSamplesUtil.DialogTitle, msg); NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Error, msg); diff --git a/src/Explorer/Explorer.tsx b/src/Explorer/Explorer.tsx index 2bd45e796..73e6342f7 100644 --- a/src/Explorer/Explorer.tsx +++ b/src/Explorer/Explorer.tsx @@ -180,7 +180,6 @@ export default class Explorer { // Resource Tree public databases: ko.ObservableArray; - public nonSystemDatabases: ko.Computed; public selectedDatabaseId: ko.Computed; public selectedCollectionId: ko.Computed; public isLeftPaneExpanded: ko.Observable; @@ -257,7 +256,6 @@ export default class Explorer { public closeDialog: ExplorerParams["closeDialog"]; private _panes: ContextualPaneBase[] = []; - private _isSystemDatabasePredicate: (database: ViewModels.Database) => boolean = (database) => false; private _isInitializingNotebooks: boolean; private notebookBasePath: ko.Observable; private _arcadiaManager: ArcadiaResourceManager; @@ -528,17 +526,6 @@ export default class Explorer { configContext.platform === Platform.Portal && !this.isRunningOnNationalCloud() && !this.isPreferredApiGraph() ); this.isRightPanelV2Enabled = ko.computed(() => userContext.features.enableRightPanelV2); - this.defaultExperience.subscribe((defaultExperience: string) => { - if ( - defaultExperience && - defaultExperience.toLowerCase() === Constants.DefaultAccountExperience.Cassandra.toLowerCase() - ) { - this._isSystemDatabasePredicate = (database: ViewModels.Database): boolean => { - return database.id() === "system"; - }; - } - }); - this.selectedDatabaseId = ko.computed(() => { const selectedNode = this.selectedNode(); if (!selectedNode) { @@ -560,10 +547,6 @@ export default class Explorer { } }); - this.nonSystemDatabases = ko.computed(() => { - return this.databases().filter((database: ViewModels.Database) => !this._isSystemDatabasePredicate(database)); - }); - this.addDatabasePane = new AddDatabasePane({ id: "adddatabasepane", visible: ko.observable(false), diff --git a/src/Explorer/Panes/CassandraAddCollectionPane.html b/src/Explorer/Panes/CassandraAddCollectionPane.html index c426a272e..2450196ee 100644 --- a/src/Explorer/Panes/CassandraAddCollectionPane.html +++ b/src/Explorer/Panes/CassandraAddCollectionPane.html @@ -114,7 +114,7 @@ aria-label="Keyspace id" /> - + diff --git a/src/Explorer/Panes/CassandraAddCollectionPane.ts b/src/Explorer/Panes/CassandraAddCollectionPane.ts index 92bfa87bc..44cf83a7f 100644 --- a/src/Explorer/Panes/CassandraAddCollectionPane.ts +++ b/src/Explorer/Panes/CassandraAddCollectionPane.ts @@ -261,10 +261,8 @@ export default class CassandraAddCollectionPane extends ContextualPaneBase { }); this.keyspaceIds(cachedKeyspaceIdsList); }; - this.container.nonSystemDatabases.subscribe((newDatabases: ViewModels.Database[]) => - updateKeyspaceIds(newDatabases) - ); - updateKeyspaceIds(this.container.nonSystemDatabases()); + this.container.databases.subscribe((newDatabases: ViewModels.Database[]) => updateKeyspaceIds(newDatabases)); + updateKeyspaceIds(this.container.databases()); } this.autoPilotUsageCost = ko.pureComputed(() => { diff --git a/src/Explorer/Tree/ResourceTreeAdapter.test.ts b/src/Explorer/Tree/ResourceTreeAdapter.test.ts index 5102149c1..e65ee1011 100644 --- a/src/Explorer/Tree/ResourceTreeAdapter.test.ts +++ b/src/Explorer/Tree/ResourceTreeAdapter.test.ts @@ -1,8 +1,8 @@ -import Explorer from "../Explorer"; import * as ko from "knockout"; -import { ResourceTreeAdapter } from "./ResourceTreeAdapter"; import * as ViewModels from "../../Contracts/ViewModels"; +import Explorer from "../Explorer"; import TabsBase from "../Tabs/TabsBase"; +import { ResourceTreeAdapter } from "./ResourceTreeAdapter"; describe("ResourceTreeAdapter", () => { const mockContainer = (): Explorer => @@ -18,7 +18,7 @@ describe("ResourceTreeAdapter", () => { } as TabsBase), }, isNotebookEnabled: ko.observable(true), - nonSystemDatabases: ko.observable([]), + databases: ko.observable([]), } as unknown) as Explorer); // TODO isDataNodeSelected needs a better design and refactor, but for now, we protect some of the code paths diff --git a/src/Explorer/Tree/ResourceTreeAdapter.tsx b/src/Explorer/Tree/ResourceTreeAdapter.tsx index 06a7d51d4..bb8dac7e8 100644 --- a/src/Explorer/Tree/ResourceTreeAdapter.tsx +++ b/src/Explorer/Tree/ResourceTreeAdapter.tsx @@ -1,39 +1,38 @@ import * as ko from "knockout"; +import { Callout, DirectionalHint, ICalloutProps, ILinkProps, Link, Stack, Text } from "office-ui-fabric-react"; import * as React from "react"; -import { ReactAdapter } from "../../Bindings/ReactBindingHandler"; -import { AccordionComponent, AccordionItemComponent } from "../Controls/Accordion/AccordionComponent"; -import { TreeComponent, TreeNode, TreeNodeMenuItem, TreeNodeComponent } from "../Controls/TreeComponent/TreeComponent"; -import * as ViewModels from "../../Contracts/ViewModels"; -import { NotebookContentItem, NotebookContentItemType } from "../Notebook/NotebookContentItem"; -import { ResourceTreeContextMenuButtonFactory } from "../ContextMenuButtonFactory"; -import { mostRecentActivity } from "../MostRecentActivity/MostRecentActivity"; -import CopyIcon from "../../../images/notebook/Notebook-copy.svg"; import CosmosDBIcon from "../../../images/Azure-Cosmos-DB.svg"; -import CollectionIcon from "../../../images/tree-collection.svg"; import DeleteIcon from "../../../images/delete.svg"; -import NotebookIcon from "../../../images/notebook/Notebook-resource.svg"; -import RefreshIcon from "../../../images/refresh-cosmos.svg"; -import NewNotebookIcon from "../../../images/notebook/Notebook-new.svg"; -import FileIcon from "../../../images/notebook/file-cosmos.svg"; -import PublishIcon from "../../../images/notebook/publish_content.svg"; -import { ArrayHashMap } from "../../Common/ArrayHashMap"; -import { NotebookUtil } from "../Notebook/NotebookUtil"; -import _ from "underscore"; -import { IPinnedRepo } from "../../Juno/JunoClient"; -import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; -import { Action, ActionModifiers, Source } from "../../Shared/Telemetry/TelemetryConstants"; -import { Areas } from "../../Common/Constants"; -import * as GitHubUtils from "../../Utils/GitHubUtils"; import GalleryIcon from "../../../images/GalleryIcon.svg"; -import { Callout, Text, Link, DirectionalHint, Stack, ICalloutProps, ILinkProps } from "office-ui-fabric-react"; +import FileIcon from "../../../images/notebook/file-cosmos.svg"; +import CopyIcon from "../../../images/notebook/Notebook-copy.svg"; +import NewNotebookIcon from "../../../images/notebook/Notebook-new.svg"; +import NotebookIcon from "../../../images/notebook/Notebook-resource.svg"; +import PublishIcon from "../../../images/notebook/publish_content.svg"; +import RefreshIcon from "../../../images/refresh-cosmos.svg"; +import CollectionIcon from "../../../images/tree-collection.svg"; +import { ReactAdapter } from "../../Bindings/ReactBindingHandler"; +import { ArrayHashMap } from "../../Common/ArrayHashMap"; +import { Areas } from "../../Common/Constants"; +import * as DataModels from "../../Contracts/DataModels"; +import * as ViewModels from "../../Contracts/ViewModels"; +import { IPinnedRepo } from "../../Juno/JunoClient"; import { LocalStorageUtility, StorageKey } from "../../Shared/StorageUtility"; +import { Action, ActionModifiers, Source } from "../../Shared/Telemetry/TelemetryConstants"; +import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; +import { userContext } from "../../UserContext"; +import * as GitHubUtils from "../../Utils/GitHubUtils"; +import { ResourceTreeContextMenuButtonFactory } from "../ContextMenuButtonFactory"; +import { AccordionComponent, AccordionItemComponent } from "../Controls/Accordion/AccordionComponent"; +import { TreeComponent, TreeNode, TreeNodeMenuItem } from "../Controls/TreeComponent/TreeComponent"; import Explorer from "../Explorer"; -import UserDefinedFunction from "./UserDefinedFunction"; +import { mostRecentActivity } from "../MostRecentActivity/MostRecentActivity"; +import { NotebookContentItem, NotebookContentItemType } from "../Notebook/NotebookContentItem"; +import { NotebookUtil } from "../Notebook/NotebookUtil"; +import TabsBase from "../Tabs/TabsBase"; import StoredProcedure from "./StoredProcedure"; import Trigger from "./Trigger"; -import TabsBase from "../Tabs/TabsBase"; -import { userContext } from "../../UserContext"; -import * as DataModels from "../../Contracts/DataModels"; +import UserDefinedFunction from "./UserDefinedFunction"; export class ResourceTreeAdapter implements ReactAdapter { public static readonly MyNotebooksTitle = "My Notebooks"; @@ -64,7 +63,7 @@ export class ResourceTreeAdapter implements ReactAdapter { this.koSubsCollectionIdMap = new ArrayHashMap(); this.databaseCollectionIdMap = new ArrayHashMap(); - this.container.nonSystemDatabases.subscribe((databases: ViewModels.Database[]) => { + this.container.databases.subscribe((databases: ViewModels.Database[]) => { // Clean up old databases this.cleanupDatabasesKoSubs(); @@ -72,7 +71,7 @@ export class ResourceTreeAdapter implements ReactAdapter { this.triggerRender(); }); - this.container.nonSystemDatabases().forEach((database: ViewModels.Database) => this.watchDatabase(database)); + this.container.databases().forEach((database: ViewModels.Database) => this.watchDatabase(database)); this.triggerRender(); } @@ -190,7 +189,7 @@ export class ResourceTreeAdapter implements ReactAdapter { } private buildDataTree(): TreeNode { - const databaseTreeNodes: TreeNode[] = this.container.nonSystemDatabases().map((database: ViewModels.Database) => { + const databaseTreeNodes: TreeNode[] = this.container.databases().map((database: ViewModels.Database) => { const databaseNode: TreeNode = { label: database.id(), iconSrc: CosmosDBIcon, diff --git a/src/hooks/useKnockoutExplorer.ts b/src/hooks/useKnockoutExplorer.ts index 495e4c8f3..80dd38a68 100644 --- a/src/hooks/useKnockoutExplorer.ts +++ b/src/hooks/useKnockoutExplorer.ts @@ -260,7 +260,7 @@ async function configurePortal(explorerParams: ExplorerParams): Promise