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";
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 ResourceLastModifiedDate,
24 } from 'views-components/data-explorer/renderers';
25 import { ProjectIcon } from 'components/icon/icon';
26 import { ResourceName } from 'views-components/data-explorer/renderers';
30 } from 'store/resources/resources';
31 import { loadDetailsPanel } from 'store/details-panel/details-panel-action';
34 resourceUuidToContextMenuKind
35 } from 'store/context-menu/context-menu-actions';
36 import { navigateTo } from 'store/navigation/navigation-action';
37 import { getProperty } from 'store/properties/properties';
38 import { PROJECT_PANEL_CURRENT_UUID } from 'store/project-panel/project-panel-action';
39 import { DataTableDefaultView } from 'components/data-table-default-view/data-table-default-view';
40 import { ArvadosTheme } from "common/custom-theme";
41 import { createTree } from 'models/tree';
43 getInitialResourceTypeFilters,
44 getInitialProcessStatusFilters
45 } from 'store/resource-type-filters/resource-type-filters';
46 import { GroupContentsResource } from 'services/groups-service/groups-service';
47 import { GroupClass, GroupResource } from 'models/group';
48 import { CollectionResource } from 'models/collection';
50 type CssRules = 'root' | "button";
52 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
57 marginLeft: theme.spacing.unit
61 export enum ProjectPanelColumnNames {
66 FILE_SIZE = "File size",
67 LAST_MODIFIED = "Last modified"
70 export interface ProjectPanelFilter extends DataTableFilterItem {
71 type: ResourceKind | ContainerRequestState;
74 export const projectPanelColumns: DataColumns<string> = [
76 name: ProjectPanelColumnNames.NAME,
79 sortDirection: SortDirection.NONE,
80 filters: createTree(),
81 render: uuid => <ResourceName uuid={uuid} />
87 mutuallyExclusiveFilters: true,
88 filters: getInitialProcessStatusFilters(),
89 render: uuid => <ProcessStatus uuid={uuid} />,
92 name: ProjectPanelColumnNames.TYPE,
95 filters: getInitialResourceTypeFilters(),
96 render: uuid => <ResourceType uuid={uuid} />
99 name: ProjectPanelColumnNames.OWNER,
102 filters: createTree(),
103 render: uuid => <ResourceOwnerWithName uuid={uuid} />
106 name: ProjectPanelColumnNames.FILE_SIZE,
109 filters: createTree(),
110 render: uuid => <ResourceFileSize uuid={uuid} />
113 name: ProjectPanelColumnNames.LAST_MODIFIED,
116 sortDirection: SortDirection.DESC,
117 filters: createTree(),
118 render: uuid => <ResourceLastModifiedDate uuid={uuid} />
122 export const PROJECT_PANEL_ID = "projectPanel";
124 const DEFAULT_VIEW_MESSAGES = [
125 'Your project is empty.',
126 'Please create a project or create a collection and upload a data.',
129 interface ProjectPanelDataProps {
130 currentItemId: string;
131 resources: ResourcesState;
134 dataExplorerItems: any;
137 type ProjectPanelProps = ProjectPanelDataProps & DispatchProp
138 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
141 export const ProjectPanel = withStyles(styles)(
142 connect((state: RootState) => ({
143 currentItemId: getProperty(PROJECT_PANEL_CURRENT_UUID)(state.properties),
144 resources: state.resources,
145 userUuid: state.auth.user!.uuid
147 class extends React.Component<ProjectPanelProps> {
149 const { classes } = this.props;
151 return <div data-cy='project-panel' className={classes.root}>
153 id={PROJECT_PANEL_ID}
154 onRowClick={this.handleRowClick}
155 onRowDoubleClick={this.handleRowDoubleClick}
156 onContextMenu={this.handleContextMenu}
157 contextMenuColumn={true}
158 dataTableDefaultView={
159 <DataTableDefaultView
161 messages={DEFAULT_VIEW_MESSAGES} />
166 isCurrentItemChild = (resource: Resource) => {
167 return resource.ownerUuid === this.props.currentItemId;
170 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
171 const { resources } = this.props;
172 const resource = getResource<GroupContentsResource>(resourceUuid)(resources);
173 // When viewing the contents of a filter group, all contents should be treated as read only.
174 let readonly = false;
175 const project = getResource<GroupResource>(this.props.currentItemId)(resources);
176 if (project && project.groupClass === GroupClass.FILTER) {
180 const menuKind = this.props.dispatch<any>(resourceUuidToContextMenuKind(resourceUuid, readonly));
181 if (menuKind && resource) {
182 this.props.dispatch<any>(openContextMenu(event, {
185 ownerUuid: resource.ownerUuid,
186 isTrashed: ('isTrashed' in resource) ? resource.isTrashed: false,
189 description: resource.description,
190 storageClassesDesired: (resource as CollectionResource).storageClassesDesired,
191 properties: ('properties' in resource) ? resource.properties : {},
194 this.props.dispatch<any>(loadDetailsPanel(resourceUuid));
197 handleRowDoubleClick = (uuid: string) => {
198 this.props.dispatch<any>(navigateTo(uuid));
201 handleRowClick = (uuid: string) => {
202 this.props.dispatch<any>(loadDetailsPanel(uuid));