From f449328f26491e784d5b18b5032e4c8fc1ff0784 Mon Sep 17 00:00:00 2001 From: Jordi Bunster Date: Tue, 13 Apr 2021 10:42:00 -0700 Subject: [PATCH] Remove unused tab finder methods from Explorer (#549) --- src/Explorer/Explorer.tsx | 53 +++---------------- .../__snapshots__/index.test.tsx.snap | 1 + .../ExecuteSprocParamsPanel/index.test.tsx | 3 ++ .../Panes/ExecuteSprocParamsPanel/index.tsx | 6 ++- src/Explorer/Tabs/StoredProcedureTab.ts | 2 +- 5 files changed, 15 insertions(+), 50 deletions(-) diff --git a/src/Explorer/Explorer.tsx b/src/Explorer/Explorer.tsx index 9c7b0c56a..22a0da29b 100644 --- a/src/Explorer/Explorer.tsx +++ b/src/Explorer/Explorer.tsx @@ -79,8 +79,6 @@ import ResourceTokenCollection from "./Tree/ResourceTokenCollection"; import { ResourceTreeAdapter } from "./Tree/ResourceTreeAdapter"; import { ResourceTreeAdapterForResourceToken } from "./Tree/ResourceTreeAdapterForResourceToken"; import StoredProcedure from "./Tree/StoredProcedure"; -import Trigger from "./Tree/Trigger"; -import UserDefinedFunction from "./Tree/UserDefinedFunction"; BindingHandlersRegisterer.registerBindingHandlers(); // Hold a reference to ComponentRegisterer to prevent transpiler to ignore import @@ -1287,49 +1285,6 @@ export default class Explorer { : this.selectedNode().collection) as ViewModels.Collection; } - // TODO: Refactor below methods, minimize dependencies and add unit tests where necessary - public findSelectedStoredProcedure(): StoredProcedure { - const selectedCollection: ViewModels.Collection = this.findSelectedCollection(); - return _.find(selectedCollection.storedProcedures(), (storedProcedure: StoredProcedure) => { - const openedSprocTab = this.tabsManager.getTabs( - ViewModels.CollectionTabKind.StoredProcedures, - (tab) => tab.node && tab.node.rid === storedProcedure.rid - ); - return ( - storedProcedure.rid === this.selectedNode().rid || - (!!openedSprocTab && openedSprocTab.length > 0 && openedSprocTab[0].isActive()) - ); - }); - } - - public findSelectedUDF(): UserDefinedFunction { - const selectedCollection: ViewModels.Collection = this.findSelectedCollection(); - return _.find(selectedCollection.userDefinedFunctions(), (userDefinedFunction: UserDefinedFunction) => { - const openedUdfTab = this.tabsManager.getTabs( - ViewModels.CollectionTabKind.UserDefinedFunctions, - (tab) => tab.node && tab.node.rid === userDefinedFunction.rid - ); - return ( - userDefinedFunction.rid === this.selectedNode().rid || - (!!openedUdfTab && openedUdfTab.length > 0 && openedUdfTab[0].isActive()) - ); - }); - } - - public findSelectedTrigger(): Trigger { - const selectedCollection: ViewModels.Collection = this.findSelectedCollection(); - return _.find(selectedCollection.triggers(), (trigger: Trigger) => { - const openedTriggerTab = this.tabsManager.getTabs( - ViewModels.CollectionTabKind.Triggers, - (tab) => tab.node && tab.node.rid === trigger.rid - ); - return ( - trigger.rid === this.selectedNode().rid || - (!!openedTriggerTab && openedTriggerTab.length > 0 && openedTriggerTab[0].isActive()) - ); - }); - } - public closeAllPanes(): void { this._panes.forEach((pane: ContextualPaneBase) => pane.close()); } @@ -2311,10 +2266,14 @@ export default class Explorer { this.openSidePanel("Settings", ); } - public openExecuteSprocParamsPanel(): void { + public openExecuteSprocParamsPanel(storedProcedure: StoredProcedure): void { this.openSidePanel( "Input parameters", - this.closeSidePanel()} /> + this.closeSidePanel()} + /> ); } diff --git a/src/Explorer/Panes/ExecuteSprocParamsPanel/__snapshots__/index.test.tsx.snap b/src/Explorer/Panes/ExecuteSprocParamsPanel/__snapshots__/index.test.tsx.snap index 16baa1b18..dc5dedfed 100644 --- a/src/Explorer/Panes/ExecuteSprocParamsPanel/__snapshots__/index.test.tsx.snap +++ b/src/Explorer/Panes/ExecuteSprocParamsPanel/__snapshots__/index.test.tsx.snap @@ -4,6 +4,7 @@ exports[`Excute Sproc Param Pane should render Default properly 1`] = ` { const fakeExplorer = {} as Explorer; + const fakeSproc = {} as StoredProcedure; const props = { explorer: fakeExplorer, + storedProcedure: fakeSproc, closePanel: (): void => undefined, }; diff --git a/src/Explorer/Panes/ExecuteSprocParamsPanel/index.tsx b/src/Explorer/Panes/ExecuteSprocParamsPanel/index.tsx index 85a90277f..1107110a5 100644 --- a/src/Explorer/Panes/ExecuteSprocParamsPanel/index.tsx +++ b/src/Explorer/Panes/ExecuteSprocParamsPanel/index.tsx @@ -3,11 +3,13 @@ import { IDropdownOption, IImageProps, Image, Stack, Text } from "office-ui-fabr import React, { FunctionComponent, useState } from "react"; import AddPropertyIcon from "../../../../images/Add-property.svg"; import Explorer from "../../Explorer"; +import StoredProcedure from "../../Tree/StoredProcedure"; import { GenericRightPaneComponent, GenericRightPaneProps } from "../GenericRightPaneComponent"; import { InputParameter } from "./InputParameter"; interface ExecuteSprocParamsPaneProps { explorer: Explorer; + storedProcedure: StoredProcedure; closePanel: () => void; } @@ -23,6 +25,7 @@ interface UnwrappedExecuteSprocParam { export const ExecuteSprocParamsPanel: FunctionComponent = ({ explorer, + storedProcedure, closePanel, }: ExecuteSprocParamsPaneProps): JSX.Element => { const [isLoading, { setTrue: setLoadingTrue, setFalse: setLoadingFalse }] = useBoolean(false); @@ -77,8 +80,7 @@ export const ExecuteSprocParamsPanel: FunctionComponent sprocParam.text); - const currentSelectedSproc = explorer.findSelectedStoredProcedure(); - currentSelectedSproc.execute(sprocParams, partitionValue); + storedProcedure.execute(sprocParams, partitionValue); setLoadingFalse(); closePanel(); }; diff --git a/src/Explorer/Tabs/StoredProcedureTab.ts b/src/Explorer/Tabs/StoredProcedureTab.ts index 7e8d9396a..416753fdd 100644 --- a/src/Explorer/Tabs/StoredProcedureTab.ts +++ b/src/Explorer/Tabs/StoredProcedureTab.ts @@ -208,7 +208,7 @@ export default class StoredProcedureTab extends ScriptTabBase { iconSrc: ExecuteQueryIcon, iconAlt: label, onCommandClick: () => { - this.collection && this.collection.container.openExecuteSprocParamsPanel(); + this.collection && this.collection.container.openExecuteSprocParamsPanel(this.node); }, commandButtonLabel: label, ariaLabel: label,