X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/5fd5db805554d3eddd46cc911a5108fbb74b3cfc..b3ed96a047c8db5febae40b6f186a656589167d8:/src/views/project-panel/project-panel.tsx?ds=sidebyside diff --git a/src/views/project-panel/project-panel.tsx b/src/views/project-panel/project-panel.tsx index 68cbc8ec..fbafdbe0 100644 --- a/src/views/project-panel/project-panel.tsx +++ b/src/views/project-panel/project-panel.tsx @@ -3,46 +3,223 @@ // SPDX-License-Identifier: AGPL-3.0 import * as React from 'react'; +import { ProjectPanelItem } from './project-panel-item'; +import { Grid, Typography, Button, StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core'; +import { FORMAT_DATE, FORMAT_FILE_SIZE } from '../../common/formatters'; +import DataExplorer from "../../views-components/data-explorer/data-explorer"; +import { DispatchProp, connect } from 'react-redux'; +import { DataColumns } from '../../components/data-table/data-table'; import { RouteComponentProps } from 'react-router'; -import { ProjectState } from '../../store/project/project-reducer'; import { RootState } from '../../store/store'; -import { connect, DispatchProp } from 'react-redux'; -import { CollectionState } from "../../store/collection/collection-reducer"; -import { setProjectItem } from "../../store/navigation/navigation-action"; -import ProjectExplorer, { ProjectExplorerContextActions } from "../../views-components/project-explorer/project-explorer"; -import { projectExplorerItems } from "./project-panel-selectors"; -import { ProjectExplorerItem } from "../../views-components/project-explorer/project-explorer-item"; +import { DataTableFilterItem } from '../../components/data-table-filters/data-table-filters'; +import { ContainerRequestState } from '../../models/container-request'; +import { SortDirection } from '../../components/data-table/data-column'; +import { ResourceKind } from '../../models/resource'; +import { RESOURCE_LABEL } from '../../common/labels'; +import { ProjectIcon, CollectionIcon, ProcessIcon, DefaultIcon } from '../../components/icon/icon'; +import { ArvadosTheme } from '../../common/custom-theme'; + +export const PROJECT_PANEL_ID = "projectPanel"; + +export interface ProjectPanelFilter extends DataTableFilterItem { + type: ResourceKind | ContainerRequestState; +} interface ProjectPanelDataProps { - projects: ProjectState; - collections: CollectionState; + currentItemId: string; } -type ProjectPanelProps = ProjectPanelDataProps & RouteComponentProps<{ name: string }> & DispatchProp; +interface ProjectPanelActionProps { + onItemClick: (item: ProjectPanelItem) => void; + onContextMenu: (event: React.MouseEvent, item: ProjectPanelItem) => void; + onDialogOpen: (ownerUuid: string) => void; + onItemDoubleClick: (item: ProjectPanelItem) => void; + onItemRouteChange: (itemId: string) => void; +} + +type ProjectPanelProps = ProjectPanelDataProps & ProjectPanelActionProps & DispatchProp + & WithStyles & RouteComponentProps<{ id: string }>; class ProjectPanel extends React.Component { render() { - const items = projectExplorerItems( - this.props.projects.items, - this.props.projects.currentItemId, - this.props.collections - ); - return ( - - ); + const { classes } = this.props; + return
+
+ + + +
+ item.uuid} /> +
; + } + + handleNewProjectClick = () => { + this.props.onDialogOpen(this.props.currentItemId); } + componentWillReceiveProps({ match, currentItemId, onItemRouteChange }: ProjectPanelProps) { + if (match.params.id !== currentItemId) { + onItemRouteChange(match.params.id); + } + } +} + +type CssRules = "toolbar" | "button"; + +const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ + toolbar: { + paddingBottom: theme.spacing.unit * 3, + textAlign: "right" + }, + button: { + marginLeft: theme.spacing.unit + }, +}); + +const RENDER_NAME = (item: ProjectPanelItem) => + + + {RENDER_ICON(item)} + + + + {item.name} + + + ; - goToItem = (item: ProjectExplorerItem) => { - this.props.dispatch(setProjectItem(this.props.projects.items, item.uuid, item.kind)); + +const RENDER_ICON = (item: ProjectPanelItem) => { + switch (item.kind) { + case ResourceKind.Project: + return ; + case ResourceKind.Collection: + return ; + case ResourceKind.Process: + return ; + default: + return ; } +}; + +const RENDER_DATE = (date: string) => { + return {FORMAT_DATE(date)}; +}; + +const RENDER_FILE_SIZE = (fileSize?: number) => + + {FORMAT_FILE_SIZE(fileSize)} + ; + +const RENDER_OWNER = (owner: string) => + + {owner} + ; + +const RENDER_TYPE = (type: string) => + + {RESOURCE_LABEL(type)} + ; + +const RENDER_STATUS = (item: ProjectPanelItem) => + + {item.status || "-"} + ; + +export enum ColumnNames { + NAME = "Name", + STATUS = "Status", + TYPE = "Type", + OWNER = "Owner", + FILE_SIZE = "File size", + LAST_MODIFIED = "Last modified" + } -export default connect( - (state: RootState) => ({ - projects: state.projects, - collections: state.collections - }) -)(ProjectPanel); +export const COLUMNS: DataColumns = [ + { + name: ColumnNames.NAME, + selected: true, + sortDirection: SortDirection.Asc, + render: RENDER_NAME, + width: "450px" + }, + { + name: "Status", + selected: true, + filters: [ + { + name: ContainerRequestState.Committed, + selected: true, + type: ContainerRequestState.Committed + }, + { + name: ContainerRequestState.Final, + selected: true, + type: ContainerRequestState.Final + }, + { + name: ContainerRequestState.Uncommitted, + selected: true, + type: ContainerRequestState.Uncommitted + } + ], + render: RENDER_STATUS, + width: "75px" + }, + { + name: ColumnNames.TYPE, + selected: true, + filters: [ + { + name: RESOURCE_LABEL(ResourceKind.Collection), + selected: true, + type: ResourceKind.Collection + }, + { + name: RESOURCE_LABEL(ResourceKind.Process), + selected: true, + type: ResourceKind.Process + }, + { + name: RESOURCE_LABEL(ResourceKind.Project), + selected: true, + type: ResourceKind.Project + } + ], + render: item => RENDER_TYPE(item.kind), + width: "125px" + }, + { + name: ColumnNames.OWNER, + selected: true, + render: item => RENDER_OWNER(item.owner), + width: "200px" + }, + { + name: ColumnNames.FILE_SIZE, + selected: true, + render: item => RENDER_FILE_SIZE(item.fileSize), + width: "50px" + }, + { + name: ColumnNames.LAST_MODIFIED, + selected: true, + sortDirection: SortDirection.None, + render: item => RENDER_DATE(item.lastModified), + width: "150px" + } +]; + +export default withStyles(styles)( + connect((state: RootState) => ({ currentItemId: state.projects.currentItemId }))(ProjectPanel));