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 { Grid, Typography, Button, StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core';
8 import { formatDate, formatFileSize } from '../../common/formatters';
9 import DataExplorer from "../../views-components/data-explorer/data-explorer";
10 import { DispatchProp, connect } from 'react-redux';
11 import { DataColumns } from '../../components/data-table/data-table';
12 import { RouteComponentProps } from 'react-router';
13 import { RootState } from '../../store/store';
14 import { DataTableFilterItem } from '../../components/data-table-filters/data-table-filters';
15 import { ContainerRequestState } from '../../models/container-request';
16 import { SortDirection } from '../../components/data-table/data-column';
17 import { ResourceKind } from '../../models/resource';
18 import { resourceLabel } from '../../common/labels';
20 export const PROJECT_PANEL_ID = "projectPanel";
22 export interface ProjectPanelFilter extends DataTableFilterItem {
23 type: ResourceKind | ContainerRequestState;
26 type ProjectPanelProps = {
27 currentItemId: string,
28 onItemClick: (item: ProjectPanelItem) => void,
29 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: ProjectPanelItem) => void;
30 onDialogOpen: (ownerUuid: string) => void;
31 onItemDoubleClick: (item: ProjectPanelItem) => void,
32 onItemRouteChange: (itemId: string) => void
35 & WithStyles<CssRules>
36 & RouteComponentProps<{ id: string }>;
38 class ProjectPanel extends React.Component<ProjectPanelProps> {
40 const { classes, currentItemId, onItemClick, onItemDoubleClick, onContextMenu, onDialogOpen } = this.props;
42 <div className={classes.toolbar}>
43 <Button color="primary" variant="raised" className={classes.button}>
46 <Button color="primary" variant="raised" className={classes.button}>
49 <Button color="primary" onClick={this.handleNewProjectClick} variant="raised" className={classes.button}>
55 onRowClick={this.props.onItemClick}
56 onRowDoubleClick={this.props.onItemDoubleClick}
57 onContextMenu={this.props.onContextMenu}
58 extractKey={(item: ProjectPanelItem) => item.uuid} />
62 handleNewProjectClick = () => {
63 this.props.onDialogOpen(this.props.currentItemId);
65 componentWillReceiveProps({ match, currentItemId, onItemRouteChange }: ProjectPanelProps) {
66 if (match.params.id !== currentItemId) {
67 onItemRouteChange(match.params.id);
72 type CssRules = "toolbar" | "button";
74 const styles: StyleRulesCallback<CssRules> = theme => ({
76 paddingBottom: theme.spacing.unit * 3,
80 marginLeft: theme.spacing.unit
84 const renderName = (item: ProjectPanelItem) =>
94 <Typography color="primary">
101 const renderIcon = (item: ProjectPanelItem) => {
103 case ResourceKind.Project:
104 return <i className="fas fa-folder fa-lg" />;
105 case ResourceKind.Collection:
106 return <i className="fas fa-archive fa-lg" />;
107 case ResourceKind.Process:
108 return <i className="fas fa-cogs fa-lg" />;
114 const renderDate = (date: string) =>
119 const renderFileSize = (fileSize?: number) =>
121 {formatFileSize(fileSize)}
124 const renderOwner = (owner: string) =>
125 <Typography noWrap color="primary">
129 const renderType = (type: string) => {
130 return <Typography noWrap>
131 {resourceLabel(type)}
135 const renderStatus = (item: ProjectPanelItem) =>
136 <Typography noWrap align="center">
140 export enum ProjectPanelColumnNames {
145 FileSize = "File size",
146 LastModified = "Last modified"
150 export const columns: DataColumns<ProjectPanelItem, ProjectPanelFilter> = [{
151 name: ProjectPanelColumnNames.Name,
153 sortDirection: SortDirection.Asc,
160 name: ContainerRequestState.Committed,
162 type: ContainerRequestState.Committed
164 name: ContainerRequestState.Final,
166 type: ContainerRequestState.Final
168 name: ContainerRequestState.Uncommitted,
170 type: ContainerRequestState.Uncommitted
172 render: renderStatus,
175 name: ProjectPanelColumnNames.Type,
178 name: resourceLabel(ResourceKind.Collection),
180 type: ResourceKind.Collection
182 name: resourceLabel(ResourceKind.Process),
184 type: ResourceKind.Process
186 name: resourceLabel(ResourceKind.Project),
188 type: ResourceKind.Project
190 render: item => renderType(item.kind),
193 name: ProjectPanelColumnNames.Owner,
195 render: item => renderOwner(item.owner),
198 name: ProjectPanelColumnNames.FileSize,
200 render: item => renderFileSize(item.fileSize),
203 name: ProjectPanelColumnNames.LastModified,
205 sortDirection: SortDirection.None,
206 render: item => renderDate(item.lastModified),
211 export default withStyles(styles)(
212 connect((state: RootState) => ({ currentItemId: state.projects.currentItemId }))(