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 { WithStyles } from '@material-ui/core';
10 import { CustomStyleRulesCallback } from 'common/custom-theme';
11 import { DataExplorer } from 'views-components/data-explorer/data-explorer';
12 import { DataColumns } from 'components/data-table/data-table';
13 import { RootState } from 'store/store';
14 import { DataTableFilterItem } from 'components/data-table-filters/data-table-filters';
15 import { ContainerRequestState } from 'models/container-request';
16 import { SortDirection } from 'components/data-table/data-column';
17 import { ResourceKind, Resource } from 'models/resource';
20 ProcessStatus as ResourceStatus,
22 ResourceOwnerWithName,
23 ResourcePortableDataHash,
27 ResourceContainerUuid,
31 ResourceParentProcess,
32 ResourceModifiedByUserUuid,
34 ResourceCreatedAtDate,
35 ResourceLastModifiedDate,
38 } from 'views-components/data-explorer/renderers';
39 import { ProjectIcon } from 'components/icon/icon';
40 import { ResourcesState, getResource } from 'store/resources/resources';
41 import { loadDetailsPanel } from 'store/details-panel/details-panel-action';
42 import { openContextMenu, resourceUuidToContextMenuKind } from 'store/context-menu/context-menu-actions';
43 import { navigateTo } from 'store/navigation/navigation-action';
44 import { getProperty } from 'store/properties/properties';
45 import { PROJECT_PANEL_CURRENT_UUID } from 'store/project-panel/project-panel-action';
46 import { ArvadosTheme } from 'common/custom-theme';
47 import { createTree } from 'models/tree';
48 import { getInitialResourceTypeFilters, getInitialProcessStatusFilters } from 'store/resource-type-filters/resource-type-filters';
49 import { GroupContentsResource } from 'services/groups-service/groups-service';
50 import { GroupClass, GroupResource } from 'models/group';
51 import { CollectionResource } from 'models/collection';
52 import { resourceIsFrozen } from 'common/frozen-resources';
53 import { ProjectResource } from 'models/project';
54 import { deselectAllOthers, toggleOne } from 'store/multiselect/multiselect-actions';
55 import { DetailsCardRoot } from 'views-components/details-card/details-card-root';
57 type CssRules = 'root' | 'button' ;
59 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
63 flexDirection: 'column',
66 marginLeft: theme.spacing(1),
70 export enum ProjectPanelColumnNames {
75 PORTABLE_DATA_HASH = 'Portable Data Hash',
76 FILE_SIZE = 'File Size',
77 FILE_COUNT = 'File Count',
79 CONTAINER_UUID = 'Container UUID',
81 OUTPUT_UUID = 'Output UUID',
82 LOG_UUID = 'Log UUID',
83 PARENT_PROCESS = 'Parent Process UUID',
84 MODIFIED_BY_USER_UUID = 'Modified by User UUID',
86 CREATED_AT = 'Date Created',
87 LAST_MODIFIED = 'Last Modified',
88 TRASH_AT = 'Trash at',
89 DELETE_AT = 'Delete at',
92 export interface ProjectPanelFilter extends DataTableFilterItem {
93 type: ResourceKind | ContainerRequestState;
96 export const projectPanelColumns: DataColumns<string, ProjectResource> = [
98 name: ProjectPanelColumnNames.NAME,
101 sort: { direction: SortDirection.NONE, field: 'name' },
102 filters: createTree(),
103 render: (uuid) => <ResourceName uuid={uuid} />,
106 name: ProjectPanelColumnNames.STATUS,
109 mutuallyExclusiveFilters: true,
110 filters: getInitialProcessStatusFilters(),
111 render: (uuid) => <ResourceStatus uuid={uuid} />,
114 name: ProjectPanelColumnNames.TYPE,
117 filters: getInitialResourceTypeFilters(),
118 render: (uuid) => <ResourceType uuid={uuid} />,
121 name: ProjectPanelColumnNames.OWNER,
124 filters: createTree(),
125 render: (uuid) => <ResourceOwnerWithName uuid={uuid} />,
128 name: ProjectPanelColumnNames.PORTABLE_DATA_HASH,
131 filters: createTree(),
132 render: (uuid) => <ResourcePortableDataHash uuid={uuid} />,
135 name: ProjectPanelColumnNames.FILE_SIZE,
138 filters: createTree(),
139 render: (uuid) => <ResourceFileSize uuid={uuid} />,
142 name: ProjectPanelColumnNames.FILE_COUNT,
145 filters: createTree(),
146 render: (uuid) => <ResourceFileCount uuid={uuid} />,
149 name: ProjectPanelColumnNames.UUID,
152 filters: createTree(),
153 render: (uuid) => <ResourceUUID uuid={uuid} />,
156 name: ProjectPanelColumnNames.CONTAINER_UUID,
159 filters: createTree(),
160 render: (uuid) => <ResourceContainerUuid uuid={uuid} />,
163 name: ProjectPanelColumnNames.RUNTIME,
166 filters: createTree(),
167 render: (uuid) => <ContainerRunTime uuid={uuid} />,
170 name: ProjectPanelColumnNames.OUTPUT_UUID,
173 filters: createTree(),
174 render: (uuid) => <ResourceOutputUuid uuid={uuid} />,
177 name: ProjectPanelColumnNames.LOG_UUID,
180 filters: createTree(),
181 render: (uuid) => <ResourceLogUuid uuid={uuid} />,
184 name: ProjectPanelColumnNames.PARENT_PROCESS,
187 filters: createTree(),
188 render: (uuid) => <ResourceParentProcess uuid={uuid} />,
191 name: ProjectPanelColumnNames.MODIFIED_BY_USER_UUID,
194 filters: createTree(),
195 render: (uuid) => <ResourceModifiedByUserUuid uuid={uuid} />,
198 name: ProjectPanelColumnNames.VERSION,
201 filters: createTree(),
202 render: (uuid) => <ResourceVersion uuid={uuid} />,
205 name: ProjectPanelColumnNames.CREATED_AT,
208 sort: { direction: SortDirection.NONE, field: 'createdAt' },
209 filters: createTree(),
210 render: (uuid) => <ResourceCreatedAtDate uuid={uuid} />,
213 name: ProjectPanelColumnNames.LAST_MODIFIED,
216 sort: { direction: SortDirection.DESC, field: 'modifiedAt' },
217 filters: createTree(),
218 render: (uuid) => <ResourceLastModifiedDate uuid={uuid} />,
221 name: ProjectPanelColumnNames.TRASH_AT,
224 sort: { direction: SortDirection.NONE, field: 'trashAt' },
225 filters: createTree(),
226 render: (uuid) => <ResourceTrashDate uuid={uuid} />,
229 name: ProjectPanelColumnNames.DELETE_AT,
232 sort: { direction: SortDirection.NONE, field: 'deleteAt' },
233 filters: createTree(),
234 render: (uuid) => <ResourceDeleteDate uuid={uuid} />,
238 export const PROJECT_PANEL_ID = 'projectPanel';
240 const DEFAULT_VIEW_MESSAGES = ['Your project is empty.', 'Please create a project or create a collection and upload a data.'];
242 interface ProjectPanelDataProps {
243 currentItemId: string;
244 resources: ResourcesState;
245 project: GroupResource;
248 dataExplorerItems: any;
252 type ProjectPanelProps = ProjectPanelDataProps & DispatchProp & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
254 const mapStateToProps = (state: RootState) => {
255 const currentItemId = getProperty<string>(PROJECT_PANEL_CURRENT_UUID)(state.properties);
256 const project = getResource<GroupResource>(currentItemId || "")(state.resources);
260 resources: state.resources,
261 userUuid: state.auth.user!.uuid,
265 export const ProjectPanel = withStyles(styles)(
266 connect(mapStateToProps)(
267 class extends React.Component<ProjectPanelProps> {
270 const { classes } = this.props;
271 return <div data-cy='project-panel' className={classes.root}>
274 id={PROJECT_PANEL_ID}
275 onRowClick={this.handleRowClick}
276 onRowDoubleClick={this.handleRowDoubleClick}
277 onContextMenu={this.handleContextMenu}
278 contextMenuColumn={true}
279 defaultViewIcon={ProjectIcon}
280 defaultViewMessages={DEFAULT_VIEW_MESSAGES}
285 isCurrentItemChild = (resource: Resource) => {
286 return resource.ownerUuid === this.props.currentItemId;
289 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
290 const { resources, isAdmin } = this.props;
291 const resource = getResource<GroupContentsResource>(resourceUuid)(resources);
292 // When viewing the contents of a filter group, all contents should be treated as read only.
293 let readonly = false;
294 const project = getResource<GroupResource>(this.props.currentItemId)(resources);
295 if (project && project.groupClass === GroupClass.FILTER) {
299 const menuKind = this.props.dispatch<any>(resourceUuidToContextMenuKind(resourceUuid, readonly));
300 if (menuKind && resource) {
301 this.props.dispatch<any>(
302 openContextMenu(event, {
305 ownerUuid: resource.ownerUuid,
306 isTrashed: 'isTrashed' in resource ? resource.isTrashed : false,
310 isFrozen: resourceIsFrozen(resource, resources),
311 description: resource.description,
312 storageClassesDesired: (resource as CollectionResource).storageClassesDesired,
313 properties: 'properties' in resource ? resource.properties : {},
317 this.props.dispatch<any>(loadDetailsPanel(resourceUuid));
320 handleRowDoubleClick = (uuid: string) => {
321 this.props.dispatch<any>(navigateTo(uuid));
324 handleRowClick = (uuid: string) => {
325 this.props.dispatch<any>(toggleOne(uuid))
326 this.props.dispatch<any>(deselectAllOthers(uuid))
327 this.props.dispatch<any>(loadDetailsPanel(uuid));