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 { PROJECT_PANEL_ID } from "../../store/project-panel/project-panel-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,
51 sortDirection: SortDirection.ASC,
60 name: ContainerRequestState.COMMITTED,
62 type: ContainerRequestState.COMMITTED
65 name: ContainerRequestState.FINAL,
67 type: ContainerRequestState.FINAL
70 name: ContainerRequestState.UNCOMMITTED,
72 type: ContainerRequestState.UNCOMMITTED
79 name: ProjectPanelColumnNames.TYPE,
83 name: resourceLabel(ResourceKind.COLLECTION),
85 type: ResourceKind.COLLECTION
88 name: resourceLabel(ResourceKind.PROCESS),
90 type: ResourceKind.PROCESS
93 name: resourceLabel(ResourceKind.PROJECT),
95 type: ResourceKind.PROJECT
98 render: item => renderType(item.kind),
102 name: ProjectPanelColumnNames.OWNER,
104 render: item => renderOwner(item.owner),
108 name: ProjectPanelColumnNames.FILE_SIZE,
110 render: item => renderFileSize(item.fileSize),
114 name: ProjectPanelColumnNames.LAST_MODIFIED,
116 sortDirection: SortDirection.NONE,
117 render: item => renderDate(item.lastModified),
122 interface ProjectPanelDataProps {
123 currentItemId: string;
126 interface ProjectPanelActionProps {
127 onItemClick: (item: ProjectPanelItem) => void;
128 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: ProjectPanelItem) => void;
129 onDialogOpen: (ownerUuid: string) => void;
130 onItemDoubleClick: (item: ProjectPanelItem) => void;
131 onItemRouteChange: (itemId: string) => void;
134 type ProjectPanelProps = ProjectPanelDataProps & ProjectPanelActionProps & DispatchProp
135 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
137 export const ProjectPanel = withStyles(styles)(
138 connect((state: RootState) => ({ currentItemId: state.projects.currentItemId }))(
139 class extends React.Component<ProjectPanelProps> {
141 const { classes } = this.props;
143 <div className={classes.toolbar}>
144 <Button color="primary" variant="raised" className={classes.button}>
147 <Button color="primary" variant="raised" className={classes.button}>
150 <Button color="primary" onClick={this.handleNewProjectClick} variant="raised" className={classes.button}>
155 id={PROJECT_PANEL_ID}
156 onRowClick={this.props.onItemClick}
157 onRowDoubleClick={this.props.onItemDoubleClick}
158 onContextMenu={this.props.onContextMenu}
159 extractKey={(item: ProjectPanelItem) => item.uuid} />
163 handleNewProjectClick = () => {
164 this.props.onDialogOpen(this.props.currentItemId);
166 componentWillReceiveProps({ match, currentItemId, onItemRouteChange }: ProjectPanelProps) {
167 if (match.params.id !== currentItemId) {
168 onItemRouteChange(match.params.id);