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 } 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, getResource } 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 } 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 filters: createTree(),
73 render: uuid => <ProcessStatus uuid={uuid} />,
76 name: ProjectPanelColumnNames.TYPE,
79 filters: getInitialResourceTypeFilters(),
80 render: uuid => <ResourceType uuid={uuid} />
83 name: ProjectPanelColumnNames.OWNER,
86 filters: createTree(),
87 render: uuid => <ResourceOwner uuid={uuid} />
90 name: ProjectPanelColumnNames.FILE_SIZE,
93 filters: createTree(),
94 render: uuid => <ResourceFileSize uuid={uuid} />
97 name: ProjectPanelColumnNames.LAST_MODIFIED,
100 sortDirection: SortDirection.DESC,
101 filters: createTree(),
102 render: uuid => <ResourceLastModifiedDate uuid={uuid} />
106 export const PROJECT_PANEL_ID = "projectPanel";
108 const DEFAUL_VIEW_MESSAGES = [
109 'Your project is empty.',
110 'Please create a project or create a collection and upload a data.',
113 interface ProjectPanelDataProps {
114 currentItemId: string;
115 resources: ResourcesState;
119 type ProjectPanelProps = ProjectPanelDataProps & DispatchProp
120 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
122 export const ProjectPanel = withStyles(styles)(
123 connect((state: RootState) => ({
124 currentItemId: getProperty(PROJECT_PANEL_CURRENT_UUID)(state.properties),
125 resources: state.resources,
126 isAdmin: state.auth.user!.isAdmin
128 class extends React.Component<ProjectPanelProps> {
130 const { classes } = this.props;
131 return <div className={classes.root}>
133 id={PROJECT_PANEL_ID}
134 onRowClick={this.handleRowClick}
135 onRowDoubleClick={this.handleRowDoubleClick}
136 onContextMenu={this.handleContextMenu}
137 contextMenuColumn={true}
138 dataTableDefaultView={
139 <DataTableDefaultView
141 messages={DEFAUL_VIEW_MESSAGES} />
146 isCurrentItemChild = (resource: Resource) => {
147 return resource.ownerUuid === this.props.currentItemId;
150 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
151 const menuKind = resourceKindToContextMenuKind(resourceUuid, this.props.isAdmin);
152 const resource = getResource<ProjectResource>(resourceUuid)(this.props.resources);
153 if (menuKind && resource) {
154 this.props.dispatch<any>(openContextMenu(event, {
157 ownerUuid: resource.ownerUuid,
158 isTrashed: resource.isTrashed,
163 this.props.dispatch<any>(loadDetailsPanel(resourceUuid));
166 handleRowDoubleClick = (uuid: string) => {
167 this.props.dispatch<any>(navigateTo(uuid));
170 handleRowClick = (uuid: string) => {
171 this.props.dispatch(loadDetailsPanel(uuid));