1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as 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, EditableResource } from '~/models/resource';
18 import { ResourceFileSize, ResourceLastModifiedDate, ProcessStatus, ResourceType, ResourceOwner } from '~/views-components/data-explorer/renderers';
19 import { ProjectIcon } from '~/components/icon/icon';
20 import { ResourceName } from '~/views-components/data-explorer/renderers';
21 import { ResourcesState, getResourceWithEditableStatus } from '~/store/resources/resources';
22 import { loadDetailsPanel } from '~/store/details-panel/details-panel-action';
23 import { resourceKindToContextMenuKind, openContextMenu } from '~/store/context-menu/context-menu-actions';
24 import { ProjectResource } from '~/models/project';
25 import { navigateTo } from '~/store/navigation/navigation-action';
26 import { getProperty } from '~/store/properties/properties';
27 import { PROJECT_PANEL_CURRENT_UUID } from '~/store/project-panel/project-panel-action';
28 import { DataTableDefaultView } from '~/components/data-table-default-view/data-table-default-view';
29 import { ArvadosTheme } from "~/common/custom-theme";
30 import { createTree } from '~/models/tree';
31 import { getInitialResourceTypeFilters, getInitialProcessStatusFilters } from '~/store/resource-type-filters/resource-type-filters';
33 type CssRules = 'root' | "button";
35 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
42 marginLeft: theme.spacing.unit
46 export enum ProjectPanelColumnNames {
51 FILE_SIZE = "File size",
52 LAST_MODIFIED = "Last modified"
55 export interface ProjectPanelFilter extends DataTableFilterItem {
56 type: ResourceKind | ContainerRequestState;
59 export const projectPanelColumns: DataColumns<string> = [
61 name: ProjectPanelColumnNames.NAME,
64 sortDirection: SortDirection.NONE,
65 filters: createTree(),
66 render: uuid => <ResourceName uuid={uuid} />
72 mutuallyExclusiveFilters: true,
73 filters: getInitialProcessStatusFilters(),
74 render: uuid => <ProcessStatus uuid={uuid} />,
77 name: ProjectPanelColumnNames.TYPE,
80 filters: getInitialResourceTypeFilters(),
81 render: uuid => <ResourceType uuid={uuid} />
84 name: ProjectPanelColumnNames.OWNER,
87 filters: createTree(),
88 render: uuid => <ResourceOwner uuid={uuid} />
91 name: ProjectPanelColumnNames.FILE_SIZE,
94 filters: createTree(),
95 render: uuid => <ResourceFileSize uuid={uuid} />
98 name: ProjectPanelColumnNames.LAST_MODIFIED,
101 sortDirection: SortDirection.DESC,
102 filters: createTree(),
103 render: uuid => <ResourceLastModifiedDate uuid={uuid} />
107 export const PROJECT_PANEL_ID = "projectPanel";
109 const DEFAULT_VIEW_MESSAGES = [
110 'Your project is empty.',
111 'Please create a project or create a collection and upload a data.',
114 interface ProjectPanelDataProps {
115 currentItemId: string;
116 resources: ResourcesState;
121 type ProjectPanelProps = ProjectPanelDataProps & DispatchProp
122 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
124 export const ProjectPanel = withStyles(styles)(
125 connect((state: RootState) => ({
126 currentItemId: getProperty(PROJECT_PANEL_CURRENT_UUID)(state.properties),
127 resources: state.resources,
128 isAdmin: state.auth.user!.isAdmin,
129 userUuid: state.auth.user!.uuid,
131 class extends React.Component<ProjectPanelProps> {
133 const { classes } = this.props;
134 return <div className={classes.root}>
136 id={PROJECT_PANEL_ID}
137 onRowClick={this.handleRowClick}
138 onRowDoubleClick={this.handleRowDoubleClick}
139 onContextMenu={this.handleContextMenu}
140 contextMenuColumn={true}
141 dataTableDefaultView={
142 <DataTableDefaultView
144 messages={DEFAULT_VIEW_MESSAGES} />
149 isCurrentItemChild = (resource: Resource) => {
150 return resource.ownerUuid === this.props.currentItemId;
153 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
154 const { isAdmin, userUuid, resources } = this.props;
155 const resource = getResourceWithEditableStatus<ProjectResource & EditableResource>(resourceUuid, userUuid)(resources);
156 const menuKind = resourceKindToContextMenuKind(resourceUuid, isAdmin, (resource || {} as EditableResource).isEditable);
157 if (menuKind && resource) {
158 this.props.dispatch<any>(openContextMenu(event, {
161 ownerUuid: resource.ownerUuid,
162 isTrashed: resource.isTrashed,
167 this.props.dispatch<any>(loadDetailsPanel(resourceUuid));
170 handleRowDoubleClick = (uuid: string) => {
171 this.props.dispatch<any>(navigateTo(uuid));
174 handleRowClick = (uuid: string) => {
175 this.props.dispatch(loadDetailsPanel(uuid));