14489-any-menus-persists-after-route-change
authorPawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>
Mon, 17 Dec 2018 11:51:33 +0000 (12:51 +0100)
committerPawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>
Mon, 17 Dec 2018 11:51:33 +0000 (12:51 +0100)
Feature #14489

Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>

src/components/data-explorer/data-explorer.tsx
src/routes/route-change-handlers.ts
src/views-components/data-explorer/data-explorer.tsx
src/views-components/main-app-bar/account-menu.tsx
src/views-components/main-app-bar/admin-menu.tsx
src/views-components/main-app-bar/help-menu.tsx
src/views-components/side-panel/side-panel.tsx

index 4175fbc6f23ccc3e18d50a7b70a0dc13808d4fe2..56958c807fb8f10a7527eb5441eacc5931506a2b 100644 (file)
@@ -49,6 +49,7 @@ interface DataExplorerDataProps<T> {
     paperProps?: PaperProps;
     actions?: React.ReactNode;
     hideSearchInput?: boolean;
+    currentRoute?: string;
 }
 
 interface DataExplorerActionProps<T> {
@@ -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 <Paper className={classes.root} {...paperProps}>
+            return <Paper className={classes.root} {...paperProps} key={currentRoute}>
                 <Toolbar className={classes.toolbar}>
                     <Grid container justify="space-between" wrap="nowrap" alignItems="center">
                         {!hideSearchInput && <div className={classes.searchBox}>
@@ -105,8 +107,7 @@ export const DataExplorer = withStyles(styles)(
                     onSortToggle={onSortToggle}
                     extractKey={extractKey}
                     working={working}
-                    defaultView={dataTableDefaultView}
-                />
+                    defaultView={dataTableDefaultView} />
                 <Toolbar className={classes.footer}>
                     <Grid container justify="flex-end">
                         <TablePagination
index 655c806f3a3b0337cc1a89eccae6b7a29ddaa832..bc5cbb6a9f41040834ac30c8d683dda97eda3f17 100644 (file)
@@ -8,6 +8,8 @@ import * as Routes from '~/routes/routes';
 import * as WorkbenchActions from '~/store/workbench/workbench-actions';
 import { navigateToRootProject } from '~/store/navigation/navigation-action';
 import { dialogActions } from '~/store/dialog/dialog-actions';
+import { contextMenuActions } from '~/store/context-menu/context-menu-actions';
+import { searchBarActions } from '~/store/search-bar/search-bar-actions';
 
 export const addRouteChangeHandlers = (history: History, store: RootStore) => {
     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));
index 710d202dfe25997c66dcde62f44ead0d9e469b10..78b4079500938707ad8808e0bcea7d29178621f2 100644 (file)
@@ -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 = () => {
index 1609aafa0849a277432f343dbe39e788de788bf7..b9df186f957171386530c26a4a4643457fc8e17a 100644 (file)
@@ -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<any>) =>
+    ({ user, dispatch, currentRoute }: AccountMenuProps & DispatchProp<any>) =>
         user
             ? <DropdownMenu
                 icon={<UserPanelIcon />}
                 id="account-menu"
-                title="Account Management">
+                title="Account Management"
+                key={currentRoute}>
                 <MenuItem>
                     {getUserFullname(user)}
                 </MenuItem>
index 88aafbae61ef3c821d90b513389a772c4b0e41da..b47bbd5211ab20905cdd1698377c6d6ce5fc9151 100644 (file)
@@ -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<any>) =>
+    ({ user, dispatch, currentRoute }: AdminMenuProps & DispatchProp<any>) =>
         user
             ? <DropdownMenu
                 icon={<AdminMenuIcon />}
                 id="admin-menu"
-                title="Admin Panel">
+                title="Admin Panel"
+                key={currentRoute}>
                 <MenuItem onClick={() => dispatch(openRepositoriesPanel())}>Repositories</MenuItem>
                 <MenuItem onClick={() => dispatch(openAdminVirtualMachines())}>Virtual Machines</MenuItem>
                 <MenuItem onClick={() => dispatch(NavigationAction.navigateToSshKeysAdmin)}>Ssh Keys</MenuItem>
index 26604228fc21ac9fbfb79ba21a96a8372324655c..94da69e7c62311d94d4e324462cd7a73d3e02ac5 100644 (file)
@@ -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<CssRules>) =>
-        <DropdownMenu
-            icon={<HelpIcon />}
-            id="help-menu"
-            title="Help">
-            <MenuItem disabled>Help</MenuItem>
-            {
-                links.map(link =>
-                    <MenuItem key={link.title}>
-                        <a href={link.link} target="_blank" className={classes.link}>
-                            <ImportContactsIcon className={classes.icon} />
-                            <Typography variant="body1" className={classes.linkTitle}>{link.title}</Typography>
-                        </a>
-                    </MenuItem>
-                )
-            }
-        </DropdownMenu>
-);
+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<CssRules>) =>
+            <DropdownMenu
+                icon={<HelpIcon />}
+                id="help-menu"
+                title="Help"
+                key={currentRoute}>
+                <MenuItem disabled>Help</MenuItem>
+                {
+                    links.map(link =>
+                        <MenuItem key={link.title}>
+                            <a href={link.link} target="_blank" className={classes.link}>
+                                <ImportContactsIcon className={classes.icon} />
+                                <Typography variant="body1" className={classes.linkTitle}>{link.title}</Typography>
+                            </a>
+                        </MenuItem>
+                    )
+                }
+            </DropdownMenu>
+    );
index 12e82dfb102f9ade1df6cd928a19c1957b7ebe3b..62d9dc3532e2efc48605b261e99ddffaa20d7133 100644 (file)
@@ -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<CssRules> & SidePanelTreeProps) =>
-    <Grid item xs>
-        <SidePanelButton />
-        <SidePanelTree {...props} />
-    </Grid>
-));
+        ({ classes, ...props }: WithStyles<CssRules> & SidePanelTreeProps & { currentRoute: string }) =>
+            <Grid item xs>
+                <SidePanelButton key={props.currentRoute} />
+                <SidePanelTree {...props} />
+            </Grid>
+    ));