X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/508746f3c7c6d7077f4290228c393e0e29d58573..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 7323ce2b..fbafdbe0 100644 --- a/src/views/project-panel/project-panel.tsx +++ b/src/views/project-panel/project-panel.tsx @@ -4,85 +4,92 @@ import * as React from 'react'; import { ProjectPanelItem } from './project-panel-item'; -import { Grid, Typography, Button, Toolbar, StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core'; -import { formatDate, formatFileSize } from '../../common/formatters'; +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 { ContextMenuAction } from '../../components/context-menu/context-menu'; import { DispatchProp, connect } from 'react-redux'; import { DataColumns } from '../../components/data-table/data-table'; import { RouteComponentProps } from 'react-router'; import { RootState } from '../../store/store'; -import { ResourceKind } from '../../models/kinds'; 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; + type: ResourceKind | ContainerRequestState; } -type ProjectPanelProps = { - currentItemId: string, - onItemClick: (item: ProjectPanelItem) => void, - onItemRouteChange: (itemId: string) => void +interface ProjectPanelDataProps { + currentItemId: string; } - & DispatchProp - & WithStyles - & RouteComponentProps<{ id: string }>; + +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 { classes } = this.props; return
-
- - -
; + onRowDoubleClick={this.props.onItemDoubleClick} + onContextMenu={this.props.onContextMenu} + extractKey={(item: ProjectPanelItem) => item.uuid} />
; } - - componentWillReceiveProps({ match, currentItemId }: ProjectPanelProps) { + + handleNewProjectClick = () => { + this.props.onDialogOpen(this.props.currentItemId); + } + componentWillReceiveProps({ match, currentItemId, onItemRouteChange }: ProjectPanelProps) { if (match.params.id !== currentItemId) { - this.props.onItemRouteChange(match.params.id); + onItemRouteChange(match.params.id); } } - - executeAction = (action: ContextMenuAction, item: ProjectPanelItem) => { - alert(`Executing ${action.name} on ${item.name}`); - } - } type CssRules = "toolbar" | "button"; -const styles: StyleRulesCallback = theme => ({ +const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ toolbar: { paddingBottom: theme.spacing.unit * 3, textAlign: "right" }, button: { marginLeft: theme.spacing.unit - } + }, }); -const renderName = (item: ProjectPanelItem) => - +const RENDER_NAME = (item: ProjectPanelItem) => + - {renderIcon(item)} + {RENDER_ICON(item)} @@ -92,134 +99,127 @@ const renderName = (item: ProjectPanelItem) => ; -const renderIcon = (item: ProjectPanelItem) => { +const RENDER_ICON = (item: ProjectPanelItem) => { switch (item.kind) { case ResourceKind.Project: - return ; + return ; case ResourceKind.Collection: - return ; + return ; case ResourceKind.Process: - case ResourceKind.Workflow: - return ; + return ; default: - return ; + return ; } }; -const renderDate = (date: string) => - - {formatDate(date)} - ; +const RENDER_DATE = (date: string) => { + return {FORMAT_DATE(date)}; +}; -const renderFileSize = (fileSize?: number) => +const RENDER_FILE_SIZE = (fileSize?: number) => - {formatFileSize(fileSize)} + {FORMAT_FILE_SIZE(fileSize)} ; -const renderOwner = (owner: string) => - +const RENDER_OWNER = (owner: string) => + {owner} ; - - -const typeToLabel = (type: string) => { - switch(type){ - case ResourceKind.Collection: - return "Data collection"; - case ResourceKind.Project: - return "Project"; - case ResourceKind.Process: - return "Process"; - default: - return "Unknown"; - } -}; - -const renderType = (type: string) => { - return - {typeToLabel(type)} +const RENDER_TYPE = (type: string) => + + {RESOURCE_LABEL(type)} ; -}; -const renderStatus = (item: ProjectPanelItem) => - +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 const columns: DataColumns = [{ - name: "Name", - selected: true, - sortDirection: "desc", - render: renderName, - width: "450px" -}, { - name: "Status", - selected: true, - render: renderStatus, - width: "75px" -}, { - name: "Type", - selected: true, - filters: [{ - name: typeToLabel(ResourceKind.Collection), +export const COLUMNS: DataColumns = [ + { + name: ColumnNames.NAME, selected: true, - type: ResourceKind.Collection - }, { - name: typeToLabel(ResourceKind.Process), + sortDirection: SortDirection.Asc, + render: RENDER_NAME, + width: "450px" + }, + { + name: "Status", selected: true, - type: ResourceKind.Process - }, { - name: typeToLabel(ResourceKind.Project), + 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, - type: ResourceKind.Project - }], - render: item => renderType(item.kind), - width: "125px" -}, { - name: "Owner", - selected: true, - render: item => renderOwner(item.owner), - width: "200px" -}, { - name: "File size", - selected: true, - render: item => renderFileSize(item.fileSize), - width: "50px" -}, { - name: "Last modified", - selected: true, - sortDirection: "none", - render: item => renderDate(item.lastModified), - width: "150px" -}]; - -const contextMenuActions = [[{ - icon: "fas fa-users fa-fw", - name: "Share" -}, { - icon: "fas fa-sign-out-alt fa-fw", - name: "Move to" -}, { - icon: "fas fa-star fa-fw", - name: "Add to favourite" -}, { - icon: "fas fa-edit fa-fw", - name: "Rename" -}, { - icon: "fas fa-copy fa-fw", - name: "Make a copy" -}, { - icon: "fas fa-download fa-fw", - name: "Download" -}], [{ - icon: "fas fa-trash-alt fa-fw", - name: "Remove" -} -]]; + 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)); + connect((state: RootState) => ({ currentItemId: state.projects.currentItemId }))(ProjectPanel));