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 { DataTableFilterItem } from '../../components/data-table-filters/data-table-filters';
15 import { ContainerRequestState } from '../../models/container-request';
16 import { SortDirection } from '../../components/data-table/data-column';
17 import { ResourceKind } from '../../models/resource';
18 import { resourceLabel } from '../../common/labels';
19 import { ProjectIcon, CollectionIcon, ProcessIcon, DefaultIcon, FavoriteIcon } from '../../components/icon/icon';
20 import { ArvadosTheme } from '../../common/custom-theme';
21 import { FavoriteStar } from '../../views-components/favorite-star/favorite-star';
23 type CssRules = "toolbar" | "button";
25 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
27 paddingBottom: theme.spacing.unit * 3,
31 marginLeft: theme.spacing.unit
35 const renderName = (item: ProjectPanelItem) =>
36 <Grid container alignItems="center" wrap="nowrap" spacing={16}>
41 <Typography color="primary">
46 <Typography variant="caption">
47 <FavoriteStar resourceUuid={item.uuid} />
53 const renderIcon = (item: ProjectPanelItem) => {
55 case ResourceKind.PROJECT:
56 return <ProjectIcon />;
57 case ResourceKind.COLLECTION:
58 return <CollectionIcon />;
59 case ResourceKind.PROCESS:
60 return <ProcessIcon />;
62 return <DefaultIcon />;
66 const renderDate = (date: string) => {
67 return <Typography noWrap>{formatDate(date)}</Typography>;
70 const renderFileSize = (fileSize?: number) =>
72 {formatFileSize(fileSize)}
75 const renderOwner = (owner: string) =>
76 <Typography noWrap color="primary" >
80 const renderType = (type: string) =>
85 const renderStatus = (item: ProjectPanelItem) =>
86 <Typography noWrap align="center" >
90 export enum ProjectPanelColumnNames {
95 FILE_SIZE = "File size",
96 LAST_MODIFIED = "Last modified"
99 export interface ProjectPanelFilter extends DataTableFilterItem {
100 type: ResourceKind | ContainerRequestState;
103 export const columns: DataColumns<ProjectPanelItem, ProjectPanelFilter> = [
105 name: ProjectPanelColumnNames.NAME,
107 sortDirection: SortDirection.ASC,
116 name: ContainerRequestState.COMMITTED,
118 type: ContainerRequestState.COMMITTED
121 name: ContainerRequestState.FINAL,
123 type: ContainerRequestState.FINAL
126 name: ContainerRequestState.UNCOMMITTED,
128 type: ContainerRequestState.UNCOMMITTED
131 render: renderStatus,
135 name: ProjectPanelColumnNames.TYPE,
139 name: resourceLabel(ResourceKind.COLLECTION),
141 type: ResourceKind.COLLECTION
144 name: resourceLabel(ResourceKind.PROCESS),
146 type: ResourceKind.PROCESS
149 name: resourceLabel(ResourceKind.PROJECT),
151 type: ResourceKind.PROJECT
154 render: item => renderType(item.kind),
158 name: ProjectPanelColumnNames.OWNER,
160 render: item => renderOwner(item.owner),
164 name: ProjectPanelColumnNames.FILE_SIZE,
166 render: item => renderFileSize(item.fileSize),
170 name: ProjectPanelColumnNames.LAST_MODIFIED,
172 sortDirection: SortDirection.NONE,
173 render: item => renderDate(item.lastModified),
178 export const PROJECT_PANEL_ID = "projectPanel";
180 interface ProjectPanelDataProps {
181 currentItemId: string;
184 interface ProjectPanelActionProps {
185 onItemClick: (item: ProjectPanelItem) => void;
186 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: ProjectPanelItem) => void;
187 onDialogOpen: (ownerUuid: string) => void;
188 onItemDoubleClick: (item: ProjectPanelItem) => void;
189 onItemRouteChange: (itemId: string) => void;
192 type ProjectPanelProps = ProjectPanelDataProps & ProjectPanelActionProps & DispatchProp
193 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
195 export const ProjectPanel = withStyles(styles)(
196 connect((state: RootState) => ({ currentItemId: state.projects.currentItemId }))(
197 class extends React.Component<ProjectPanelProps> {
199 const { classes } = this.props;
201 <div className={classes.toolbar}>
202 <Button color="primary" variant="raised" className={classes.button}>
205 <Button color="primary" variant="raised" className={classes.button}>
208 <Button color="primary" onClick={this.handleNewProjectClick} variant="raised" className={classes.button}>
213 id={PROJECT_PANEL_ID}
214 onRowClick={this.props.onItemClick}
215 onRowDoubleClick={this.props.onItemDoubleClick}
216 onContextMenu={this.props.onContextMenu}
217 extractKey={(item: ProjectPanelItem) => item.uuid} />
221 handleNewProjectClick = () => {
222 this.props.onDialogOpen(this.props.currentItemId);
224 componentWillReceiveProps({ match, currentItemId, onItemRouteChange }: ProjectPanelProps) {
225 if (match.params.id !== currentItemId) {
226 onItemRouteChange(match.params.id);