X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/9e4b7889a99ff2f76d8029aef3a85c4620178ba3..4a8d85d10073d2555253bdb631d293eaf7deccbf:/src/views-components/data-explorer/data-explorer.tsx diff --git a/src/views-components/data-explorer/data-explorer.tsx b/src/views-components/data-explorer/data-explorer.tsx index 1215915b9c..f89bc65e9b 100644 --- a/src/views-components/data-explorer/data-explorer.tsx +++ b/src/views-components/data-explorer/data-explorer.tsx @@ -2,195 +2,57 @@ // // SPDX-License-Identifier: AGPL-3.0 -import * as React from 'react'; -import { Typography, Grid, ListItem, Divider, List, ListItemIcon, ListItemText, Paper, Toolbar } from '@material-ui/core'; -import IconButton, { IconButtonProps } from '@material-ui/core/IconButton'; -import MoreVertIcon from "@material-ui/icons/MoreVert"; -import Popover from '../../components/popover/popover'; -import { formatFileSize, formatDate } from '../../common/formatters'; -import { DataItem } from './data-item'; -import { DataColumns, DataTableProps } from "../../components/data-table/data-table"; +import { connect } from "react-redux"; +import { RootState } from "../../store/store"; +import DataExplorer from "../../components/data-explorer/data-explorer"; +import { getDataExplorer } from "../../store/data-explorer/data-explorer-reducer"; +import { Dispatch } from "redux"; +import actions from "../../store/data-explorer/data-explorer-action"; import { DataColumn } from "../../components/data-table/data-column"; -import ColumnSelector from "../../components/column-selector/column-selector"; -import DataTable from "../../components/data-table/data-table"; - -interface DataExplorerProps { - items: DataItem[]; - onItemClick: (item: DataItem) => void; -} - -interface DataExplorerState { - columns: DataColumns; +import { DataTableFilterItem } from "../../components/data-table-filters/data-table-filters"; +import { ContextMenuAction, ContextMenuActionGroup } from "../../components/context-menu/context-menu"; + +interface Props { + id: string; + contextActions: ContextMenuActionGroup[]; + onRowClick: (item: any) => void; + onContextAction: (action: ContextMenuAction, item: any) => void; } -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: () => null, - render: renderItemActions - } - ] - }; - - render() { - return - - - - - - - - ; - } +const mapStateToProps = (state: RootState, { id, contextActions }: Props) => + getDataExplorer(state.dataExplorer, id); - toggleColumn = (column: DataColumn) => { - const index = this.state.columns.indexOf(column); - const columns = this.state.columns.slice(0); - columns.splice(index, 1, { ...column, selected: !column.selected }); - this.setState({ columns }); - } - - renderName = (item: DataItem) => - this.props.onItemClick(item)}> - - {renderIcon(item)} - - - - {item.name} - - - - -} +const mapDispatchToProps = (dispatch: Dispatch, { id, contextActions, onRowClick, onContextAction }: Props) => ({ + onSearch: (searchValue: string) => { + dispatch(actions.SET_SEARCH_VALUE({ id, searchValue })); + }, -const renderIcon = (dataItem: DataItem) => { - switch (dataItem.type) { - case "arvados#group": - return ; - case "arvados#groupList": - return ; - default: - return ; - } -}; + onColumnToggle: (column: DataColumn) => { + dispatch(actions.TOGGLE_COLUMN({ id, columnName: column.name })); + }, -const renderDate = (date: string) => - - {formatDate(date)} - ; + onSortToggle: (column: DataColumn) => { + dispatch(actions.TOGGLE_SORT({ id, columnName: column.name })); + }, -const renderFileSize = (fileSize?: number) => - - {formatFileSize(fileSize)} - ; + onFiltersChange: (filters: DataTableFilterItem[], column: DataColumn) => { + dispatch(actions.SET_FILTERS({ id, columnName: column.name, filters })); + }, -const renderOwner = (owner: string) => - - {owner} - ; + onChangePage: (page: number) => { + dispatch(actions.SET_PAGE({ id, page })); + }, -const renderType = (type: string) => - - {type} - ; + onChangeRowsPerPage: (rowsPerPage: number) => { + dispatch(actions.SET_ROWS_PER_PAGE({ id, rowsPerPage })); + }, -const renderStatus = (status?: string) => - - {status || "-"} - ; + contextActions, -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" })} - - - ; + onRowClick, -const renderAction = (action: { label: string, icon: string }, index?: number) => - - - - - - {action.label} - - ; + onContextAction +}); -const ItemActionsTrigger: React.SFC = (props) => - - - ; +export default connect(mapStateToProps, mapDispatchToProps)(DataExplorer); -export default DataExplorer;