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';
18 import { SortDirection } from '../../components/data-table/data-column';
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 onItemRouteChange: (itemId: string) => void
32 & WithStyles<CssRules>
33 & RouteComponentProps<{ id: string }>;
34 class ProjectPanel extends React.Component<ProjectPanelProps> {
37 <div className={this.props.classes.toolbar}>
38 <Button color="primary" variant="raised" className={this.props.classes.button}>
41 <Button color="primary" variant="raised" className={this.props.classes.button}>
44 <Button color="primary" variant="raised" className={this.props.classes.button}>
50 contextActions={contextMenuActions}
51 onRowClick={this.props.onItemClick}
52 onContextAction={this.executeAction} />;
56 componentWillReceiveProps({ match, currentItemId }: ProjectPanelProps) {
57 if (match.params.id !== currentItemId) {
58 this.props.onItemRouteChange(match.params.id);
62 executeAction = (action: ContextMenuAction, item: ProjectPanelItem) => {
63 alert(`Executing ${action.name} on ${item.name}`);
68 type CssRules = "toolbar" | "button";
70 const styles: StyleRulesCallback<CssRules> = theme => ({
72 paddingBottom: theme.spacing.unit * 3,
76 marginLeft: theme.spacing.unit
80 const renderName = (item: ProjectPanelItem) =>
90 <Typography color="primary">
97 const renderIcon = (item: ProjectPanelItem) => {
99 case ResourceKind.Project:
100 return <i className="fas fa-folder fa-lg" />;
101 case ResourceKind.Collection:
102 return <i className="fas fa-archive fa-lg" />;
103 case ResourceKind.Process:
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">
151 export enum ProjectPanelColumnNames {
156 FileSize = "File size",
157 LastModified = "Last modified"
161 export const columns: DataColumns<ProjectPanelItem, ProjectPanelFilter> = [{
162 name: ProjectPanelColumnNames.Name,
164 sortDirection: SortDirection.Asc,
171 name: ContainerRequestState.Committed,
173 type: ContainerRequestState.Committed
175 name: ContainerRequestState.Final,
177 type: ContainerRequestState.Final
179 name: ContainerRequestState.Uncommitted,
181 type: ContainerRequestState.Uncommitted
183 render: renderStatus,
186 name: ProjectPanelColumnNames.Type,
189 name: typeToLabel(ResourceKind.Collection),
191 type: ResourceKind.Collection
193 name: typeToLabel(ResourceKind.Process),
195 type: ResourceKind.Process
197 name: typeToLabel(ResourceKind.Project),
199 type: ResourceKind.Project
201 render: item => renderType(item.kind),
204 name: ProjectPanelColumnNames.Owner,
206 render: item => renderOwner(item.owner),
209 name: ProjectPanelColumnNames.FileSize,
211 render: item => renderFileSize(item.fileSize),
214 name: ProjectPanelColumnNames.LastModified,
216 sortDirection: SortDirection.None,
217 render: item => renderDate(item.lastModified),
221 const contextMenuActions = [[{
222 icon: "fas fa-users fa-fw",
225 icon: "fas fa-sign-out-alt fa-fw",
228 icon: "fas fa-star fa-fw",
229 name: "Add to favourite"
231 icon: "fas fa-edit fa-fw",
234 icon: "fas fa-copy fa-fw",
237 icon: "fas fa-download fa-fw",
240 icon: "fas fa-trash-alt fa-fw",
245 export default withStyles(styles)(
246 connect((state: RootState) => ({ currentItemId: state.projects.currentItemId }))(