Merge branch '14917-searching-by-properties'
[arvados-workbench2.git] / src / views-components / side-panel-button / side-panel-button.tsx
index f0543b4ca471d3a2cbb25f857758ee7fc4e3b62f..0f79759078d1ca2009a69643c2a7ab7681d467ca 100644 (file)
@@ -13,7 +13,8 @@ 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';
 
 type CssRules = 'button' | 'menuItem' | 'icon';
 
@@ -33,8 +34,8 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
 });
 
 interface SidePanelDataProps {
+    location: any;
     currentItemId: string;
-    showButton: boolean;
 }
 
 interface SidePanelState {
@@ -45,19 +46,13 @@ type SidePanelProps = SidePanelDataProps & DispatchProp & WithStyles<CssRules>;
 
 const transformOrigin: PopoverOrigin = {
     vertical: -50,
-    horizontal: 45
-};
-
-const checkButtonVisibility = ({ router }: RootState) => {
-    const pathname = router.location ? router.location.pathname : '';
-    const match = matchProjectRoute(pathname);
-    return !!match;
+    horizontal: 0
 };
 
 export const SidePanelButton = withStyles(styles)(
     connect((state: RootState) => ({
         currentItemId: getProperty(PROJECT_PANEL_CURRENT_UUID)(state.properties),
-        showButton: checkButtonVisibility(state)
+        location: state.router.location
     }))(
         class extends React.Component<SidePanelProps> {
 
@@ -66,11 +61,11 @@ export const SidePanelButton = withStyles(styles)(
             };
 
             render() {
-                const { classes, showButton } = this.props;
+                const { classes } = this.props;
                 const { anchorEl } = this.state;
                 return <Toolbar>
-                    {showButton && <Grid container>
-                        <Grid container item xs alignItems="center" justify="center">
+                    <Grid container>
+                        <Grid container item xs alignItems="center" justify="flex-start">
                             <Button variant="contained" color="primary" size="small" className={classes.button}
                                 aria-owns={anchorEl ? 'aside-menu-list' : undefined}
                                 aria-haspopup="true"
@@ -88,7 +83,7 @@ export const SidePanelButton = withStyles(styles)(
                                 <MenuItem className={classes.menuItem} onClick={this.handleNewCollectionClick}>
                                     <CollectionIcon className={classes.icon} /> New collection
                                 </MenuItem>
-                                <MenuItem className={classes.menuItem}>
+                                <MenuItem className={classes.menuItem} onClick={this.handleRunProcessClick}>
                                     <ProcessIcon className={classes.icon} /> Run a process
                                 </MenuItem>
                                 <MenuItem className={classes.menuItem} onClick={this.handleNewProjectClick}>
@@ -96,7 +91,7 @@ export const SidePanelButton = withStyles(styles)(
                                 </MenuItem>
                             </Menu>
                         </Grid>
-                    </Grid> }
+                    </Grid>
                 </Toolbar>;
             }
 
@@ -104,6 +99,15 @@ export const SidePanelButton = withStyles(styles)(
                 this.props.dispatch<any>(openProjectCreateDialog(this.props.currentItemId));
             }
 
+            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);
+            }
+
             handleNewCollectionClick = () => {
                 this.props.dispatch<any>(openCollectionCreateDialog(this.props.currentItemId));
             }