1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { Button, StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core';
7 import { DataExplorer } from "~/views-components/data-explorer/data-explorer";
8 import { DispatchProp, connect } from 'react-redux';
9 import { DataColumns } from '~/components/data-table/data-table';
10 import { RouteComponentProps } from 'react-router';
11 import { RootState } from '~/store/store';
12 import { DataTableFilterItem } from '~/components/data-table-filters/data-table-filters';
13 import { ContainerRequestState } from '~/models/container-request';
14 import { SortDirection } from '~/components/data-table/data-column';
15 import { ResourceKind } from '~/models/resource';
16 import { resourceLabel } from '~/common/labels';
17 import { ArvadosTheme } from '~/common/custom-theme';
18 import { ResourceFileSize, ResourceLastModifiedDate, ProcessStatus, ResourceType, ResourceOwner } from '~/views-components/data-explorer/renderers';
19 import { restoreBranch, setProjectItem, ItemMode } from '~/store/navigation/navigation-action';
20 import { ProjectIcon } from '~/components/icon/icon';
21 import { ResourceName } from '~/views-components/data-explorer/renderers';
22 import { ResourcesState, getResource } from '~/store/resources/resources';
23 import { loadDetailsPanel } from '~/store/details-panel/details-panel-action';
24 import { ContextMenuKind } from '~/views-components/context-menu/context-menu';
25 import { contextMenuActions } from '~/store/context-menu/context-menu-actions';
26 import { CollectionResource } from '~/models/collection';
27 import { ProjectResource } from '~/models/project';
28 import { openProjectCreator } from '~/store/project/project-action';
29 import { reset } from 'redux-form';
30 import { COLLECTION_CREATE_DIALOG } from '~/views-components/dialog-create/dialog-collection-create';
31 import { collectionCreateActions } from '~/store/collections/creator/collection-creator-action';
32 import { navigateToResource } from '~/store/navigation/navigation-action';
34 type CssRules = 'root' | "toolbar" | "button";
36 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
43 paddingBottom: theme.spacing.unit * 3,
47 marginLeft: theme.spacing.unit
51 export enum ProjectPanelColumnNames {
56 FILE_SIZE = "File size",
57 LAST_MODIFIED = "Last modified"
60 export interface ProjectPanelFilter extends DataTableFilterItem {
61 type: ResourceKind | ContainerRequestState;
64 export const columns: DataColumns<string, ProjectPanelFilter> = [
66 name: ProjectPanelColumnNames.NAME,
69 sortDirection: SortDirection.ASC,
71 render: uuid => <ResourceName uuid={uuid} />,
78 sortDirection: SortDirection.NONE,
81 name: ContainerRequestState.COMMITTED,
83 type: ContainerRequestState.COMMITTED
86 name: ContainerRequestState.FINAL,
88 type: ContainerRequestState.FINAL
91 name: ContainerRequestState.UNCOMMITTED,
93 type: ContainerRequestState.UNCOMMITTED
96 render: uuid => <ProcessStatus uuid={uuid} />,
100 name: ProjectPanelColumnNames.TYPE,
103 sortDirection: SortDirection.NONE,
106 name: resourceLabel(ResourceKind.COLLECTION),
108 type: ResourceKind.COLLECTION
111 name: resourceLabel(ResourceKind.PROCESS),
113 type: ResourceKind.PROCESS
116 name: resourceLabel(ResourceKind.PROJECT),
118 type: ResourceKind.PROJECT
121 render: uuid => <ResourceType uuid={uuid} />,
125 name: ProjectPanelColumnNames.OWNER,
128 sortDirection: SortDirection.NONE,
130 render: uuid => <ResourceOwner uuid={uuid} />,
134 name: ProjectPanelColumnNames.FILE_SIZE,
137 sortDirection: SortDirection.NONE,
139 render: uuid => <ResourceFileSize uuid={uuid} />,
143 name: ProjectPanelColumnNames.LAST_MODIFIED,
146 sortDirection: SortDirection.NONE,
148 render: uuid => <ResourceLastModifiedDate uuid={uuid} />,
153 export const PROJECT_PANEL_ID = "projectPanel";
155 interface ProjectPanelDataProps {
156 currentItemId: string;
157 resources: ResourcesState;
160 type ProjectPanelProps = ProjectPanelDataProps & DispatchProp
161 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
163 export const ProjectPanel = withStyles(styles)(
164 connect((state: RootState) => ({ currentItemId: state.projects.currentItemId, resources: state.resources }))(
165 class extends React.Component<ProjectPanelProps> {
167 const { classes } = this.props;
168 return <div className={classes.root}>
169 <div className={classes.toolbar}>
170 <Button color="primary" onClick={this.handleNewCollectionClick} variant="raised" className={classes.button}>
173 <Button color="primary" variant="raised" className={classes.button}>
176 <Button color="primary" onClick={this.handleNewProjectClick} variant="raised" className={classes.button}>
181 id={PROJECT_PANEL_ID}
183 onRowClick={this.handleRowClick}
184 onRowDoubleClick={this.handleRowDoubleClick}
185 onContextMenu={this.handleContextMenu}
186 defaultIcon={ProjectIcon}
187 defaultMessages={['Your project is empty.', 'Please create a project or create a collection and upload a data.']} />
191 handleNewProjectClick = () => {
192 this.props.dispatch<any>(openProjectCreator(this.props.currentItemId));
195 handleNewCollectionClick = () => {
196 this.props.dispatch(reset(COLLECTION_CREATE_DIALOG));
197 this.props.dispatch(collectionCreateActions.OPEN_COLLECTION_CREATOR({ ownerUuid: this.props.currentItemId }));
200 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
201 event.preventDefault();
202 const resource = getResource(resourceUuid)(this.props.resources) as CollectionResource | ProjectResource | undefined;
204 let kind: ContextMenuKind;
206 if (resource.kind === ResourceKind.PROJECT) {
207 kind = ContextMenuKind.PROJECT;
208 } else if (resource.kind === ResourceKind.COLLECTION) {
209 kind = ContextMenuKind.COLLECTION_RESOURCE;
211 kind = ContextMenuKind.RESOURCE;
213 if (kind !== ContextMenuKind.RESOURCE) {
215 contextMenuActions.OPEN_CONTEXT_MENU({
216 position: { x: event.clientX, y: event.clientY },
219 name: resource.name || '',
220 description: resource.description,
229 handleRowDoubleClick = (uuid: string) => {
230 this.props.dispatch<any>(navigateToResource(uuid));
233 handleRowClick = (uuid: string) => {
234 this.props.dispatch(loadDetailsPanel(uuid));
237 async componentDidMount() {
238 if (this.props.match.params.id && this.props.currentItemId === '') {
239 await this.props.dispatch<any>(restoreBranch(this.props.match.params.id));
240 this.props.dispatch<any>(setProjectItem(this.props.match.params.id, ItemMode.BOTH));