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 => <ResourceOwner 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 }>;
140 let data: any[] = [];
141 let href: string = '';
143 export const ProjectPanel = withStyles(styles)(
144 connect((state: RootState) => ({
145 currentItemId: getProperty(PROJECT_PANEL_CURRENT_UUID)(state.properties),
146 resources: state.resources,
147 userUuid: state.auth.user!.uuid,
148 dataExplorerItems: state.dataExplorer?.projectPanel.items,
150 class extends React.Component<ProjectPanelProps> {
152 const { classes, dataExplorerItems } = this.props;
155 if (dataExplorerItems.length > 0 && data === dataExplorerItems && href !== window.location.href) {
158 href = window.location.href;
159 data = dataExplorerItems;
162 return <div data-cy='project-panel' className={classes.root}>
165 id={PROJECT_PANEL_ID}
166 onRowClick={this.handleRowClick}
167 onRowDoubleClick={this.handleRowDoubleClick}
168 onContextMenu={this.handleContextMenu}
169 contextMenuColumn={true}
170 dataTableDefaultView={
171 <DataTableDefaultView
173 messages={DEFAULT_VIEW_MESSAGES} />
178 isCurrentItemChild = (resource: Resource) => {
179 return resource.ownerUuid === this.props.currentItemId;
182 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
183 const { resources } = this.props;
184 const resource = getResource<GroupContentsResource>(resourceUuid)(resources);
185 // When viewing the contents of a filter group, all contents should be treated as read only.
186 let readonly = false;
187 const project = getResource<GroupResource>(this.props.currentItemId)(resources);
188 if (project && project.groupClass === GroupClass.FILTER) {
192 const menuKind = this.props.dispatch<any>(resourceUuidToContextMenuKind(resourceUuid, readonly));
193 if (menuKind && resource) {
194 this.props.dispatch<any>(openContextMenu(event, {
197 ownerUuid: resource.ownerUuid,
198 isTrashed: ('isTrashed' in resource) ? resource.isTrashed: false,
201 description: resource.description,
202 storageClassesDesired: (resource as CollectionResource).storageClassesDesired,
205 this.props.dispatch<any>(loadDetailsPanel(resourceUuid));
208 handleRowDoubleClick = (uuid: string) => {
209 this.props.dispatch<any>(navigateTo(uuid));
212 handleRowClick = (uuid: string) => {
213 this.props.dispatch<any>(loadDetailsPanel(uuid));