X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/f79c7407429a38dfe3c274e886983d8e3ea0fdaa..0cfd92ccb88a7cac4ff6d1645bbbe62386f4bb1b:/src/views-components/side-panel-button/side-panel-button.tsx diff --git a/src/views-components/side-panel-button/side-panel-button.tsx b/src/views-components/side-panel-button/side-panel-button.tsx index f0543b4c..5e547740 100644 --- a/src/views-components/side-panel-button/side-panel-button.tsx +++ b/src/views-components/side-panel-button/side-panel-button.tsx @@ -5,15 +5,19 @@ 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 { navigateToRunProcess } from '~/store/navigation/navigation-action'; +import { runProcessPanelActions } from '~/store/run-process-panel/run-process-panel-actions'; +import { getUserUuid } from '~/common/getuser'; import { matchProjectRoute } from '~/routes/routes'; +import { GroupResource } from '~/models/group'; +import { ResourcesState, getResource } from '~/store/resources/resources'; +import { extractUuidKind, ResourceKind } from '~/models/resource'; type CssRules = 'button' | 'menuItem' | 'icon'; @@ -33,8 +37,10 @@ const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ }); interface SidePanelDataProps { + location: any; currentItemId: string; - showButton: boolean; + resources: ResourcesState; + currentUserUUID: string | undefined; } interface SidePanelState { @@ -45,19 +51,24 @@ type SidePanelProps = SidePanelDataProps & DispatchProp & WithStyles; const transformOrigin: PopoverOrigin = { vertical: -50, - horizontal: 45 + horizontal: 0 }; -const checkButtonVisibility = ({ router }: RootState) => { - const pathname = router.location ? router.location.pathname : ''; - const match = matchProjectRoute(pathname); - return !!match; +const isProjectTrashed = (proj: GroupResource, resources: ResourcesState): boolean => { + if (proj.isTrashed) { return true; } + if (extractUuidKind(proj.ownerUuid) === ResourceKind.USER) { return false; } + const parentProj = getResource(proj.ownerUuid)(resources); + return isProjectTrashed(parentProj!, resources); }; export const SidePanelButton = withStyles(styles)( connect((state: RootState) => ({ - currentItemId: getProperty(PROJECT_PANEL_CURRENT_UUID)(state.properties), - showButton: checkButtonVisibility(state) + currentItemId: state.router.location + ? state.router.location.pathname.split('/').slice(-1)[0] + : null, + location: state.router.location, + resources: state.resources, + currentUserUUID: getUserUuid(state), }))( class extends React.Component { @@ -66,12 +77,24 @@ export const SidePanelButton = withStyles(styles)( }; render() { - const { classes, showButton } = this.props; + const { classes, location, resources, currentUserUUID, currentItemId } = this.props; const { anchorEl } = this.state; + let enabled = false; + if (currentItemId === currentUserUUID) { + enabled = true; + } else if (matchProjectRoute(location ? location.pathname : '')) { + const currentProject = getResource(currentItemId)(resources); + if (currentProject && + currentProject.writableBy.indexOf(currentUserUUID || '') >= 0 && + !isProjectTrashed(currentProject, resources)) { + enabled = true; + } + } return - {showButton && - -