1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { ProjectPanelItem } from './project-panel-item';
7 import { Button, StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core';
8 import { DataExplorer } from "~/views-components/data-explorer/data-explorer";
9 import { DispatchProp, connect } from 'react-redux';
10 import { DataColumns } from '~/components/data-table/data-table';
11 import { RouteComponentProps } from 'react-router';
12 import { RootState } from '~/store/store';
13 import { DataTableFilterItem } from '~/components/data-table-filters/data-table-filters';
14 import { ContainerRequestState } from '~/models/container-request';
15 import { SortDirection } from '~/components/data-table/data-column';
16 import { ResourceKind } from '~/models/resource';
17 import { resourceLabel } from '~/common/labels';
18 import { ArvadosTheme } from '~/common/custom-theme';
19 import { renderName, renderStatus, renderType, renderOwner, renderFileSize, renderDate } from '~/views-components/data-explorer/renderers';
20 import { restoreBranch } from '~/store/navigation/navigation-action';
21 import { ProjectIcon } from '~/components/icon/icon';
23 type CssRules = 'root' | "toolbar" | "button";
25 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
32 paddingBottom: theme.spacing.unit * 3,
36 marginLeft: theme.spacing.unit
40 export enum ProjectPanelColumnNames {
45 FILE_SIZE = "File size",
46 LAST_MODIFIED = "Last modified"
49 export interface ProjectPanelFilter extends DataTableFilterItem {
50 type: ResourceKind | ContainerRequestState;
53 export const columns: DataColumns<ProjectPanelItem, ProjectPanelFilter> = [
55 name: ProjectPanelColumnNames.NAME,
58 sortDirection: SortDirection.ASC,
68 name: ContainerRequestState.COMMITTED,
70 type: ContainerRequestState.COMMITTED
73 name: ContainerRequestState.FINAL,
75 type: ContainerRequestState.FINAL
78 name: ContainerRequestState.UNCOMMITTED,
80 type: ContainerRequestState.UNCOMMITTED
87 name: ProjectPanelColumnNames.TYPE,
92 name: resourceLabel(ResourceKind.COLLECTION),
94 type: ResourceKind.COLLECTION
97 name: resourceLabel(ResourceKind.PROCESS),
99 type: ResourceKind.PROCESS
102 name: resourceLabel(ResourceKind.PROJECT),
104 type: ResourceKind.PROJECT
107 render: item => renderType(item.kind),
111 name: ProjectPanelColumnNames.OWNER,
114 render: item => renderOwner(item.owner),
118 name: ProjectPanelColumnNames.FILE_SIZE,
121 render: item => renderFileSize(item.fileSize),
125 name: ProjectPanelColumnNames.LAST_MODIFIED,
128 sortDirection: SortDirection.NONE,
129 render: item => renderDate(item.lastModified),
134 export const PROJECT_PANEL_ID = "projectPanel";
136 interface ProjectPanelDataProps {
137 currentItemId: string;
140 interface ProjectPanelActionProps {
141 onItemClick: (item: ProjectPanelItem) => void;
142 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: ProjectPanelItem) => void;
143 onProjectCreationDialogOpen: (ownerUuid: string) => void;
144 onCollectionCreationDialogOpen: (ownerUuid: string) => void;
145 onItemDoubleClick: (item: ProjectPanelItem) => void;
146 onItemRouteChange: (itemId: string) => void;
149 type ProjectPanelProps = ProjectPanelDataProps & ProjectPanelActionProps & DispatchProp
150 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
152 export const ProjectPanel = withStyles(styles)(
153 connect((state: RootState) => ({ currentItemId: state.projects.currentItemId }))(
154 class extends React.Component<ProjectPanelProps> {
156 const { classes } = this.props;
157 return <div className={classes.root}>
158 <div className={classes.toolbar}>
159 <Button color="primary" onClick={this.handleNewCollectionClick} variant="raised" className={classes.button}>
162 <Button color="primary" variant="raised" className={classes.button}>
165 <Button color="primary" onClick={this.handleNewProjectClick} variant="raised" className={classes.button}>
170 id={PROJECT_PANEL_ID}
172 onRowClick={this.props.onItemClick}
173 onRowDoubleClick={this.props.onItemDoubleClick}
174 onContextMenu={this.props.onContextMenu}
175 extractKey={(item: ProjectPanelItem) => item.uuid}
176 defaultIcon={ProjectIcon}
177 defaultMessages={['Your project is empty.', 'Please create a project or create a collection and upload a data.']} />
181 handleNewProjectClick = () => {
182 this.props.onProjectCreationDialogOpen(this.props.currentItemId);
185 handleNewCollectionClick = () => {
186 this.props.onCollectionCreationDialogOpen(this.props.currentItemId);
189 componentWillReceiveProps({ match, currentItemId, onItemRouteChange }: ProjectPanelProps) {
190 if (match.params.id !== currentItemId) {
191 onItemRouteChange(match.params.id);
195 componentDidMount() {
196 if (this.props.match.params.id && this.props.currentItemId === '') {
197 this.props.dispatch<any>(restoreBranch(this.props.match.params.id));