From d7c62ac7f17501f3c8b85943d3f190ac07ff1cf8 Mon Sep 17 00:00:00 2001 From: Sunil Kumar Yadav <79906609+sunilyadav840@users.noreply.github.com> Date: Thu, 13 May 2021 06:33:52 +0530 Subject: [PATCH] Migrate Collapse/Open Resource Tree to React (#733) Co-authored-by: Steve Faulkner --- less/documentDB.less | 6 +- less/tree.less | 1 + src/Common/CollapsedResourceTree.tsx | 35 ++++++ src/Common/ResourceTree.tsx | 59 ++++++++++ .../SettingsComponent.test.tsx.snap | 8 -- src/Explorer/Explorer.tsx | 23 +--- .../GitHubReposPanel.test.tsx.snap | 2 - .../StringInputPane.test.tsx.snap | 2 - ...eteDatabaseConfirmationPanel.test.tsx.snap | 2 - src/Main.tsx | 106 +++--------------- 10 files changed, 120 insertions(+), 124 deletions(-) create mode 100644 src/Common/CollapsedResourceTree.tsx create mode 100644 src/Common/ResourceTree.tsx diff --git a/less/documentDB.less b/less/documentDB.less index e58206818..5fc2f8571 100644 --- a/less/documentDB.less +++ b/less/documentDB.less @@ -2099,7 +2099,7 @@ a:link { display: flex; flex: 1 1 auto; overflow-x: auto; - overflow-y: auto; + overflow-y: hidden; height: 100%; } @@ -3085,3 +3085,7 @@ settings-pane { padding-left: @SmallSpace; } } +.hiddenMain { + visibility: hidden; + height: 0px; +} \ No newline at end of file diff --git a/less/tree.less b/less/tree.less index 56a5ee38e..e60bcf69c 100644 --- a/less/tree.less +++ b/less/tree.less @@ -3,6 +3,7 @@ .resourceTree { height: 100%; + width: 20%; flex: 0 0 auto; .main { height: 100%; diff --git a/src/Common/CollapsedResourceTree.tsx b/src/Common/CollapsedResourceTree.tsx new file mode 100644 index 000000000..ea1ee6a32 --- /dev/null +++ b/src/Common/CollapsedResourceTree.tsx @@ -0,0 +1,35 @@ +import React, { FunctionComponent } from "react"; +import arrowLeftImg from "../../images/imgarrowlefticon.svg"; + +export interface CollapsedResourceTreeProps { + toggleLeftPaneExpanded: () => void; + isLeftPaneExpanded: boolean; +} + +export const CollapsedResourceTree: FunctionComponent = ({ + toggleLeftPaneExpanded, + isLeftPaneExpanded, +}: CollapsedResourceTreeProps): JSX.Element => { + return ( +
+
+
    +
  • + + Expand + + + + +
  • +
+
+
+ ); +}; diff --git a/src/Common/ResourceTree.tsx b/src/Common/ResourceTree.tsx new file mode 100644 index 000000000..9aae283ea --- /dev/null +++ b/src/Common/ResourceTree.tsx @@ -0,0 +1,59 @@ +import React, { FunctionComponent } from "react"; +import arrowLeftImg from "../../images/imgarrowlefticon.svg"; +import refreshImg from "../../images/refresh-cosmos.svg"; +import { AuthType } from "../AuthType"; +import { userContext } from "../UserContext"; + +export interface ResourceTreeProps { + toggleLeftPaneExpanded: () => void; + isLeftPaneExpanded: boolean; +} + +export const ResourceTree: FunctionComponent = ({ + toggleLeftPaneExpanded, + isLeftPaneExpanded, +}: ResourceTreeProps): JSX.Element => { + return ( +
+ {/* Collections Window - - Start */} +
+ {/* Collections Window Title/Command Bar - Start */} +
+
+ +
+ + Refresh tree + + + Hide + +
+
+
+ {userContext.authType === AuthType.ResourceToken ? ( +
+ ) : ( +
+ )} +
+ {/* Collections Window - End */} +
+ ); +}; diff --git a/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap b/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap index 9eb6d8b7e..d413c0525 100644 --- a/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap +++ b/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap @@ -1051,7 +1051,6 @@ exports[`SettingsComponent renders 1`] = ` "isAutoscaleDefaultEnabled": [Function], "isFixedCollectionWithSharedThroughputSupported": [Function], "isHostedDataExplorerEnabled": [Function], - "isLeftPaneExpanded": [Function], "isMongoIndexingEnabled": [Function], "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], @@ -1118,7 +1117,6 @@ exports[`SettingsComponent renders 1`] = ` "activeTab": [Function], "openedTabs": [Function], }, - "toggleLeftPaneExpandedKeyPress": [Function], }, "databaseId": "test", "defaultTtl": [Function], @@ -2163,7 +2161,6 @@ exports[`SettingsComponent renders 1`] = ` "isAutoscaleDefaultEnabled": [Function], "isFixedCollectionWithSharedThroughputSupported": [Function], "isHostedDataExplorerEnabled": [Function], - "isLeftPaneExpanded": [Function], "isMongoIndexingEnabled": [Function], "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], @@ -2230,7 +2227,6 @@ exports[`SettingsComponent renders 1`] = ` "activeTab": [Function], "openedTabs": [Function], }, - "toggleLeftPaneExpandedKeyPress": [Function], } } isAutoPilotSelected={false} @@ -3288,7 +3284,6 @@ exports[`SettingsComponent renders 1`] = ` "isAutoscaleDefaultEnabled": [Function], "isFixedCollectionWithSharedThroughputSupported": [Function], "isHostedDataExplorerEnabled": [Function], - "isLeftPaneExpanded": [Function], "isMongoIndexingEnabled": [Function], "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], @@ -3355,7 +3350,6 @@ exports[`SettingsComponent renders 1`] = ` "activeTab": [Function], "openedTabs": [Function], }, - "toggleLeftPaneExpandedKeyPress": [Function], }, "databaseId": "test", "defaultTtl": [Function], @@ -4400,7 +4394,6 @@ exports[`SettingsComponent renders 1`] = ` "isAutoscaleDefaultEnabled": [Function], "isFixedCollectionWithSharedThroughputSupported": [Function], "isHostedDataExplorerEnabled": [Function], - "isLeftPaneExpanded": [Function], "isMongoIndexingEnabled": [Function], "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], @@ -4467,7 +4460,6 @@ exports[`SettingsComponent renders 1`] = ` "activeTab": [Function], "openedTabs": [Function], }, - "toggleLeftPaneExpandedKeyPress": [Function], } } geospatialConfigType="Geometry" diff --git a/src/Explorer/Explorer.tsx b/src/Explorer/Explorer.tsx index 40c04bc61..b3451c0e7 100644 --- a/src/Explorer/Explorer.tsx +++ b/src/Explorer/Explorer.tsx @@ -134,7 +134,6 @@ export default class Explorer { public databases: ko.ObservableArray; public selectedDatabaseId: ko.Computed; public selectedCollectionId: ko.Computed; - public isLeftPaneExpanded: ko.Observable; public selectedNode: ko.Observable; private resourceTree: ResourceTreeAdapter; @@ -231,6 +230,7 @@ export default class Explorer { }); } }); + this.isNotebooksEnabledForAccount = ko.observable(false); this.isNotebooksEnabledForAccount.subscribe((isEnabledForAccount: boolean) => this.refreshCommandBarButtons()); this.isSparkEnabledForAccount = ko.observable(false); @@ -335,7 +335,6 @@ export default class Explorer { } return true; }); - this.isLeftPaneExpanded = ko.observable(true); this.selectedNode = ko.observable(); this.selectedNode.subscribe((nodeSelected: ViewModels.TreeNode) => { // Make sure switching tabs restores tabs display @@ -675,16 +674,8 @@ export default class Explorer { this.setIsNotificationConsoleExpanded(true); } - public toggleLeftPaneExpanded() { - this.isLeftPaneExpanded(!this.isLeftPaneExpanded()); - - if (this.isLeftPaneExpanded()) { - document.getElementById("expandToggleLeftPaneButton").focus(); - this.splitter.expandLeft(); - } else { - document.getElementById("collapseToggleLeftPaneButton").focus(); - this.splitter.collapseLeft(); - } + public collapseConsole(): void { + this.setIsNotificationConsoleExpanded(false); } public refreshDatabaseForResourceToken(): Q.Promise { @@ -803,14 +794,6 @@ export default class Explorer { this.refreshNotebookList(); }; - public toggleLeftPaneExpandedKeyPress = (source: any, event: KeyboardEvent): boolean => { - if (event.keyCode === Constants.KeyCodes.Space || event.keyCode === Constants.KeyCodes.Enter) { - this.toggleLeftPaneExpanded(); - return false; - } - return true; - }; - // Facade public provideFeedbackEmail = () => { window.open(Constants.Urls.feedbackEmail, "_blank"); diff --git a/src/Explorer/Panes/GitHubReposPanel/__snapshots__/GitHubReposPanel.test.tsx.snap b/src/Explorer/Panes/GitHubReposPanel/__snapshots__/GitHubReposPanel.test.tsx.snap index 223e8e63b..5da784af4 100644 --- a/src/Explorer/Panes/GitHubReposPanel/__snapshots__/GitHubReposPanel.test.tsx.snap +++ b/src/Explorer/Panes/GitHubReposPanel/__snapshots__/GitHubReposPanel.test.tsx.snap @@ -1040,7 +1040,6 @@ exports[`GitHub Repos Panel should render Default properly 1`] = ` "isAutoscaleDefaultEnabled": [Function], "isFixedCollectionWithSharedThroughputSupported": [Function], "isHostedDataExplorerEnabled": [Function], - "isLeftPaneExpanded": [Function], "isMongoIndexingEnabled": [Function], "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], @@ -1107,7 +1106,6 @@ exports[`GitHub Repos Panel should render Default properly 1`] = ` "activeTab": [Function], "openedTabs": [Function], }, - "toggleLeftPaneExpandedKeyPress": [Function], }, "getRepo": [Function], "pinRepo": [Function], diff --git a/src/Explorer/Panes/StringInputPane/__snapshots__/StringInputPane.test.tsx.snap b/src/Explorer/Panes/StringInputPane/__snapshots__/StringInputPane.test.tsx.snap index b05197cb9..f779e8b74 100644 --- a/src/Explorer/Panes/StringInputPane/__snapshots__/StringInputPane.test.tsx.snap +++ b/src/Explorer/Panes/StringInputPane/__snapshots__/StringInputPane.test.tsx.snap @@ -1030,7 +1030,6 @@ exports[`StringInput Pane should render Create new directory properly 1`] = ` "isAutoscaleDefaultEnabled": [Function], "isFixedCollectionWithSharedThroughputSupported": [Function], "isHostedDataExplorerEnabled": [Function], - "isLeftPaneExpanded": [Function], "isMongoIndexingEnabled": [Function], "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], @@ -1097,7 +1096,6 @@ exports[`StringInput Pane should render Create new directory properly 1`] = ` "activeTab": [Function], "openedTabs": [Function], }, - "toggleLeftPaneExpandedKeyPress": [Function], } } inProgressMessage="Creating directory " diff --git a/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap b/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap index 0e7a59725..ace1945cb 100644 --- a/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap +++ b/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap @@ -1030,7 +1030,6 @@ exports[`Delete Database Confirmation Pane submit() Should call delete database "isHostedDataExplorerEnabled": [Function], "isLastCollection": [Function], "isLastNonEmptyDatabase": [Function], - "isLeftPaneExpanded": [Function], "isMongoIndexingEnabled": [Function], "isNotebookEnabled": [Function], "isNotebooksEnabledForAccount": [Function], @@ -1099,7 +1098,6 @@ exports[`Delete Database Confirmation Pane submit() Should call delete database "activeTab": [Function], "openedTabs": [Function], }, - "toggleLeftPaneExpandedKeyPress": [Function], } } openNotificationConsole={[Function]} diff --git a/src/Main.tsx b/src/Main.tsx index 57ce3b5bd..2abf3d2f5 100644 --- a/src/Main.tsx +++ b/src/Main.tsx @@ -14,8 +14,6 @@ import "../externals/jquery.typeahead.min.js"; import "../images/CosmosDB_rgb_ui_lighttheme.ico"; import "../images/favicon.ico"; import hdeConnectImage from "../images/HdeConnectCosmosDB.svg"; -import arrowLeftImg from "../images/imgarrowlefticon.svg"; -import refreshImg from "../images/refresh-cosmos.svg"; import "../less/documentDB.less"; import "../less/forms.less"; import "../less/infobox.less"; @@ -27,7 +25,8 @@ import "../less/TableStyles/EntityEditor.less"; import "../less/TableStyles/fulldatatables.less"; import "../less/TableStyles/queryBuilder.less"; import "../less/tree.less"; -import { AuthType } from "./AuthType"; +import { CollapsedResourceTree } from "./Common/CollapsedResourceTree"; +import { ResourceTree } from "./Common/ResourceTree"; import "./Explorer/Controls/Accordion/AccordionComponent.less"; import "./Explorer/Controls/CollapsiblePanel/CollapsiblePanelComponent.less"; import { Dialog, DialogProps } from "./Explorer/Controls/Dialog"; @@ -54,7 +53,6 @@ import { useSidePanel } from "./hooks/useSidePanel"; import { useTabs } from "./hooks/useTabs"; import "./Libs/jquery"; import "./Shared/appInsights"; -import { userContext } from "./UserContext"; initializeIcons(); @@ -63,6 +61,7 @@ const App: React.FunctionComponent = () => { const [notificationConsoleData, setNotificationConsoleData] = useState(undefined); //TODO: Refactor so we don't need to pass the id to remove a console data const [inProgressConsoleDataIdToBeDeleted, setInProgressConsoleDataIdToBeDeleted] = useState(""); + const [isLeftPaneExpanded, setIsLeftPaneExpanded] = useState(true); const [dialogProps, setDialogProps] = useState(); const [showDialog, setShowDialog] = useState(false); @@ -92,6 +91,15 @@ const App: React.FunctionComponent = () => { const config = useConfig(); const explorer = useKnockoutExplorer(config?.platform, explorerParams); + const toggleLeftPaneExpanded = () => { + setIsLeftPaneExpanded(!isLeftPaneExpanded); + if (isLeftPaneExpanded) { + document.getElementById("expandToggleLeftPaneButton").focus(); + } else { + document.getElementById("collapseToggleLeftPaneButton").focus(); + } + }; + if (!explorer) { return ; } @@ -107,93 +115,13 @@ const App: React.FunctionComponent = () => {
{/* Collections Tree Expanded - Start */} -
- {/* Collections Window - - Start */} -
- {/* Collections Window Title/Command Bar - Start */} -
-
- -
- - - - - Hide - -
-
-
- {userContext.authType === AuthType.ResourceToken ? ( -
- ) : ( -
- )} -
- {/* Collections Window - End */} -
+ {/* Collections Tree Expanded - End */} {/* Collections Tree Collapsed - Start */} -
-
-
    -
  • - - Expand - - - - -
  • -
-
-
+ {/* Collections Tree Collapsed - End */}
{/* Splitter - Start */}