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';
20 import { restoreBranch } from '../../store/navigation/navigation-action';
22 type CssRules = "toolbar" | "button";
24 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
26 paddingBottom: theme.spacing.unit * 3,
30 marginLeft: theme.spacing.unit
34 export enum ProjectPanelColumnNames {
39 FILE_SIZE = "File size",
40 LAST_MODIFIED = "Last modified"
43 export interface ProjectPanelFilter extends DataTableFilterItem {
44 type: ResourceKind | ContainerRequestState;
47 export const columns: DataColumns<ProjectPanelItem, ProjectPanelFilter> = [
49 name: ProjectPanelColumnNames.NAME,
52 sortDirection: SortDirection.ASC,
62 name: ContainerRequestState.COMMITTED,
64 type: ContainerRequestState.COMMITTED
67 name: ContainerRequestState.FINAL,
69 type: ContainerRequestState.FINAL
72 name: ContainerRequestState.UNCOMMITTED,
74 type: ContainerRequestState.UNCOMMITTED
81 name: ProjectPanelColumnNames.TYPE,
86 name: resourceLabel(ResourceKind.COLLECTION),
88 type: ResourceKind.COLLECTION
91 name: resourceLabel(ResourceKind.PROCESS),
93 type: ResourceKind.PROCESS
96 name: resourceLabel(ResourceKind.PROJECT),
98 type: ResourceKind.PROJECT
101 render: item => renderType(item.kind),
105 name: ProjectPanelColumnNames.OWNER,
108 render: item => renderOwner(item.owner),
112 name: ProjectPanelColumnNames.FILE_SIZE,
115 render: item => renderFileSize(item.fileSize),
119 name: ProjectPanelColumnNames.LAST_MODIFIED,
122 sortDirection: SortDirection.NONE,
123 render: item => renderDate(item.lastModified),
128 export const PROJECT_PANEL_ID = "projectPanel";
130 interface ProjectPanelDataProps {
131 currentItemId: string;
134 interface ProjectPanelActionProps {
135 onItemClick: (item: ProjectPanelItem) => void;
136 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: ProjectPanelItem) => void;
137 onProjectCreationDialogOpen: (ownerUuid: string) => void;
138 onCollectionCreationDialogOpen: (ownerUuid: string) => void;
139 onItemDoubleClick: (item: ProjectPanelItem) => void;
140 onItemRouteChange: (itemId: string) => void;
143 type ProjectPanelProps = ProjectPanelDataProps & ProjectPanelActionProps & DispatchProp
144 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
146 export const ProjectPanel = withStyles(styles)(
147 connect((state: RootState) => ({ currentItemId: state.projects.currentItemId }))(
148 class extends React.Component<ProjectPanelProps> {
150 const { classes } = this.props;
152 <div className={classes.toolbar}>
153 <Button color="primary" onClick={this.handleNewCollectionClick} variant="raised" className={classes.button}>
156 <Button color="primary" variant="raised" className={classes.button}>
159 <Button color="primary" onClick={this.handleNewProjectClick} variant="raised" className={classes.button}>
164 id={PROJECT_PANEL_ID}
166 onRowClick={this.props.onItemClick}
167 onRowDoubleClick={this.props.onItemDoubleClick}
168 onContextMenu={this.props.onContextMenu}
169 extractKey={(item: ProjectPanelItem) => item.uuid} />
173 handleNewProjectClick = () => {
174 this.props.onProjectCreationDialogOpen(this.props.currentItemId);
177 handleNewCollectionClick = () => {
178 this.props.onCollectionCreationDialogOpen(this.props.currentItemId);
181 componentWillReceiveProps({ match, currentItemId, onItemRouteChange }: ProjectPanelProps) {
182 if (match.params.id !== currentItemId) {
183 onItemRouteChange(match.params.id);
187 componentDidMount() {
188 if (this.props.match.params.id && this.props.currentItemId === '') {
189 this.props.dispatch<any>(restoreBranch(this.props.match.params.id));