X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/0cfd92ccb88a7cac4ff6d1645bbbe62386f4bb1b..3c7e3cdc547ad5468421e1c049daa94b0d4b8bc0:/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 5e547740..a219e55a 100644 --- a/src/views-components/side-panel-button/side-panel-button.tsx +++ b/src/views-components/side-panel-button/side-panel-button.tsx @@ -2,22 +2,25 @@ // // SPDX-License-Identifier: AGPL-3.0 -import * as React from 'react'; +import React from 'react'; import { connect, DispatchProp } from 'react-redux'; -import { RootState } from '~/store/store'; -import { ArvadosTheme } from '~/common/custom-theme'; +import { RootState } from 'store/store'; +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'; +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 { GroupClass, GroupResource } from 'models/group'; +import { ResourcesState, getResource } from 'store/resources/resources'; +import { extractUuidKind, ResourceKind } from 'models/resource'; +import { pluginConfig } from 'plugins'; +import { ElementListReducer } from 'common/plugintypes'; +import { Location } from 'history'; type CssRules = 'button' | 'menuItem' | 'icon'; @@ -37,7 +40,7 @@ const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ }); interface SidePanelDataProps { - location: any; + location: Location; currentItemId: string; resources: ResourcesState; currentUserUUID: string | undefined; @@ -54,11 +57,12 @@ const transformOrigin: PopoverOrigin = { horizontal: 0 }; -const isProjectTrashed = (proj: GroupResource, resources: ResourcesState): boolean => { +export const isProjectTrashed = (proj: GroupResource | undefined, resources: ResourcesState): boolean => { + if (proj === undefined) { return false; } if (proj.isTrashed) { return true; } if (extractUuidKind(proj.ownerUuid) === ResourceKind.USER) { return false; } const parentProj = getResource(proj.ownerUuid)(resources); - return isProjectTrashed(parentProj!, resources); + return isProjectTrashed(parentProj, resources); }; export const SidePanelButton = withStyles(styles)( @@ -86,14 +90,40 @@ export const SidePanelButton = withStyles(styles)( const currentProject = getResource(currentItemId)(resources); if (currentProject && currentProject.writableBy.indexOf(currentUserUUID || '') >= 0 && - !isProjectTrashed(currentProject, resources)) { + !isProjectTrashed(currentProject, resources) && + currentProject.groupClass !== GroupClass.FILTER) { enabled = true; } } + + for (const enableFn of pluginConfig.enableNewButtonMatchers) { + if (enableFn(location, currentItemId, currentUserUUID, resources)) { + enabled = true; + } + } + + let menuItems = <> + + New collection + + + Run a process + + + New project + + ; + + const reduceItemsFn: (a: React.ReactElement[], b: ElementListReducer) => React.ReactElement[] = + (a, b) => b(a, classes.menuItem); + + menuItems = React.createElement(React.Fragment, null, + pluginConfig.newButtonMenuList.reduce(reduceItemsFn, React.Children.toArray(menuItems.props.children))); + return -