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, 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 { DispatchProp, connect } from 'react-redux';
11 import { DataColumns } from '../../components/data-table/data-table';
12 import { RouteComponentProps } from 'react-router';
13 import { RootState } from '../../store/store';
14 import { ResourceKind } from '../../models/kinds';
15 import { DataTableFilterItem } from '../../components/data-table-filters/data-table-filters';
16 import { ContainerRequestState } from '../../models/container-request';
17 import { SortDirection } from '../../components/data-table/data-column';
18 import { resourceLabel } from '../../common/labels';
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 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: ProjectPanelItem) => void;
30 onDialogOpen: (ownerUuid: string) => void;
31 onItemDoubleClick: (item: ProjectPanelItem) => void,
32 onItemRouteChange: (itemId: string) => void
35 & WithStyles<CssRules>
36 & RouteComponentProps<{ id: string }>;
38 class ProjectPanel extends React.Component<ProjectPanelProps> {
41 <div className={this.props.classes.toolbar}>
42 <Button color="primary" variant="raised" className={this.props.classes.button}>
45 <Button color="primary" variant="raised" className={this.props.classes.button}>
48 <Button color="primary" onClick={() => this.props.onDialogOpen(this.props.currentItemId)} variant="raised" className={this.props.classes.button}>
54 onRowClick={this.props.onItemClick}
55 onRowDoubleClick={this.props.onItemDoubleClick}
56 onContextMenu={this.props.onContextMenu} />
60 componentWillReceiveProps({ match, currentItemId }: ProjectPanelProps) {
61 if (match.params.id !== currentItemId) {
62 this.props.onItemRouteChange(match.params.id);
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 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">
124 const renderType = (type: string) => {
125 return <Typography noWrap>
126 {resourceLabel(type)}
130 const renderStatus = (item: ProjectPanelItem) =>
131 <Typography noWrap align="center">
135 export enum ProjectPanelColumnNames {
140 FileSize = "File size",
141 LastModified = "Last modified"
145 export const columns: DataColumns<ProjectPanelItem, ProjectPanelFilter> = [{
146 name: ProjectPanelColumnNames.Name,
148 sortDirection: SortDirection.Asc,
155 name: ContainerRequestState.Committed,
157 type: ContainerRequestState.Committed
159 name: ContainerRequestState.Final,
161 type: ContainerRequestState.Final
163 name: ContainerRequestState.Uncommitted,
165 type: ContainerRequestState.Uncommitted
167 render: renderStatus,
170 name: ProjectPanelColumnNames.Type,
173 name: resourceLabel(ResourceKind.Collection),
175 type: ResourceKind.Collection
177 name: resourceLabel(ResourceKind.Process),
179 type: ResourceKind.Process
181 name: resourceLabel(ResourceKind.Project),
183 type: ResourceKind.Project
185 render: item => renderType(item.kind),
188 name: ProjectPanelColumnNames.Owner,
190 render: item => renderOwner(item.owner),
193 name: ProjectPanelColumnNames.FileSize,
195 render: item => renderFileSize(item.fileSize),
198 name: ProjectPanelColumnNames.LastModified,
200 sortDirection: SortDirection.None,
201 render: item => renderDate(item.lastModified),
206 export default withStyles(styles)(
207 connect((state: RootState) => ({ currentItemId: state.projects.currentItemId }))(