1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import withStyles from '@material-ui/core/styles/withStyles';
7 import { DispatchProp, connect } from 'react-redux';
8 import { RouteComponentProps } from 'react-router';
9 import { StyleRulesCallback, WithStyles } from '@material-ui/core';
10 import { RootState } from 'store/store';
11 import { Resource } from 'models/resource';
12 import { ResourcesState, getResource } from 'store/resources/resources';
13 import { loadDetailsPanel } from 'store/details-panel/details-panel-action';
14 import { openContextMenu, resourceUuidToContextMenuKind } from 'store/context-menu/context-menu-actions';
15 import { navigateTo } from 'store/navigation/navigation-action';
16 import { getProperty } from 'store/properties/properties';
17 import { PROJECT_PANEL_CURRENT_UUID } from 'store/project-panel/project-panel-action';
18 import { ArvadosTheme } from 'common/custom-theme';
19 import { GroupContentsResource } from 'services/groups-service/groups-service';
20 import { GroupClass, GroupResource } from 'models/group';
21 import { CollectionResource } from 'models/collection';
22 import { resourceIsFrozen } from 'common/frozen-resources';
23 import { deselectAllOthers, toggleOne } from 'store/multiselect/multiselect-actions';
24 import { DetailsCardRoot } from 'views-components/details-card/details-card-root';
25 import { MPVContainer, MPVPanelContent, MPVPanelState } from 'components/multi-panel-view/multi-panel-view';
26 import { ProjectPanelData } from './project-panel-data';
27 import { ProjectPanelRun } from './project-panel-run';
29 type CssRules = 'root' | 'button' | 'mpvRoot' | 'dataExplorer';
31 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
35 flexDirection: 'column',
38 marginLeft: theme.spacing.unit,
43 flexDirection: 'column',
53 const panelsData: MPVPanelState[] = [
54 { name: "Data", visible: true },
55 { name: "Workflow Runs", visible: false },
58 interface ProjectPanelDataProps {
59 currentItemId: string;
60 resources: ResourcesState;
61 project: GroupResource;
64 dataExplorerItems: any;
68 type ProjectPanelProps = ProjectPanelDataProps & DispatchProp & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
70 const mapStateToProps = (state: RootState) => {
71 const currentItemId = getProperty<string>(PROJECT_PANEL_CURRENT_UUID)(state.properties);
72 const project = getResource<GroupResource>(currentItemId || "")(state.resources);
76 resources: state.resources,
77 userUuid: state.auth.user!.uuid,
81 export const ProjectPanel = withStyles(styles)(
82 connect(mapStateToProps)(
83 class extends React.Component<ProjectPanelProps> {
86 const { classes } = this.props;
87 return <div data-cy='project-panel' className={classes.root}>
90 className={classes.mpvRoot}
92 panelStates={panelsData}
94 justify-content="flex-start"
100 data-cy="process-data"
101 className={classes.dataExplorer}>
103 onRowClick={this.handleRowClick}
104 onRowDoubleClick={this.handleRowDoubleClick}
105 onContextMenu={this.handleContextMenu}
111 data-cy="process-run"
112 className={classes.dataExplorer}>
114 onRowClick={this.handleRowClick}
115 onRowDoubleClick={this.handleRowDoubleClick}
116 onContextMenu={this.handleContextMenu}
123 isCurrentItemChild = (resource: Resource) => {
124 return resource.ownerUuid === this.props.currentItemId;
127 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
128 const { resources, isAdmin } = this.props;
129 const resource = getResource<GroupContentsResource>(resourceUuid)(resources);
130 // When viewing the contents of a filter group, all contents should be treated as read only.
131 let readonly = false;
132 const project = getResource<GroupResource>(this.props.currentItemId)(resources);
133 if (project && project.groupClass === GroupClass.FILTER) {
137 const menuKind = this.props.dispatch<any>(resourceUuidToContextMenuKind(resourceUuid, readonly));
138 if (menuKind && resource) {
139 this.props.dispatch<any>(
140 openContextMenu(event, {
143 ownerUuid: resource.ownerUuid,
144 isTrashed: 'isTrashed' in resource ? resource.isTrashed : false,
148 isFrozen: resourceIsFrozen(resource, resources),
149 description: resource.description,
150 storageClassesDesired: (resource as CollectionResource).storageClassesDesired,
151 properties: 'properties' in resource ? resource.properties : {},
155 this.props.dispatch<any>(loadDetailsPanel(resourceUuid));
158 handleRowDoubleClick = (uuid: string) => {
159 this.props.dispatch<any>(navigateTo(uuid));
162 handleRowClick = (uuid: string) => {
163 this.props.dispatch<any>(toggleOne(uuid))
164 this.props.dispatch<any>(deselectAllOthers(uuid))
165 this.props.dispatch<any>(loadDetailsPanel(uuid));