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 { 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 { openCollectionCreateDialog } from '../../store/collections/collection-create-actions';
29 import { openProjectCreateDialog } from '~/store/projects/project-create-actions';
31 type CssRules = 'root' | "toolbar" | "button";
33 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
40 paddingBottom: theme.spacing.unit * 3,
44 marginLeft: theme.spacing.unit
48 export enum ProjectPanelColumnNames {
53 FILE_SIZE = "File size",
54 LAST_MODIFIED = "Last modified"
57 export interface ProjectPanelFilter extends DataTableFilterItem {
58 type: ResourceKind | ContainerRequestState;
61 export const projectPanelColumns: DataColumns<string, ProjectPanelFilter> = [
63 name: ProjectPanelColumnNames.NAME,
66 sortDirection: SortDirection.ASC,
68 render: uuid => <ResourceName uuid={uuid} />
75 render: uuid => <ProcessStatus uuid={uuid} />,
78 name: ProjectPanelColumnNames.TYPE,
83 name: resourceLabel(ResourceKind.COLLECTION),
85 type: ResourceKind.COLLECTION
88 name: resourceLabel(ResourceKind.PROCESS),
90 type: ResourceKind.PROCESS
93 name: resourceLabel(ResourceKind.PROJECT),
95 type: ResourceKind.PROJECT
98 render: uuid => <ResourceType uuid={uuid} />
101 name: ProjectPanelColumnNames.OWNER,
105 render: uuid => <ResourceOwner uuid={uuid} />
108 name: ProjectPanelColumnNames.FILE_SIZE,
112 render: uuid => <ResourceFileSize uuid={uuid} />
115 name: ProjectPanelColumnNames.LAST_MODIFIED,
118 sortDirection: SortDirection.NONE,
120 render: uuid => <ResourceLastModifiedDate uuid={uuid} />
124 export const PROJECT_PANEL_ID = "projectPanel";
126 interface ProjectPanelDataProps {
127 currentItemId: string;
128 resources: ResourcesState;
131 type ProjectPanelProps = ProjectPanelDataProps & DispatchProp
132 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
134 export const ProjectPanel = withStyles(styles)(
135 connect((state: RootState) => ({
136 currentItemId: getProperty(PROJECT_PANEL_CURRENT_UUID)(state.properties),
137 resources: state.resources
139 class extends React.Component<ProjectPanelProps> {
141 const { classes } = this.props;
142 return <div className={classes.root}>
143 <div className={classes.toolbar}>
144 <Button color="primary" onClick={this.handleNewCollectionClick} variant="raised" className={classes.button}>
147 <Button color="primary" variant="raised" className={classes.button}>
150 <Button color="primary" onClick={this.handleNewProjectClick} variant="raised" className={classes.button}>
155 id={PROJECT_PANEL_ID}
156 onRowClick={this.handleRowClick}
157 onRowDoubleClick={this.handleRowDoubleClick}
158 onContextMenu={this.handleContextMenu}
159 defaultIcon={ProjectIcon}
160 defaultMessages={['Your project is empty.', 'Please create a project or create a collection and upload a data.']}
161 contextMenuColumn={true}/>
165 handleNewProjectClick = () => {
166 this.props.dispatch<any>(openProjectCreateDialog(this.props.currentItemId));
169 handleNewCollectionClick = () => {
170 this.props.dispatch<any>(openCollectionCreateDialog(this.props.currentItemId));
173 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
174 const menuKind = resourceKindToContextMenuKind(resourceUuid);
175 const resource = getResource<ProjectResource>(resourceUuid)(this.props.resources);
176 if (menuKind && resource) {
177 this.props.dispatch<any>(openContextMenu(event, {
180 ownerUuid: resource.ownerUuid,
181 isTrashed: resource.isTrashed,
188 handleRowDoubleClick = (uuid: string) => {
189 this.props.dispatch<any>(navigateTo(uuid));
192 handleRowClick = (uuid: string) => {
193 this.props.dispatch(loadDetailsPanel(uuid));