X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/fbd2012fa56f6de44dfc4008d70e5a21cfcaf459..7364c06cd354952de2d469aa6285b7624864acf7:/src/components/data-explorer/data-explorer.tsx diff --git a/src/components/data-explorer/data-explorer.tsx b/src/components/data-explorer/data-explorer.tsx index 2c2c56e999..026820be28 100644 --- a/src/components/data-explorer/data-explorer.tsx +++ b/src/components/data-explorer/data-explorer.tsx @@ -3,68 +3,124 @@ // SPDX-License-Identifier: AGPL-3.0 import * as React from 'react'; -import { DataTable, DataTableProps, DataColumn, ColumnSelector } from "../../components/data-table"; -import { Typography, Grid, ListItem, Divider, List, ListItemIcon, ListItemText } from '@material-ui/core'; -import IconButton, { IconButtonProps } from '@material-ui/core/IconButton'; +import { DataTable, DataColumn, ColumnSelector } from "../../components/data-table"; +import { Typography, Grid, Paper, Toolbar } from '@material-ui/core'; +import IconButton from '@material-ui/core/IconButton'; import MoreVertIcon from "@material-ui/icons/MoreVert"; -import Popover from '../popover/popover'; import { formatFileSize, formatDate } from '../../common/formatters'; import { DataItem } from './data-item'; - +import { mockAnchorFromMouseEvent } from '../popover/helpers'; +import ContextMenu, { ContextMenuActionGroup } from '../context-menu/context-menu'; + +export interface DataExplorerContextActions { + onAddToFavourite: (dataIitem: DataItem) => void; + onCopy: (dataIitem: DataItem) => void; + onDownload: (dataIitem: DataItem) => void; + onMoveTo: (dataIitem: DataItem) => void; + onRemove: (dataIitem: DataItem) => void; + onRename: (dataIitem: DataItem) => void; + onShare: (dataIitem: DataItem) => void; +} interface DataExplorerProps { items: DataItem[]; onItemClick: (item: DataItem) => void; + contextActions: DataExplorerContextActions; } -type DataExplorerState = Pick, "columns">; +interface DataExplorerState { + columns: Array>; + contextMenu: { + anchorEl?: HTMLElement; + item?: DataItem; + actions: Array>; + }; +} class DataExplorer extends React.Component { state: DataExplorerState = { - columns: [ - { - name: "Name", - selected: true, - render: item => this.renderName(item) - }, - { - name: "Status", - selected: true, - render: item => renderStatus(item.status) - }, - { - name: "Type", - selected: true, - render: item => renderType(item.type) - }, - { - name: "Owner", - selected: true, - render: item => renderOwner(item.owner) - }, - { - name: "File size", - selected: true, - render: (item) => renderFileSize(item.fileSize) - }, - { - name: "Last modified", - selected: true, - render: item => renderDate(item.lastModified) - }, - { - name: "Actions", - selected: true, - configurable: false, - renderHeader: () => this.renderActionsHeader(), - render: renderItemActions + contextMenu: { + actions: [[{ + icon: "fas fa-users fa-fw", + name: "Share", + onClick: this.handleContextAction("onShare") + }, { + icon: "fas fa-sign-out-alt fa-fw", + name: "Move to", + onClick: this.handleContextAction("onMoveTo") + }, { + icon: "fas fa-star fa-fw", + name: "Add to favourite", + onClick: this.handleContextAction("onAddToFavourite") + }, { + icon: "fas fa-edit fa-fw", + name: "Rename", + onClick: this.handleContextAction("onRename") + }, { + icon: "fas fa-copy fa-fw", + name: "Make a copy", + onClick: this.handleContextAction("onCopy") + }, { + icon: "fas fa-download fa-fw", + name: "Download", + onClick: this.handleContextAction("onDownload") + }], [{ + icon: "fas fa-trash-alt fa-fw", + name: "Remove", + onClick: this.handleContextAction("onRemove") } - ] + ]] + }, + columns: [{ + name: "Name", + selected: true, + render: item => this.renderName(item) + }, { + name: "Status", + selected: true, + render: item => renderStatus(item.status) + }, { + name: "Type", + selected: true, + render: item => renderType(item.type) + }, { + name: "Owner", + selected: true, + render: item => renderOwner(item.owner) + }, { + name: "File size", + selected: true, + render: item => renderFileSize(item.fileSize) + }, { + name: "Last modified", + selected: true, + render: item => renderDate(item.lastModified) + }, { + name: "Actions", + selected: true, + configurable: false, + renderHeader: () => null, + render: item => this.renderActions(item) + }] }; render() { - return ; + return + + + + + + + + + ; } toggleColumn = (column: DataColumn) => { @@ -74,13 +130,6 @@ class DataExplorer extends React.Component this.setState({ columns }); } - renderActionsHeader = () => - - - - renderName = (item: DataItem) => + renderActions = (item: DataItem) => + + this.openItemMenuOnActionsClick(event, item)}> + + + + + openItemMenuOnRowClick = (event: React.MouseEvent, item: DataItem) => { + event.preventDefault(); + this.setContextMenuState({ + anchorEl: mockAnchorFromMouseEvent(event), + item + }); + } + + openItemMenuOnActionsClick = (event: React.MouseEvent, item: DataItem) => { + this.setContextMenuState({ + anchorEl: event.currentTarget, + item + }); + } + + closeContextMenu = () => { + this.setContextMenuState({}); + } + + setContextMenuState = (contextMenu: { anchorEl?: HTMLElement; item?: DataItem; }) => { + this.setState(prev => ({ contextMenu: { ...contextMenu, actions: prev.contextMenu.actions } })); + } + + handleContextAction(action: keyof DataExplorerContextActions) { + return (item: DataItem) => { + this.closeContextMenu(); + this.props.contextActions[action](item); + }; + } + } const renderIcon = (dataItem: DataItem) => { @@ -136,53 +222,4 @@ const renderStatus = (status?: string) => {status || "-"} ; -const renderItemActions = () => - - - - {[{ - icon: "fas fa-users", - label: "Share" - }, - { - icon: "fas fa-sign-out-alt", - label: "Move to" - }, - { - icon: "fas fa-star", - label: "Add to favourite" - }, - { - icon: "fas fa-edit", - label: "Rename" - }, - { - icon: "fas fa-copy", - label: "Make a copy" - }, - { - icon: "fas fa-download", - label: "Download" - }].map(renderAction)} - < Divider /> - {renderAction({ icon: "fas fa-trash-alt", label: "Remove" })} - - - ; - -const renderAction = (action: { label: string, icon: string }, index?: number) => - - - - - - {action.label} - - ; - -const ItemActionsTrigger: React.SFC = (props) => - - - ; - export default DataExplorer;