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, Toolbar, 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 { ContextMenuAction } from '../../components/context-menu/context-menu';
11 import { DispatchProp, connect } from 'react-redux';
12 import { DataColumns } from '../../components/data-table/data-table';
13 import { RouteComponentProps } from 'react-router';
14 import { RootState } from '../../store/store';
15 import { ResourceKind } from '../../models/kinds';
16 import { DataTableFilterItem } from '../../components/data-table-filters/data-table-filters';
18 export const PROJECT_PANEL_ID = "projectPanel";
20 export interface ProjectPanelFilter extends DataTableFilterItem {
24 type ProjectPanelProps = {
25 currentItemId: string,
26 onItemClick: (item: ProjectPanelItem) => void,
27 onItemRouteChange: (itemId: string) => void
30 & WithStyles<CssRules>
31 & RouteComponentProps<{ id: string }>;
32 class ProjectPanel extends React.Component<ProjectPanelProps> {
35 <div className={this.props.classes.toolbar}>
36 <Button color="primary" variant="raised" className={this.props.classes.button}>
39 <Button color="primary" variant="raised" className={this.props.classes.button}>
42 <Button color="primary" variant="raised" className={this.props.classes.button}>
48 contextActions={contextMenuActions}
49 onRowClick={this.props.onItemClick}
50 onContextAction={this.executeAction} />;
54 componentWillReceiveProps({ match, currentItemId }: ProjectPanelProps) {
55 if (match.params.id !== currentItemId) {
56 this.props.onItemRouteChange(match.params.id);
60 executeAction = (action: ContextMenuAction, item: ProjectPanelItem) => {
61 alert(`Executing ${action.name} on ${item.name}`);
66 type CssRules = "toolbar" | "button";
68 const styles: StyleRulesCallback<CssRules> = theme => ({
70 paddingBottom: theme.spacing.unit * 3,
74 marginLeft: theme.spacing.unit
78 const renderName = (item: ProjectPanelItem) =>
88 <Typography color="primary">
95 const renderIcon = (item: ProjectPanelItem) => {
97 case ResourceKind.Project:
98 return <i className="fas fa-folder fa-lg" />;
99 case ResourceKind.Collection:
100 return <i className="fas fa-archive fa-lg" />;
101 case ResourceKind.Process:
102 case ResourceKind.Workflow:
103 return <i className="fas fa-cogs fa-lg" />;
109 const renderDate = (date: string) =>
114 const renderFileSize = (fileSize?: number) =>
116 {formatFileSize(fileSize)}
119 const renderOwner = (owner: string) =>
120 <Typography noWrap color="primary">
126 const typeToLabel = (type: string) => {
128 case ResourceKind.Collection:
129 return "Data collection";
130 case ResourceKind.Project:
132 case ResourceKind.Process:
139 const renderType = (type: string) => {
140 return <Typography noWrap>
145 const renderStatus = (item: ProjectPanelItem) =>
146 <Typography noWrap align="center">
152 export const columns: DataColumns<ProjectPanelItem, ProjectPanelFilter> = [{
155 sortDirection: "desc",
161 render: renderStatus,
167 name: typeToLabel(ResourceKind.Collection),
169 type: ResourceKind.Collection
171 name: typeToLabel(ResourceKind.Process),
173 type: ResourceKind.Process
175 name: typeToLabel(ResourceKind.Project),
177 type: ResourceKind.Project
179 render: item => renderType(item.kind),
184 render: item => renderOwner(item.owner),
189 render: item => renderFileSize(item.fileSize),
192 name: "Last modified",
194 sortDirection: "none",
195 render: item => renderDate(item.lastModified),
199 const contextMenuActions = [[{
200 icon: "fas fa-users fa-fw",
203 icon: "fas fa-sign-out-alt fa-fw",
206 icon: "fas fa-star fa-fw",
207 name: "Add to favourite"
209 icon: "fas fa-edit fa-fw",
212 icon: "fas fa-copy fa-fw",
215 icon: "fas fa-download fa-fw",
218 icon: "fas fa-trash-alt fa-fw",
223 export default withStyles(styles)(
224 connect((state: RootState) => ({ currentItemId: state.projects.currentItemId }))(