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 { Button, StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core';
8 import { DataExplorer } from "../../views-components/data-explorer/data-explorer";
9 import { DispatchProp, connect } from 'react-redux';
10 import { DataColumns } from '../../components/data-table/data-table';
11 import { RouteComponentProps } from 'react-router';
12 import { RootState } from '../../store/store';
13 import { DataTableFilterItem } from '../../components/data-table-filters/data-table-filters';
14 import { ContainerRequestState } from '../../models/container-request';
15 import { SortDirection } from '../../components/data-table/data-column';
16 import { ResourceKind } from '../../models/resource';
17 import { resourceLabel } from '../../common/labels';
18 import { ArvadosTheme } from '../../common/custom-theme';
19 import { renderName, renderStatus, renderType, renderOwner, renderFileSize, renderDate } from '../../views-components/data-explorer/renderers';
21 type CssRules = "toolbar" | "button";
23 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
25 paddingBottom: theme.spacing.unit * 3,
29 marginLeft: theme.spacing.unit
33 export enum ProjectPanelColumnNames {
38 FILE_SIZE = "File size",
39 LAST_MODIFIED = "Last modified"
42 export interface ProjectPanelFilter extends DataTableFilterItem {
43 type: ResourceKind | ContainerRequestState;
46 export const columns: DataColumns<ProjectPanelItem, ProjectPanelFilter> = [
48 name: ProjectPanelColumnNames.NAME,
51 sortDirection: SortDirection.ASC,
61 name: ContainerRequestState.COMMITTED,
63 type: ContainerRequestState.COMMITTED
66 name: ContainerRequestState.FINAL,
68 type: ContainerRequestState.FINAL
71 name: ContainerRequestState.UNCOMMITTED,
73 type: ContainerRequestState.UNCOMMITTED
80 name: ProjectPanelColumnNames.TYPE,
85 name: resourceLabel(ResourceKind.COLLECTION),
87 type: ResourceKind.COLLECTION
90 name: resourceLabel(ResourceKind.PROCESS),
92 type: ResourceKind.PROCESS
95 name: resourceLabel(ResourceKind.PROJECT),
97 type: ResourceKind.PROJECT
100 render: item => renderType(item.kind),
104 name: ProjectPanelColumnNames.OWNER,
107 render: item => renderOwner(item.owner),
111 name: ProjectPanelColumnNames.FILE_SIZE,
114 render: item => renderFileSize(item.fileSize),
118 name: ProjectPanelColumnNames.LAST_MODIFIED,
121 sortDirection: SortDirection.NONE,
122 render: item => renderDate(item.lastModified),
127 export const PROJECT_PANEL_ID = "projectPanel";
129 interface ProjectPanelDataProps {
130 currentItemId: string;
133 interface ProjectPanelActionProps {
134 onItemClick: (item: ProjectPanelItem) => void;
135 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: ProjectPanelItem) => void;
136 onProjectCreationDialogOpen: (ownerUuid: string) => void;
137 onCollectionCreationDialogOpen: (ownerUuid: string) => void;
138 onItemDoubleClick: (item: ProjectPanelItem) => void;
139 onItemRouteChange: (itemId: string) => void;
142 type ProjectPanelProps = ProjectPanelDataProps & ProjectPanelActionProps & DispatchProp
143 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
145 export const ProjectPanel = withStyles(styles)(
146 connect((state: RootState) => ({ currentItemId: state.projects.currentItemId }))(
147 class extends React.Component<ProjectPanelProps> {
149 const { classes } = this.props;
151 <div className={classes.toolbar}>
152 <Button color="primary" onClick={this.handleNewCollectionClick} variant="raised" className={classes.button}>
155 <Button color="primary" variant="raised" className={classes.button}>
158 <Button color="primary" onClick={this.handleNewProjectClick} variant="raised" className={classes.button}>
163 id={PROJECT_PANEL_ID}
165 onRowClick={this.props.onItemClick}
166 onRowDoubleClick={this.props.onItemDoubleClick}
167 onContextMenu={this.props.onContextMenu}
168 extractKey={(item: ProjectPanelItem) => item.uuid} />
172 handleNewProjectClick = () => {
173 this.props.onProjectCreationDialogOpen(this.props.currentItemId);
176 handleNewCollectionClick = () => {
177 this.props.onCollectionCreationDialogOpen(this.props.currentItemId);
179 componentWillReceiveProps({ match, currentItemId, onItemRouteChange }: ProjectPanelProps) {
180 if (match.params.id !== currentItemId) {
181 onItemRouteChange(match.params.id);