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,
67 sortDirection: SortDirection.NONE,
70 name: ContainerRequestState.COMMITTED,
72 type: ContainerRequestState.COMMITTED
75 name: ContainerRequestState.FINAL,
77 type: ContainerRequestState.FINAL
80 name: ContainerRequestState.UNCOMMITTED,
82 type: ContainerRequestState.UNCOMMITTED
89 name: ProjectPanelColumnNames.TYPE,
92 sortDirection: SortDirection.NONE,
95 name: resourceLabel(ResourceKind.COLLECTION),
97 type: ResourceKind.COLLECTION
100 name: resourceLabel(ResourceKind.PROCESS),
102 type: ResourceKind.PROCESS
105 name: resourceLabel(ResourceKind.PROJECT),
107 type: ResourceKind.PROJECT
110 render: item => renderType(item.kind),
114 name: ProjectPanelColumnNames.OWNER,
117 sortDirection: SortDirection.NONE,
119 render: item => renderOwner(item.owner),
123 name: ProjectPanelColumnNames.FILE_SIZE,
126 sortDirection: SortDirection.NONE,
128 render: item => renderFileSize(item.fileSize),
132 name: ProjectPanelColumnNames.LAST_MODIFIED,
135 sortDirection: SortDirection.NONE,
137 render: item => renderDate(item.lastModified),
142 export const PROJECT_PANEL_ID = "projectPanel";
144 interface ProjectPanelDataProps {
145 currentItemId: string;
148 interface ProjectPanelActionProps {
149 onItemClick: (item: ProjectPanelItem) => void;
150 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: ProjectPanelItem) => void;
151 onProjectCreationDialogOpen: (ownerUuid: string) => void;
152 onCollectionCreationDialogOpen: (ownerUuid: string) => void;
153 onItemDoubleClick: (item: ProjectPanelItem) => void;
154 onItemRouteChange: (itemId: string) => void;
157 type ProjectPanelProps = ProjectPanelDataProps & ProjectPanelActionProps & DispatchProp
158 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
160 export const ProjectPanel = withStyles(styles)(
161 connect((state: RootState) => ({ currentItemId: state.projects.currentItemId }))(
162 class extends React.Component<ProjectPanelProps> {
164 const { classes } = this.props;
165 return <div className={classes.root}>
166 <div className={classes.toolbar}>
167 <Button color="primary" onClick={this.handleNewCollectionClick} variant="raised" className={classes.button}>
170 <Button color="primary" variant="raised" className={classes.button}>
173 <Button color="primary" onClick={this.handleNewProjectClick} variant="raised" className={classes.button}>
178 id={PROJECT_PANEL_ID}
180 onRowClick={this.props.onItemClick}
181 onRowDoubleClick={this.props.onItemDoubleClick}
182 onContextMenu={this.props.onContextMenu}
183 extractKey={(item: ProjectPanelItem) => item.uuid}
184 defaultIcon={ProjectIcon}
185 defaultMessages={['Your project is empty.', 'Please create a project or create a collection and upload a data.']} />
189 handleNewProjectClick = () => {
190 this.props.onProjectCreationDialogOpen(this.props.currentItemId);
193 handleNewCollectionClick = () => {
194 this.props.onCollectionCreationDialogOpen(this.props.currentItemId);
197 componentWillReceiveProps({ match, currentItemId, onItemRouteChange }: ProjectPanelProps) {
198 if (match.params.id !== currentItemId) {
199 onItemRouteChange(match.params.id);
203 componentDidMount() {
204 if (this.props.match.params.id && this.props.currentItemId === '') {
205 this.props.dispatch<any>(restoreBranch(this.props.match.params.id));