From a7239c7579e71ee8bdc2729f83752a9a3066d4b2 Mon Sep 17 00:00:00 2001 From: Hardikkumar Nai <80053762+hardiknai-techm@users.noreply.github.com> Date: Thu, 24 Jun 2021 10:51:27 +0530 Subject: [PATCH] Remove Explorer.openDeleteDatabaseConfirmationPane (#908) Co-authored-by: Steve Faulkner --- .eslintignore | 1 - src/Explorer/ContextMenuButtonFactory.ts | 172 -------------------- src/Explorer/ContextMenuButtonFactory.tsx | 184 ++++++++++++++++++++++ src/Explorer/Explorer.tsx | 16 -- src/Explorer/Tree/ResourceTreeAdapter.tsx | 2 +- 5 files changed, 185 insertions(+), 190 deletions(-) delete mode 100644 src/Explorer/ContextMenuButtonFactory.ts create mode 100644 src/Explorer/ContextMenuButtonFactory.tsx diff --git a/.eslintignore b/.eslintignore index 26a8dfa46..4cad77619 100644 --- a/.eslintignore +++ b/.eslintignore @@ -44,7 +44,6 @@ src/Definitions/png.d.ts src/Definitions/svg.d.ts src/Explorer/ComponentRegisterer.test.ts src/Explorer/ComponentRegisterer.ts -src/Explorer/ContextMenuButtonFactory.ts src/Explorer/Controls/CollapsiblePanel/CollapsiblePanelComponent.ts src/Explorer/Controls/DiffEditor/DiffEditorComponent.ts src/Explorer/Controls/DynamicList/DynamicList.test.ts diff --git a/src/Explorer/ContextMenuButtonFactory.ts b/src/Explorer/ContextMenuButtonFactory.ts deleted file mode 100644 index 42eac8d44..000000000 --- a/src/Explorer/ContextMenuButtonFactory.ts +++ /dev/null @@ -1,172 +0,0 @@ -import AddCollectionIcon from "../../images/AddCollection.svg"; -import AddSqlQueryIcon from "../../images/AddSqlQuery_16x16.svg"; -import AddStoredProcedureIcon from "../../images/AddStoredProcedure.svg"; -import AddTriggerIcon from "../../images/AddTrigger.svg"; -import AddUdfIcon from "../../images/AddUdf.svg"; -import DeleteCollectionIcon from "../../images/DeleteCollection.svg"; -import DeleteDatabaseIcon from "../../images/DeleteDatabase.svg"; -import DeleteSprocIcon from "../../images/DeleteSproc.svg"; -import DeleteTriggerIcon from "../../images/DeleteTrigger.svg"; -import DeleteUDFIcon from "../../images/DeleteUDF.svg"; -import HostedTerminalIcon from "../../images/Hosted-Terminal.svg"; -import * as ViewModels from "../Contracts/ViewModels"; -import { userContext } from "../UserContext"; -import { getCollectionName, getDatabaseName } from "../Utils/APITypeUtils"; -import { TreeNodeMenuItem } from "./Controls/TreeComponent/TreeComponent"; -import Explorer from "./Explorer"; -import StoredProcedure from "./Tree/StoredProcedure"; -import Trigger from "./Tree/Trigger"; -import UserDefinedFunction from "./Tree/UserDefinedFunction"; -export interface CollectionContextMenuButtonParams { - databaseId: string; - collectionId: string; -} - -export interface DatabaseContextMenuButtonParams { - databaseId: string; -} -/** - * New resource tree (in ReactJS) - */ -export class ResourceTreeContextMenuButtonFactory { - public static createDatabaseContextMenu(container: Explorer, databaseId: string): TreeNodeMenuItem[] { - const items: TreeNodeMenuItem[] = [ - { - iconSrc: AddCollectionIcon, - onClick: () => container.onNewCollectionClicked(databaseId), - label: `New ${getCollectionName()}`, - }, - ]; - - if (userContext.apiType !== "Tables") { - items.push({ - iconSrc: DeleteDatabaseIcon, - onClick: () => container.openDeleteDatabaseConfirmationPane(), - label: `Delete ${getDatabaseName()}`, - styleClass: "deleteDatabaseMenuItem", - }); - } - return items; - } - - public static createCollectionContextMenuButton( - container: Explorer, - selectedCollection: ViewModels.Collection - ): TreeNodeMenuItem[] { - const items: TreeNodeMenuItem[] = []; - if (userContext.apiType === "SQL" || userContext.apiType === "Gremlin") { - items.push({ - iconSrc: AddSqlQueryIcon, - onClick: () => selectedCollection && selectedCollection.onNewQueryClick(selectedCollection, null), - label: "New SQL Query", - }); - } - - if (userContext.apiType === "Mongo") { - items.push({ - iconSrc: AddSqlQueryIcon, - onClick: () => selectedCollection && selectedCollection.onNewMongoQueryClick(selectedCollection, null), - label: "New Query", - }); - - items.push({ - iconSrc: HostedTerminalIcon, - onClick: () => { - const selectedCollection: ViewModels.Collection = container.findSelectedCollection(); - if (container.isShellEnabled()) { - container.openNotebookTerminal(ViewModels.TerminalKind.Mongo); - } else { - selectedCollection && selectedCollection.onNewMongoShellClick(); - } - }, - label: container.isShellEnabled() ? "Open Mongo Shell" : "New Shell", - }); - } - - if (userContext.apiType === "SQL" || userContext.apiType === "Gremlin") { - items.push({ - iconSrc: AddStoredProcedureIcon, - onClick: () => { - const selectedCollection: ViewModels.Collection = container.findSelectedCollection(); - selectedCollection && selectedCollection.onNewStoredProcedureClick(selectedCollection, null); - }, - label: "New Stored Procedure", - }); - - items.push({ - iconSrc: AddUdfIcon, - onClick: () => { - const selectedCollection: ViewModels.Collection = container.findSelectedCollection(); - selectedCollection && selectedCollection.onNewUserDefinedFunctionClick(selectedCollection, null); - }, - label: "New UDF", - }); - - items.push({ - iconSrc: AddTriggerIcon, - onClick: () => { - const selectedCollection: ViewModels.Collection = container.findSelectedCollection(); - selectedCollection && selectedCollection.onNewTriggerClick(selectedCollection, null); - }, - label: "New Trigger", - }); - } - - items.push({ - iconSrc: DeleteCollectionIcon, - onClick: () => container.openDeleteCollectionConfirmationPane(), - label: `Delete ${getCollectionName()}`, - styleClass: "deleteCollectionMenuItem", - }); - - return items; - } - - public static createStoreProcedureContextMenuItems( - container: Explorer, - storedProcedure: StoredProcedure - ): TreeNodeMenuItem[] { - if (userContext.apiType === "Cassandra") { - return []; - } - - return [ - { - iconSrc: DeleteSprocIcon, - onClick: () => storedProcedure.delete(), - label: "Delete Store Procedure", - }, - ]; - } - - public static createTriggerContextMenuItems(container: Explorer, trigger: Trigger): TreeNodeMenuItem[] { - if (userContext.apiType === "Cassandra") { - return []; - } - - return [ - { - iconSrc: DeleteTriggerIcon, - onClick: () => trigger.delete(), - label: "Delete Trigger", - }, - ]; - } - - public static createUserDefinedFunctionContextMenuItems( - container: Explorer, - userDefinedFunction: UserDefinedFunction - ): TreeNodeMenuItem[] { - if (userContext.apiType === "Cassandra") { - return []; - } - - return [ - { - iconSrc: DeleteUDFIcon, - onClick: () => userDefinedFunction.delete(), - label: "Delete User Defined Function", - }, - ]; - } -} diff --git a/src/Explorer/ContextMenuButtonFactory.tsx b/src/Explorer/ContextMenuButtonFactory.tsx new file mode 100644 index 000000000..fa86a70bd --- /dev/null +++ b/src/Explorer/ContextMenuButtonFactory.tsx @@ -0,0 +1,184 @@ +import React from "react"; +import AddCollectionIcon from "../../images/AddCollection.svg"; +import AddSqlQueryIcon from "../../images/AddSqlQuery_16x16.svg"; +import AddStoredProcedureIcon from "../../images/AddStoredProcedure.svg"; +import AddTriggerIcon from "../../images/AddTrigger.svg"; +import AddUdfIcon from "../../images/AddUdf.svg"; +import DeleteCollectionIcon from "../../images/DeleteCollection.svg"; +import DeleteDatabaseIcon from "../../images/DeleteDatabase.svg"; +import DeleteSprocIcon from "../../images/DeleteSproc.svg"; +import DeleteTriggerIcon from "../../images/DeleteTrigger.svg"; +import DeleteUDFIcon from "../../images/DeleteUDF.svg"; +import HostedTerminalIcon from "../../images/Hosted-Terminal.svg"; +import * as ViewModels from "../Contracts/ViewModels"; +import { useSidePanel } from "../hooks/useSidePanel"; +import { userContext } from "../UserContext"; +import { getCollectionName, getDatabaseName } from "../Utils/APITypeUtils"; +import { TreeNodeMenuItem } from "./Controls/TreeComponent/TreeComponent"; +import Explorer from "./Explorer"; +import { DeleteCollectionConfirmationPane } from "./Panes/DeleteCollectionConfirmationPane/DeleteCollectionConfirmationPane"; +import { DeleteDatabaseConfirmationPanel } from "./Panes/DeleteDatabaseConfirmationPanel"; +import StoredProcedure from "./Tree/StoredProcedure"; +import Trigger from "./Tree/Trigger"; +import UserDefinedFunction from "./Tree/UserDefinedFunction"; + +export interface CollectionContextMenuButtonParams { + databaseId: string; + collectionId: string; +} + +export interface DatabaseContextMenuButtonParams { + databaseId: string; +} +/** + * New resource tree (in ReactJS) + */ +export const createDatabaseContextMenu = (container: Explorer, databaseId: string): TreeNodeMenuItem[] => { + const items: TreeNodeMenuItem[] = [ + { + iconSrc: AddCollectionIcon, + onClick: () => container.onNewCollectionClicked(databaseId), + label: `New ${getCollectionName()}`, + }, + ]; + + if (userContext.apiType !== "Tables") { + items.push({ + iconSrc: DeleteDatabaseIcon, + onClick: () => + useSidePanel + .getState() + .openSidePanel( + "Delete " + getDatabaseName(), + + ), + label: `Delete ${getDatabaseName()}`, + styleClass: "deleteDatabaseMenuItem", + }); + } + return items; +}; + +export const createCollectionContextMenuButton = ( + container: Explorer, + selectedCollection: ViewModels.Collection +): TreeNodeMenuItem[] => { + const items: TreeNodeMenuItem[] = []; + if (userContext.apiType === "SQL" || userContext.apiType === "Gremlin") { + items.push({ + iconSrc: AddSqlQueryIcon, + onClick: () => selectedCollection && selectedCollection.onNewQueryClick(selectedCollection, undefined), + label: "New SQL Query", + }); + } + + if (userContext.apiType === "Mongo") { + items.push({ + iconSrc: AddSqlQueryIcon, + onClick: () => selectedCollection && selectedCollection.onNewMongoQueryClick(selectedCollection, undefined), + label: "New Query", + }); + + items.push({ + iconSrc: HostedTerminalIcon, + onClick: () => { + const selectedCollection: ViewModels.Collection = container.findSelectedCollection(); + if (container.isShellEnabled()) { + container.openNotebookTerminal(ViewModels.TerminalKind.Mongo); + } else { + selectedCollection && selectedCollection.onNewMongoShellClick(); + } + }, + label: container.isShellEnabled() ? "Open Mongo Shell" : "New Shell", + }); + } + + if (userContext.apiType === "SQL" || userContext.apiType === "Gremlin") { + items.push({ + iconSrc: AddStoredProcedureIcon, + onClick: () => { + const selectedCollection: ViewModels.Collection = container.findSelectedCollection(); + selectedCollection && selectedCollection.onNewStoredProcedureClick(selectedCollection, undefined); + }, + label: "New Stored Procedure", + }); + + items.push({ + iconSrc: AddUdfIcon, + onClick: () => { + const selectedCollection: ViewModels.Collection = container.findSelectedCollection(); + selectedCollection && selectedCollection.onNewUserDefinedFunctionClick(selectedCollection, undefined); + }, + label: "New UDF", + }); + + items.push({ + iconSrc: AddTriggerIcon, + onClick: () => { + const selectedCollection: ViewModels.Collection = container.findSelectedCollection(); + selectedCollection && selectedCollection.onNewTriggerClick(selectedCollection, undefined); + }, + label: "New Trigger", + }); + } + + items.push({ + iconSrc: DeleteCollectionIcon, + onClick: () => + useSidePanel + .getState() + .openSidePanel("Delete " + getCollectionName(), ), + label: `Delete ${getCollectionName()}`, + styleClass: "deleteCollectionMenuItem", + }); + + return items; +}; + +export const createStoreProcedureContextMenuItems = ( + container: Explorer, + storedProcedure: StoredProcedure +): TreeNodeMenuItem[] => { + if (userContext.apiType === "Cassandra") { + return []; + } + + return [ + { + iconSrc: DeleteSprocIcon, + onClick: () => storedProcedure.delete(), + label: "Delete Store Procedure", + }, + ]; +}; + +export const createTriggerContextMenuItems = (container: Explorer, trigger: Trigger): TreeNodeMenuItem[] => { + if (userContext.apiType === "Cassandra") { + return []; + } + + return [ + { + iconSrc: DeleteTriggerIcon, + onClick: () => trigger.delete(), + label: "Delete Trigger", + }, + ]; +}; + +export const createUserDefinedFunctionContextMenuItems = ( + container: Explorer, + userDefinedFunction: UserDefinedFunction +): TreeNodeMenuItem[] => { + if (userContext.apiType === "Cassandra") { + return []; + } + + return [ + { + iconSrc: DeleteUDFIcon, + onClick: () => userDefinedFunction.delete(), + label: "Delete User Defined Function", + }, + ]; +}; diff --git a/src/Explorer/Explorer.tsx b/src/Explorer/Explorer.tsx index 6115ad786..87122177d 100644 --- a/src/Explorer/Explorer.tsx +++ b/src/Explorer/Explorer.tsx @@ -50,8 +50,6 @@ import { AddCollectionPanel } from "./Panes/AddCollectionPanel"; import { AddDatabasePanel } from "./Panes/AddDatabasePanel/AddDatabasePanel"; import { BrowseQueriesPane } from "./Panes/BrowseQueriesPane/BrowseQueriesPane"; import { CassandraAddCollectionPane } from "./Panes/CassandraAddCollectionPane/CassandraAddCollectionPane"; -import { DeleteCollectionConfirmationPane } from "./Panes/DeleteCollectionConfirmationPane/DeleteCollectionConfirmationPane"; -import { DeleteDatabaseConfirmationPanel } from "./Panes/DeleteDatabaseConfirmationPanel"; import { ExecuteSprocParamsPane } from "./Panes/ExecuteSprocParamsPane/ExecuteSprocParamsPane"; import { GitHubReposPanel } from "./Panes/GitHubReposPanel/GitHubReposPanel"; import { SaveQueryPane } from "./Panes/SaveQueryPane/SaveQueryPane"; @@ -1332,20 +1330,6 @@ export default class Explorer { } } - public openDeleteCollectionConfirmationPane(): void { - useSidePanel - .getState() - .openSidePanel("Delete " + getCollectionName(), ); - } - - public openDeleteDatabaseConfirmationPane(): void { - useSidePanel - .getState() - .openSidePanel( - "Delete " + getDatabaseName(), - - ); - } public openUploadItemsPanePane(): void { useSidePanel.getState().openSidePanel("Upload " + getUploadName(), ); } diff --git a/src/Explorer/Tree/ResourceTreeAdapter.tsx b/src/Explorer/Tree/ResourceTreeAdapter.tsx index 1e7fa4910..64e82ff99 100644 --- a/src/Explorer/Tree/ResourceTreeAdapter.tsx +++ b/src/Explorer/Tree/ResourceTreeAdapter.tsx @@ -23,7 +23,7 @@ import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; import { userContext } from "../../UserContext"; import { isServerlessAccount } from "../../Utils/CapabilityUtils"; import * as GitHubUtils from "../../Utils/GitHubUtils"; -import { ResourceTreeContextMenuButtonFactory } from "../ContextMenuButtonFactory"; +import * as ResourceTreeContextMenuButtonFactory from "../ContextMenuButtonFactory"; import { AccordionComponent, AccordionItemComponent } from "../Controls/Accordion/AccordionComponent"; import { TreeComponent, TreeNode, TreeNodeMenuItem } from "../Controls/TreeComponent/TreeComponent"; import Explorer from "../Explorer";