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';
17 export const PROJECT_PANEL_ID = "projectPanel";
19 type ProjectPanelProps = {
20 currentItemId: string,
21 onItemClick: (item: ProjectPanelItem) => void,
22 onItemRouteChange: (itemId: string) => void
25 & WithStyles<CssRules>
26 & RouteComponentProps<{ id: string }>;
27 class ProjectPanel extends React.Component<ProjectPanelProps> {
30 <div className={this.props.classes.toolbar}>
31 <Button color="primary" variant="raised" className={this.props.classes.button}>
34 <Button color="primary" variant="raised" className={this.props.classes.button}>
37 <Button color="primary" variant="raised" className={this.props.classes.button}>
43 contextActions={contextMenuActions}
44 onRowClick={this.props.onItemClick}
45 onContextAction={this.executeAction} />;
49 componentWillReceiveProps({ match, currentItemId }: ProjectPanelProps) {
50 if (match.params.id !== currentItemId) {
51 this.props.onItemRouteChange(match.params.id);
55 executeAction = (action: ContextMenuAction, item: ProjectPanelItem) => {
56 alert(`Executing ${action.name} on ${item.name}`);
61 type CssRules = "toolbar" | "button";
63 const styles: StyleRulesCallback<CssRules> = theme => ({
65 paddingBottom: theme.spacing.unit * 3,
69 marginLeft: theme.spacing.unit
73 const renderName = (item: ProjectPanelItem) =>
83 <Typography color="primary">
90 const renderIcon = (item: ProjectPanelItem) => {
92 case ResourceKind.Project:
93 return <i className="fas fa-folder fa-lg" />;
94 case ResourceKind.Collection:
95 return <i className="fas fa-archive fa-lg" />;
96 case ResourceKind.Process:
97 case ResourceKind.Workflow:
98 return <i className="fas fa-cogs fa-lg" />;
104 const renderDate = (date: string) =>
109 const renderFileSize = (fileSize?: number) =>
111 {formatFileSize(fileSize)}
114 const renderOwner = (owner: string) =>
115 <Typography noWrap color="primary">
119 const getItemTypeLabel = (type: string) => {
121 case ResourceKind.Collection:
122 return "Data collection";
123 case ResourceKind.Project:
125 case ResourceKind.Process:
127 case ResourceKind.Workflow:
134 const renderType = (type: string) => {
135 return <Typography noWrap>
136 {getItemTypeLabel(type)}
140 const renderStatus = (item: ProjectPanelItem) =>
141 <Typography noWrap align="center">
145 export const columns: DataColumns<ProjectPanelItem> = [{
148 sortDirection: "desc",
154 render: renderStatus,
166 render: item => renderType(item.kind),
171 render: item => renderOwner(item.owner),
176 render: item => renderFileSize(item.fileSize),
179 name: "Last modified",
181 sortDirection: "none",
182 render: item => renderDate(item.lastModified),
186 const contextMenuActions = [[{
187 icon: "fas fa-users fa-fw",
190 icon: "fas fa-sign-out-alt fa-fw",
193 icon: "fas fa-star fa-fw",
194 name: "Add to favourite"
196 icon: "fas fa-edit fa-fw",
199 icon: "fas fa-copy fa-fw",
202 icon: "fas fa-download fa-fw",
205 icon: "fas fa-trash-alt fa-fw",
210 export default withStyles(styles)(
211 connect((state: RootState) => ({ currentItemId: state.projects.currentItemId }))(