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 actions from "../../store/data-explorer/data-explorer-action";
13 import { DataColumns } from '../../components/data-table/data-table';
14 import { ResourceKind } from "../../models/resource";
15 import { RouteComponentProps } from 'react-router';
16 import { RootState } from '../../store/store';
18 export const PROJECT_PANEL_ID = "projectPanel";
20 type ProjectPanelProps = {
21 currentItemId: string,
22 onItemClick: (item: ProjectPanelItem) => void,
23 onItemRouteChange: (itemId: string) => void
26 & WithStyles<CssRules>
27 & RouteComponentProps<{ id: string }>;
28 class ProjectPanel extends React.Component<ProjectPanelProps> {
31 <div className={this.props.classes.toolbar}>
32 <Button color="primary" variant="raised" className={this.props.classes.button}>
35 <Button color="primary" variant="raised" className={this.props.classes.button}>
38 <Button color="primary" variant="raised" className={this.props.classes.button}>
44 contextActions={contextMenuActions}
45 onRowClick={this.props.onItemClick}
46 onContextAction={this.executeAction} />;
50 componentWillReceiveProps({ match, currentItemId }: ProjectPanelProps) {
51 if (match.params.id !== currentItemId) {
52 this.props.onItemRouteChange(match.params.id);
56 executeAction = (action: ContextMenuAction, item: ProjectPanelItem) => {
57 alert(`Executing ${action.name} on ${item.name}`);
62 type CssRules = "toolbar" | "button";
64 const styles: StyleRulesCallback<CssRules> = theme => ({
66 paddingBottom: theme.spacing.unit * 3,
70 marginLeft: theme.spacing.unit
74 const renderName = (item: ProjectPanelItem) =>
84 <Typography color="primary">
91 const renderIcon = (item: ProjectPanelItem) => {
93 case ResourceKind.PROJECT:
94 return <i className="fas fa-folder fa-lg" />;
95 case ResourceKind.COLLECTION:
96 return <i className="fas fa-th fa-lg" />;
102 const renderDate = (date: string) =>
107 const renderFileSize = (fileSize?: number) =>
109 {formatFileSize(fileSize)}
112 const renderOwner = (owner: string) =>
113 <Typography noWrap color="primary">
117 const renderType = (type: string) =>
122 const renderStatus = (item: ProjectPanelItem) =>
123 <Typography noWrap align="center">
127 export const columns: DataColumns<ProjectPanelItem> = [{
130 sortDirection: "desc",
136 render: renderStatus,
148 render: item => renderType(item.kind),
153 render: item => renderOwner(item.owner),
158 render: item => renderFileSize(item.fileSize),
161 name: "Last modified",
163 sortDirection: "none",
164 render: item => renderDate(item.lastModified),
168 const contextMenuActions = [[{
169 icon: "fas fa-users fa-fw",
172 icon: "fas fa-sign-out-alt fa-fw",
175 icon: "fas fa-star fa-fw",
176 name: "Add to favourite"
178 icon: "fas fa-edit fa-fw",
181 icon: "fas fa-copy fa-fw",
184 icon: "fas fa-download fa-fw",
187 icon: "fas fa-trash-alt fa-fw",
192 export default withStyles(styles)(
193 connect((state: RootState) => ({ currentItemId: state.projects.currentItemId }))(