1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { connect, DispatchProp } from 'react-redux';
7 import { RootState } from '~/store/store';
8 import { getProperty } from '~/store/properties/properties';
9 import { PROJECT_PANEL_CURRENT_UUID } from '~/store/project-panel/project-panel-action';
10 import { ArvadosTheme } from '~/common/custom-theme';
11 import { PopoverOrigin } from '@material-ui/core/Popover';
12 import { StyleRulesCallback, WithStyles, withStyles, Toolbar, Grid, Button, MenuItem, Menu } from '@material-ui/core';
13 import { AddIcon, CollectionIcon, ProcessIcon, ProjectIcon } from '~/components/icon/icon';
14 import { openProjectCreateDialog } from '~/store/projects/project-create-actions';
15 import { openCollectionCreateDialog } from '~/store/collections/collection-create-actions';
16 import { matchProjectRoute } from '~/routes/routes';
18 type CssRules = 'button' | 'menuItem' | 'icon';
20 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
23 padding: '2px 10px 2px 5px',
28 color: theme.palette.grey["700"]
31 marginRight: theme.spacing.unit
35 interface SidePanelDataProps {
36 currentItemId: string;
37 buttonVisible: boolean;
40 interface SidePanelState {
44 type SidePanelProps = SidePanelDataProps & DispatchProp & WithStyles<CssRules>;
46 const transformOrigin: PopoverOrigin = {
51 const isButtonVisible = ({ router }: RootState) => {
52 const pathname = router.location ? router.location.pathname : '';
53 const match = matchProjectRoute(pathname);
57 export const SidePanelButton = withStyles(styles)(
58 connect((state: RootState) => ({
59 currentItemId: getProperty(PROJECT_PANEL_CURRENT_UUID)(state.properties),
60 buttonVisible: isButtonVisible(state)
62 class extends React.Component<SidePanelProps> {
64 state: SidePanelState = {
69 const { classes, buttonVisible } = this.props;
70 const { anchorEl } = this.state;
72 {buttonVisible && <Grid container>
73 <Grid container item xs alignItems="center" justify="flex-start">
74 <Button variant="contained" color="primary" size="small" className={classes.button}
75 aria-owns={anchorEl ? 'aside-menu-list' : undefined}
77 onClick={this.handleOpen}>
84 open={Boolean(anchorEl)}
85 onClose={this.handleClose}
86 onClick={this.handleClose}
87 transformOrigin={transformOrigin}>
88 <MenuItem className={classes.menuItem} onClick={this.handleNewCollectionClick}>
89 <CollectionIcon className={classes.icon} /> New collection
91 <MenuItem className={classes.menuItem}>
92 <ProcessIcon className={classes.icon} /> Run a process
94 <MenuItem className={classes.menuItem} onClick={this.handleNewProjectClick}>
95 <ProjectIcon className={classes.icon} /> New project
103 handleNewProjectClick = () => {
104 this.props.dispatch<any>(openProjectCreateDialog(this.props.currentItemId));
107 handleNewCollectionClick = () => {
108 this.props.dispatch<any>(openCollectionCreateDialog(this.props.currentItemId));
111 handleClose = () => {
112 this.setState({ anchorEl: undefined });
115 handleOpen = (event: React.MouseEvent<HTMLButtonElement>) => {
116 this.setState({ anchorEl: event.currentTarget });