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';
17 import { ContainerRequestState } from '../../models/container-request';
19 export const PROJECT_PANEL_ID = "projectPanel";
21 export interface ProjectPanelFilter extends DataTableFilterItem {
22 type: ResourceKind | ContainerRequestState;
25 type ProjectPanelProps = {
26 currentItemId: string,
27 onItemClick: (item: ProjectPanelItem) => void,
28 onItemRouteChange: (itemId: string) => void
31 & WithStyles<CssRules>
32 & RouteComponentProps<{ id: string }>;
33 class ProjectPanel extends React.Component<ProjectPanelProps> {
36 <div className={this.props.classes.toolbar}>
37 <Button color="primary" variant="raised" className={this.props.classes.button}>
40 <Button color="primary" variant="raised" className={this.props.classes.button}>
43 <Button color="primary" variant="raised" className={this.props.classes.button}>
49 contextActions={contextMenuActions}
50 onRowClick={this.props.onItemClick}
51 onContextAction={this.executeAction} />;
55 componentWillReceiveProps({ match, currentItemId }: ProjectPanelProps) {
56 if (match.params.id !== currentItemId) {
57 this.props.onItemRouteChange(match.params.id);
61 executeAction = (action: ContextMenuAction, item: ProjectPanelItem) => {
62 alert(`Executing ${action.name} on ${item.name}`);
67 type CssRules = "toolbar" | "button";
69 const styles: StyleRulesCallback<CssRules> = theme => ({
71 paddingBottom: theme.spacing.unit * 3,
75 marginLeft: theme.spacing.unit
79 const renderName = (item: ProjectPanelItem) =>
89 <Typography color="primary">
96 const renderIcon = (item: ProjectPanelItem) => {
98 case ResourceKind.Project:
99 return <i className="fas fa-folder fa-lg" />;
100 case ResourceKind.Collection:
101 return <i className="fas fa-archive fa-lg" />;
102 case ResourceKind.Process:
103 case ResourceKind.Workflow:
104 return <i className="fas fa-cogs fa-lg" />;
110 const renderDate = (date: string) =>
115 const renderFileSize = (fileSize?: number) =>
117 {formatFileSize(fileSize)}
120 const renderOwner = (owner: string) =>
121 <Typography noWrap color="primary">
127 const typeToLabel = (type: string) => {
129 case ResourceKind.Collection:
130 return "Data collection";
131 case ResourceKind.Project:
133 case ResourceKind.Process:
140 const renderType = (type: string) => {
141 return <Typography noWrap>
146 const renderStatus = (item: ProjectPanelItem) =>
147 <Typography noWrap align="center">
153 export const columns: DataColumns<ProjectPanelItem, ProjectPanelFilter> = [{
156 sortDirection: "desc",
163 name: ContainerRequestState.Committed,
165 type: ContainerRequestState.Committed
167 name: ContainerRequestState.Final,
169 type: ContainerRequestState.Final
171 name: ContainerRequestState.Uncommitted,
173 type: ContainerRequestState.Uncommitted
175 render: renderStatus,
181 name: typeToLabel(ResourceKind.Collection),
183 type: ResourceKind.Collection
185 name: typeToLabel(ResourceKind.Process),
187 type: ResourceKind.Process
189 name: typeToLabel(ResourceKind.Project),
191 type: ResourceKind.Project
193 render: item => renderType(item.kind),
198 render: item => renderOwner(item.owner),
203 render: item => renderFileSize(item.fileSize),
206 name: "Last modified",
208 sortDirection: "none",
209 render: item => renderDate(item.lastModified),
213 const contextMenuActions = [[{
214 icon: "fas fa-users fa-fw",
217 icon: "fas fa-sign-out-alt fa-fw",
220 icon: "fas fa-star fa-fw",
221 name: "Add to favourite"
223 icon: "fas fa-edit fa-fw",
226 icon: "fas fa-copy fa-fw",
229 icon: "fas fa-download fa-fw",
232 icon: "fas fa-trash-alt fa-fw",
237 export default withStyles(styles)(
238 connect((state: RootState) => ({ currentItemId: state.projects.currentItemId }))(