// Copyright (C) The Arvados Authors. All rights reserved. // // SPDX-License-Identifier: AGPL-3.0 import * as React from 'react'; import { connect, DispatchProp } from 'react-redux'; import { RootState } from '~/store/store'; import { getProperty } from '~/store/properties/properties'; import { PROJECT_PANEL_CURRENT_UUID } from '~/store/project-panel/project-panel-action'; import { ArvadosTheme } from '~/common/custom-theme'; import { PopoverOrigin } from '@material-ui/core/Popover'; import { StyleRulesCallback, WithStyles, withStyles, Toolbar, Grid, Button, MenuItem, Menu } from '@material-ui/core'; 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'; const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ button: { boxShadow: 'none', padding: '2px 10px 2px 5px', fontSize: '0.75rem' }, menuItem: { fontSize: '0.875rem', color: theme.palette.grey["700"] }, icon: { marginRight: theme.spacing.unit } }); interface SidePanelDataProps { currentItemId: string; isProjectRoute: boolean; properties: Properties; } interface Properties { breadcrumbs: Array<{uuid: string, label: string}>; } interface SidePanelState { anchorEl: any; } type SidePanelProps = SidePanelDataProps & DispatchProp & WithStyles; const transformOrigin: PopoverOrigin = { vertical: -50, 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 }))( class extends React.Component { state: SidePanelState = { anchorEl: undefined }; render() { const { classes, isProjectRoute, properties } = this.props; const { anchorEl } = this.state; return New collection Run a process New project ; } handleNewProjectClick = () => { this.props.dispatch(openProjectCreateDialog(this.props.currentItemId)); } handleRunProcessClick = () => { this.props.dispatch(runProcessPanelActions.SET_PROCESS_OWNER_UUID(this.props.currentItemId)); this.props.dispatch(navigateToRunProcess); } handleNewCollectionClick = () => { this.props.dispatch(openCollectionCreateDialog(this.props.currentItemId)); } handleClose = () => { this.setState({ anchorEl: undefined }); } handleOpen = (event: React.MouseEvent) => { this.setState({ anchorEl: event.currentTarget }); } } ) );