Merge branch '14917-searching-by-properties'
[arvados-workbench2.git] / src / views-components / side-panel-button / side-panel-button.tsx
index b4784bfe69c401b51e17a01d2b61c5ca13b524c2..0f79759078d1ca2009a69643c2a7ab7681d467ca 100644 (file)
@@ -13,7 +13,6 @@ import { StyleRulesCallback, WithStyles, withStyles, Toolbar, Grid, Button, Menu
 import { AddIcon, CollectionIcon, ProcessIcon, ProjectIcon } from '~/components/icon/icon';
 import { openProjectCreateDialog } from '~/store/projects/project-create-actions';
 import { openCollectionCreateDialog } from '~/store/collections/collection-create-actions';
-import { matchProjectRoute } from '~/routes/routes';
 import { navigateToRunProcess } from '~/store/navigation/navigation-action';
 import { runProcessPanelActions } from '~/store/run-process-panel/run-process-panel-actions';
 
@@ -35,13 +34,8 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
 });
 
 interface SidePanelDataProps {
+    location: any;
     currentItemId: string;
-    isProjectRoute: boolean;
-    properties: Properties;
-}
-
-interface Properties {
-    breadcrumbs: Array<{uuid: string, label: string}>;
 }
 
 interface SidePanelState {
@@ -55,26 +49,10 @@ const transformOrigin: PopoverOrigin = {
     horizontal: 0
 };
 
-const isProjectRoute = ({ router }: RootState) => {
-    const pathname = router.location ? router.location.pathname : '';
-    const match = matchProjectRoute(pathname);
-    return !!match;
-};
-
-const isItemSharedWithMe = (properties: Properties) => {
-    if (properties.breadcrumbs) {
-        const isItemSharedWithMe = properties.breadcrumbs[0].label === 'Shared with me';
-        return isItemSharedWithMe;
-    } else {
-        return false;
-    }
-};
-
 export const SidePanelButton = withStyles(styles)(
     connect((state: RootState) => ({
         currentItemId: getProperty(PROJECT_PANEL_CURRENT_UUID)(state.properties),
-        isProjectRoute: isProjectRoute(state),
-        properties: state.properties
+        location: state.router.location
     }))(
         class extends React.Component<SidePanelProps> {
 
@@ -83,7 +61,7 @@ export const SidePanelButton = withStyles(styles)(
             };
 
             render() {
-                const { classes, isProjectRoute, properties } = this.props;
+                const { classes } = this.props;
                 const { anchorEl } = this.state;
                 return <Toolbar>
                     <Grid container>
@@ -91,8 +69,7 @@ export const SidePanelButton = withStyles(styles)(
                             <Button variant="contained" color="primary" size="small" className={classes.button}
                                 aria-owns={anchorEl ? 'aside-menu-list' : undefined}
                                 aria-haspopup="true"
-                                onClick={this.handleOpen}
-                                disabled={!isProjectRoute || isItemSharedWithMe(properties)}>
+                                onClick={this.handleOpen}>
                                 <AddIcon />
                                 New
                             </Button>
@@ -123,7 +100,11 @@ export const SidePanelButton = withStyles(styles)(
             }
 
             handleRunProcessClick = () => {
+                const location = this.props.location;
+                this.props.dispatch(runProcessPanelActions.RESET_RUN_PROCESS_PANEL());
+                this.props.dispatch(runProcessPanelActions.SET_PROCESS_PATHNAME(location.pathname));
                 this.props.dispatch(runProcessPanelActions.SET_PROCESS_OWNER_UUID(this.props.currentItemId));
+                
                 this.props.dispatch<any>(navigateToRunProcess);
             }