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 { 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 { ContextMenuKind } from '~/views-components/context-menu/context-menu';
24 import { contextMenuActions, resourceKindToContextMenuKind, openContextMenu } from '~/store/context-menu/context-menu-actions';
25 import { CollectionResource } from '~/models/collection';
26 import { ProjectResource } from '~/models/project';
27 import { navigateTo } from '~/store/navigation/navigation-action';
28 import { getProperty } from '~/store/properties/properties';
29 import { PROJECT_PANEL_CURRENT_UUID } from '~/store/project-panel/project-panel-action';
30 import { openCollectionCreateDialog } from '../../store/collections/collection-create-actions';
31 import { openProjectCreateDialog } from '~/store/projects/project-create-actions';
33 type CssRules = 'root' | "toolbar" | "button";
35 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
42 paddingBottom: theme.spacing.unit * 3,
46 marginLeft: theme.spacing.unit
50 export enum ProjectPanelColumnNames {
55 FILE_SIZE = "File size",
56 LAST_MODIFIED = "Last modified"
59 export interface ProjectPanelFilter extends DataTableFilterItem {
60 type: ResourceKind | ContainerRequestState;
63 export const projectPanelColumns: DataColumns<string, ProjectPanelFilter> = [
65 name: ProjectPanelColumnNames.NAME,
68 sortDirection: SortDirection.ASC,
70 render: uuid => <ResourceName uuid={uuid} />,
77 sortDirection: SortDirection.NONE,
80 name: ContainerRequestState.COMMITTED,
82 type: ContainerRequestState.COMMITTED
85 name: ContainerRequestState.FINAL,
87 type: ContainerRequestState.FINAL
90 name: ContainerRequestState.UNCOMMITTED,
92 type: ContainerRequestState.UNCOMMITTED
95 render: uuid => <ProcessStatus uuid={uuid} />,
99 name: ProjectPanelColumnNames.TYPE,
102 sortDirection: SortDirection.NONE,
105 name: resourceLabel(ResourceKind.COLLECTION),
107 type: ResourceKind.COLLECTION
110 name: resourceLabel(ResourceKind.PROCESS),
112 type: ResourceKind.PROCESS
115 name: resourceLabel(ResourceKind.PROJECT),
117 type: ResourceKind.PROJECT
120 render: uuid => <ResourceType uuid={uuid} />,
124 name: ProjectPanelColumnNames.OWNER,
127 sortDirection: SortDirection.NONE,
129 render: uuid => <ResourceOwner uuid={uuid} />,
133 name: ProjectPanelColumnNames.FILE_SIZE,
136 sortDirection: SortDirection.NONE,
138 render: uuid => <ResourceFileSize uuid={uuid} />,
142 name: ProjectPanelColumnNames.LAST_MODIFIED,
145 sortDirection: SortDirection.NONE,
147 render: uuid => <ResourceLastModifiedDate uuid={uuid} />,
152 export const PROJECT_PANEL_ID = "projectPanel";
154 interface ProjectPanelDataProps {
155 currentItemId: string;
156 resources: ResourcesState;
159 type ProjectPanelProps = ProjectPanelDataProps & DispatchProp
160 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
162 export const ProjectPanel = withStyles(styles)(
163 connect((state: RootState) => ({
164 currentItemId: getProperty(PROJECT_PANEL_CURRENT_UUID)(state.properties),
165 resources: state.resources
167 class extends React.Component<ProjectPanelProps> {
169 const { classes } = this.props;
170 return <div className={classes.root}>
171 <div className={classes.toolbar}>
172 <Button color="primary" onClick={this.handleNewCollectionClick} variant="raised" className={classes.button}>
175 <Button color="primary" variant="raised" className={classes.button}>
178 <Button color="primary" onClick={this.handleNewProjectClick} variant="raised" className={classes.button}>
183 id={PROJECT_PANEL_ID}
184 onRowClick={this.handleRowClick}
185 onRowDoubleClick={this.handleRowDoubleClick}
186 onContextMenu={this.handleContextMenu}
187 defaultIcon={ProjectIcon}
188 defaultMessages={['Your project is empty.', 'Please create a project or create a collection and upload a data.']} />
192 handleNewProjectClick = () => {
193 this.props.dispatch<any>(openProjectCreateDialog(this.props.currentItemId));
196 handleNewCollectionClick = () => {
197 this.props.dispatch<any>(openCollectionCreateDialog(this.props.currentItemId));
200 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
201 const kind = resourceKindToContextMenuKind(resourceUuid);
203 this.props.dispatch<any>(openContextMenu(event, { name: '', uuid: resourceUuid, kind }));
207 handleRowDoubleClick = (uuid: string) => {
208 this.props.dispatch<any>(navigateTo(uuid));
211 handleRowClick = (uuid: string) => {
212 this.props.dispatch(loadDetailsPanel(uuid));