From ee63ba213e2e56a57e0cd49f6c7ce9bde5014f53 Mon Sep 17 00:00:00 2001 From: Pawel Kowalczyk Date: Mon, 17 Dec 2018 12:51:33 +0100 Subject: [PATCH] 14489-any-menus-persists-after-route-change Feature #14489 Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk --- .../data-explorer/data-explorer.tsx | 9 ++-- src/routes/route-change-handlers.ts | 4 ++ .../data-explorer/data-explorer.tsx | 3 +- .../main-app-bar/account-menu.tsx | 9 ++-- .../main-app-bar/admin-menu.tsx | 9 ++-- .../main-app-bar/help-menu.tsx | 54 ++++++++++++------- .../side-panel/side-panel.tsx | 17 +++--- 7 files changed, 66 insertions(+), 39 deletions(-) diff --git a/src/components/data-explorer/data-explorer.tsx b/src/components/data-explorer/data-explorer.tsx index 4175fbc6..56958c80 100644 --- a/src/components/data-explorer/data-explorer.tsx +++ b/src/components/data-explorer/data-explorer.tsx @@ -49,6 +49,7 @@ interface DataExplorerDataProps { paperProps?: PaperProps; actions?: React.ReactNode; hideSearchInput?: boolean; + currentRoute?: string; } interface DataExplorerActionProps { @@ -79,9 +80,10 @@ export const DataExplorer = withStyles(styles)( columns, onContextMenu, onFiltersChange, onSortToggle, working, extractKey, rowsPerPage, rowsPerPageOptions, onColumnToggle, searchValue, onSearch, items, itemsAvailable, onRowClick, onRowDoubleClick, classes, - dataTableDefaultView, hideColumnSelector, actions, paperProps, hideSearchInput + dataTableDefaultView, hideColumnSelector, actions, paperProps, hideSearchInput, + currentRoute } = this.props; - return + return {!hideSearchInput &&
@@ -105,8 +107,7 @@ export const DataExplorer = withStyles(styles)( onSortToggle={onSortToggle} extractKey={extractKey} working={working} - defaultView={dataTableDefaultView} - /> + defaultView={dataTableDefaultView} /> { const handler = handleLocationChange(store); @@ -40,6 +42,8 @@ const handleLocationChange = (store: RootStore) => ({ pathname }: Location) => { const linksMatch = Routes.matchLinksRoute(pathname); store.dispatch(dialogActions.CLOSE_ALL_DIALOGS()); + store.dispatch(contextMenuActions.CLOSE_CONTEXT_MENU()); + store.dispatch(searchBarActions.CLOSE_SEARCH_VIEW()); if (projectMatch) { store.dispatch(WorkbenchActions.loadProject(projectMatch.params.id)); diff --git a/src/views-components/data-explorer/data-explorer.tsx b/src/views-components/data-explorer/data-explorer.tsx index 710d202d..78b40795 100644 --- a/src/views-components/data-explorer/data-explorer.tsx +++ b/src/views-components/data-explorer/data-explorer.tsx @@ -23,7 +23,8 @@ interface Props { const mapStateToProps = (state: RootState, { id }: Props) => { const progress = state.progressIndicator.find(p => p.id === id); const working = progress && progress.working; - return { ...getDataExplorer(state.dataExplorer, id), working }; + const currentRoute = state.router.location ? state.router.location.pathname : ''; + return { ...getDataExplorer(state.dataExplorer, id), working, currentRoute }; }; const mapDispatchToProps = () => { diff --git a/src/views-components/main-app-bar/account-menu.tsx b/src/views-components/main-app-bar/account-menu.tsx index 1609aafa..b9df186f 100644 --- a/src/views-components/main-app-bar/account-menu.tsx +++ b/src/views-components/main-app-bar/account-menu.tsx @@ -17,19 +17,22 @@ import { openUserVirtualMachines } from "~/store/virtual-machines/virtual-machin interface AccountMenuProps { user?: User; + currentRoute: string; } const mapStateToProps = (state: RootState): AccountMenuProps => ({ - user: state.auth.user + user: state.auth.user, + currentRoute: state.router.location ? state.router.location.pathname : '' }); export const AccountMenu = connect(mapStateToProps)( - ({ user, dispatch }: AccountMenuProps & DispatchProp) => + ({ user, dispatch, currentRoute }: AccountMenuProps & DispatchProp) => user ? } id="account-menu" - title="Account Management"> + title="Account Management" + key={currentRoute}> {getUserFullname(user)} diff --git a/src/views-components/main-app-bar/admin-menu.tsx b/src/views-components/main-app-bar/admin-menu.tsx index 88aafbae..b47bbd52 100644 --- a/src/views-components/main-app-bar/admin-menu.tsx +++ b/src/views-components/main-app-bar/admin-menu.tsx @@ -17,19 +17,22 @@ import { openUserPanel } from "~/store/users/users-actions"; interface AdminMenuProps { user?: User; + currentRoute: string; } const mapStateToProps = (state: RootState): AdminMenuProps => ({ - user: state.auth.user + user: state.auth.user, + currentRoute: state.router.location ? state.router.location.pathname : '' }); export const AdminMenu = connect(mapStateToProps)( - ({ user, dispatch }: AdminMenuProps & DispatchProp) => + ({ user, dispatch, currentRoute }: AdminMenuProps & DispatchProp) => user ? } id="admin-menu" - title="Admin Panel"> + title="Admin Panel" + key={currentRoute}> dispatch(openRepositoriesPanel())}>Repositories dispatch(openAdminVirtualMachines())}>Virtual Machines dispatch(NavigationAction.navigateToSshKeysAdmin)}>Ssh Keys diff --git a/src/views-components/main-app-bar/help-menu.tsx b/src/views-components/main-app-bar/help-menu.tsx index 26604228..94da69e7 100644 --- a/src/views-components/main-app-bar/help-menu.tsx +++ b/src/views-components/main-app-bar/help-menu.tsx @@ -3,11 +3,14 @@ // SPDX-License-Identifier: AGPL-3.0 import * as React from "react"; -import { MenuItem, Typography, ListSubheader } from "@material-ui/core"; +import { MenuItem, Typography } from "@material-ui/core"; import { DropdownMenu } from "~/components/dropdown-menu/dropdown-menu"; import { ImportContactsIcon, HelpIcon } from "~/components/icon/icon"; import { ArvadosTheme } from '~/common/custom-theme'; import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles'; +import { RootState } from "~/store/store"; +import { compose } from "redux"; +import { connect } from "react-redux"; type CssRules = 'link' | 'icon' | 'title' | 'linkTitle'; @@ -52,22 +55,33 @@ const links = [ }, ]; -export const HelpMenu = withStyles(styles)( - ({ classes }: WithStyles) => - } - id="help-menu" - title="Help"> - Help - { - links.map(link => - - - - {link.title} - - - ) - } - -); +interface HelpMenuProps { + currentRoute: string; +} + +const mapStateToProps = ({ router }: RootState) => ({ + currentRoute: router.location ? router.location.pathname : '', +}); + +export const HelpMenu = compose( + connect(mapStateToProps), + withStyles(styles))( + ({ classes, currentRoute }: HelpMenuProps & WithStyles) => + } + id="help-menu" + title="Help" + key={currentRoute}> + Help + { + links.map(link => + + + + {link.title} + + + ) + } + + ); diff --git a/src/views-components/side-panel/side-panel.tsx b/src/views-components/side-panel/side-panel.tsx index 12e82dfb..62d9dc35 100644 --- a/src/views-components/side-panel/side-panel.tsx +++ b/src/views-components/side-panel/side-panel.tsx @@ -8,7 +8,7 @@ import { ArvadosTheme } from '~/common/custom-theme'; import { SidePanelTree, SidePanelTreeProps } from '~/views-components/side-panel-tree/side-panel-tree'; import { compose, Dispatch } from 'redux'; import { connect } from 'react-redux'; -import { navigateFromSidePanel } from '../../store/side-panel/side-panel-action'; +import { navigateFromSidePanel } from '~/store/side-panel/side-panel-action'; import { Grid } from '@material-ui/core'; import { SidePanelButton } from '~/views-components/side-panel-button/side-panel-button'; import { RootState } from '~/store/store'; @@ -33,14 +33,15 @@ const mapDispatchToProps = (dispatch: Dispatch): SidePanelTreeProps => ({ } }); -const mapStateToProps = (state: RootState) => ({ +const mapStateToProps = ({ router }: RootState) => ({ + currentRoute: router.location ? router.location.pathname : '', }); export const SidePanel = withStyles(styles)( connect(mapStateToProps, mapDispatchToProps)( - ({ classes, ...props }: WithStyles & SidePanelTreeProps) => - - - - -)); + ({ classes, ...props }: WithStyles & SidePanelTreeProps & { currentRoute: string }) => + + + + + )); -- 2.30.2