From a1d5648bbceff29b67d6f8d6cc14971159774dca Mon Sep 17 00:00:00 2001 From: Hardikkumar Nai <80053762+hardiknai-techm@users.noreply.github.com> Date: Mon, 28 Jun 2021 10:09:28 +0530 Subject: [PATCH] Remove Explorer.openAddCollectionPane (#905) Co-authored-by: Steve Faulkner --- .eslintignore | 1 - src/Explorer/Explorer.tsx | 13 ++++---- .../{Database.test.ts => Database.test.tsx} | 8 ++--- .../Tree/{Database.ts => Database.tsx} | 30 ++++++++++++------- 4 files changed, 29 insertions(+), 23 deletions(-) rename src/Explorer/Tree/{Database.test.ts => Database.test.tsx} (95%) rename src/Explorer/Tree/{Database.ts => Database.tsx} (92%) diff --git a/.eslintignore b/.eslintignore index 4cad77619..2b837830b 100644 --- a/.eslintignore +++ b/.eslintignore @@ -154,7 +154,6 @@ src/Explorer/Tree/AccessibleVerticalList.ts src/Explorer/Tree/Collection.test.ts src/Explorer/Tree/Collection.ts src/Explorer/Tree/ConflictId.ts -src/Explorer/Tree/Database.ts src/Explorer/Tree/DocumentId.ts src/Explorer/Tree/ObjectId.ts src/Explorer/Tree/ResourceTokenCollection.ts diff --git a/src/Explorer/Explorer.tsx b/src/Explorer/Explorer.tsx index a4a53017f..055868a24 100644 --- a/src/Explorer/Explorer.tsx +++ b/src/Explorer/Explorer.tsx @@ -1200,7 +1200,7 @@ export default class Explorer { } } - public onNewCollectionClicked(databaseId?: string): void { + public async onNewCollectionClicked(databaseId?: string): Promise { if (userContext.apiType === "Cassandra") { useSidePanel .getState() @@ -1209,7 +1209,10 @@ export default class Explorer { ); } else { - this.openAddCollectionPanel(databaseId); + await useDatabases.getState().loadDatabaseOffers(); + useSidePanel + .getState() + .openSidePanel("New " + getCollectionName(), ); } } @@ -1262,12 +1265,6 @@ export default class Explorer { .openSidePanel("Input parameters", ); } - public async openAddCollectionPanel(databaseId?: string): Promise { - await useDatabases.getState().loadDatabaseOffers(); - useSidePanel - .getState() - .openSidePanel("New " + getCollectionName(), ); - } public openAddDatabasePane(): void { useSidePanel.getState().openSidePanel("New " + getDatabaseName(), ); } diff --git a/src/Explorer/Tree/Database.test.ts b/src/Explorer/Tree/Database.test.tsx similarity index 95% rename from src/Explorer/Tree/Database.test.ts rename to src/Explorer/Tree/Database.test.tsx index d364adca5..87c75f8c5 100644 --- a/src/Explorer/Tree/Database.test.ts +++ b/src/Explorer/Tree/Database.test.tsx @@ -31,9 +31,9 @@ updateUserContext({ describe("Add Schema", () => { it("should not call requestSchema or getSchema if analyticalStorageTtl is undefined", () => { - const collection: DataModels.Collection = {} as DataModels.Collection; + const collection: DataModels.Collection = { id: "fakeId" } as DataModels.Collection; collection.analyticalStorageTtl = undefined; - const database = new Database(createMockContainer(), { id: "fakeId" }); + const database = new Database(createMockContainer(), collection); database.container = createMockContainer(); database.container.isSchemaEnabled = ko.computed(() => false); @@ -47,10 +47,10 @@ describe("Add Schema", () => { }); it("should call requestSchema or getSchema if analyticalStorageTtl is not undefined", () => { - const collection: DataModels.Collection = { id: "fakeId" } as DataModels.Collection; + const collection: DataModels.Collection = {} as DataModels.Collection; collection.analyticalStorageTtl = 0; - const database = new Database(createMockContainer(), {}); + const database = new Database(createMockContainer(), collection); database.container = createMockContainer(); database.container.isSchemaEnabled = ko.computed(() => true); diff --git a/src/Explorer/Tree/Database.ts b/src/Explorer/Tree/Database.tsx similarity index 92% rename from src/Explorer/Tree/Database.ts rename to src/Explorer/Tree/Database.tsx index bf2a1537c..cfa7decf0 100644 --- a/src/Explorer/Tree/Database.ts +++ b/src/Explorer/Tree/Database.tsx @@ -1,4 +1,5 @@ import * as ko from "knockout"; +import React from "react"; import * as _ from "underscore"; import { AuthType } from "../../AuthType"; import * as Constants from "../../Common/Constants"; @@ -9,18 +10,20 @@ import * as Logger from "../../Common/Logger"; import { fetchPortalNotifications } from "../../Common/PortalNotifications"; import * as DataModels from "../../Contracts/DataModels"; import * as ViewModels from "../../Contracts/ViewModels"; +import { useSidePanel } from "../../hooks/useSidePanel"; import { IJunoResponse, JunoClient } from "../../Juno/JunoClient"; import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants"; import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; import { userContext } from "../../UserContext"; +import { getCollectionName } from "../../Utils/APITypeUtils"; import { isServerlessAccount } from "../../Utils/CapabilityUtils"; import { logConsoleError } from "../../Utils/NotificationConsoleUtils"; import Explorer from "../Explorer"; +import { AddCollectionPanel } from "../Panes/AddCollectionPanel"; import { DatabaseSettingsTabV2 } from "../Tabs/SettingsTabV2"; import { useDatabases } from "../useDatabases"; import { useSelectedNode } from "../useSelectedNode"; import Collection from "./Collection"; - export default class Database implements ViewModels.Database { public nodeKind: string; public container: Explorer; @@ -35,7 +38,7 @@ export default class Database implements ViewModels.Database { public junoClient: JunoClient; private isOfferRead: boolean; - constructor(container: Explorer, data: any) { + constructor(container: Explorer, data: DataModels.Database) { this.nodeKind = "Database"; this.container = container; this.self = data._self; @@ -74,6 +77,7 @@ export default class Database implements ViewModels.Database { tabTitle: "Scale", }); pendingNotificationsPromise.then( + // eslint-disable-next-line @typescript-eslint/no-explicit-any (data: any) => { const pendingNotification: DataModels.Notification = data?.[0]; const tabOptions: ViewModels.TabOptions = { @@ -89,7 +93,7 @@ export default class Database implements ViewModels.Database { settingsTab.pendingNotification(pendingNotification); this.container.tabsManager.activateNewTab(settingsTab); }, - (error: any) => { + (error) => { const errorMessage = getErrorMessage(error); TelemetryProcessor.traceFailure( Action.Tab, @@ -114,7 +118,7 @@ export default class Database implements ViewModels.Database { settingsTab.pendingNotification(pendingNotification); this.container.tabsManager.activateTab(settingsTab); }, - (error: any) => { + () => { settingsTab.pendingNotification(undefined); this.container.tabsManager.activateTab(settingsTab); } @@ -190,8 +194,14 @@ export default class Database implements ViewModels.Database { this.deleteCollectionsFromList(deltaCollections.toDelete); } - public openAddCollection(database: Database) { - database.container.openAddCollectionPanel(database.id()); + public async openAddCollection(database: Database): Promise { + await useDatabases.getState().loadDatabaseOffers(); + useSidePanel + .getState() + .openSidePanel( + "New " + getCollectionName(), + + ); } public findCollectionWithId(collectionId: string): ViewModels.Collection { @@ -221,7 +231,7 @@ export default class Database implements ViewModels.Database { } return _.find(notifications, (notification: DataModels.Notification) => { - const throughputUpdateRegExp: RegExp = new RegExp("Throughput update (.*) in progress"); + const throughputUpdateRegExp = new RegExp("Throughput update (.*) in progress"); return ( notification.kind === "message" && !notification.collectionName && @@ -259,7 +269,7 @@ export default class Database implements ViewModels.Database { } ); - let collectionsToDelete: Collection[] = []; + const collectionsToDelete: Collection[] = []; ko.utils.arrayForEach(this.collections(), (collection: Collection) => { const collectionPresentInUpdatedList = _.some( updatedCollectionsList, @@ -299,7 +309,7 @@ export default class Database implements ViewModels.Database { } public addSchema(collection: DataModels.Collection, interval?: number): NodeJS.Timeout { - let checkForSchema: NodeJS.Timeout = null; + let checkForSchema: NodeJS.Timeout; interval = interval || 5000; if (collection.analyticalStorageTtl !== undefined && this.container.isSchemaEnabled()) { @@ -325,7 +335,7 @@ export default class Database implements ViewModels.Database { clearInterval(checkForSchema); } - if (response.data !== null) { + if (response.data !== undefined) { clearInterval(checkForSchema); collection.schema = response.data; }