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<DataItem>;
+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<DataExplorerProps, DataExplorerState> {
-    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 <Paper>
-            <Toolbar>
-                <Grid container justify="flex-end">
-                    <ColumnSelector
-                        columns={this.state.columns}
-                        onColumnToggle={this.toggleColumn} />
-                </Grid>
-            </Toolbar>
-            <DataTable
-                columns={this.state.columns}
-                items={this.props.items} />
-            <Toolbar />
-        </Paper>;
-    }
+const mapStateToProps = (state: RootState, { id, contextActions }: Props) =>
+    getDataExplorer(state.dataExplorer, id);
 
-    toggleColumn = (column: DataColumn<DataItem>) => {
-        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) =>
-        <Grid
-            container
-            alignItems="center"
-            wrap="nowrap"
-            spacing={16}
-            onClick={() => this.props.onItemClick(item)}>
-            <Grid item>
-                {renderIcon(item)}
-            </Grid>
-            <Grid item>
-                <Typography color="primary">
-                    {item.name}
-                </Typography>
-            </Grid>
-        </Grid>
-
-}
+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 <i className="fas fa-folder fa-lg" />;
-        case "arvados#groupList":
-            return <i className="fas fa-th fa-lg" />;
-        default:
-            return <i />;
-    }
-};
+    onColumnToggle: (column: DataColumn<any>) => {
+        dispatch(actions.TOGGLE_COLUMN({ id, columnName: column.name }));
+    },
 
-const renderDate = (date: string) =>
-    <Typography noWrap>
-        {formatDate(date)}
-    </Typography>;
+    onSortToggle: (column: DataColumn<any>) => {
+        dispatch(actions.TOGGLE_SORT({ id, columnName: column.name }));
+    },
 
-const renderFileSize = (fileSize?: number) =>
-    <Typography noWrap>
-        {formatFileSize(fileSize)}
-    </Typography>;
+    onFiltersChange: (filters: DataTableFilterItem[], column: DataColumn<any>) => {
+        dispatch(actions.SET_FILTERS({ id, columnName: column.name, filters }));
+    },
 
-const renderOwner = (owner: string) =>
-    <Typography noWrap color="primary">
-        {owner}
-    </Typography>;
+    onChangePage: (page: number) => {
+        dispatch(actions.SET_PAGE({ id, page }));
+    },
 
-const renderType = (type: string) =>
-    <Typography noWrap>
-        {type}
-    </Typography>;
+    onChangeRowsPerPage: (rowsPerPage: number) => {
+        dispatch(actions.SET_ROWS_PER_PAGE({ id, rowsPerPage }));
+    },
 
-const renderStatus = (status?: string) =>
-    <Typography noWrap align="center">
-        {status || "-"}
-    </Typography>;
+    contextActions,
 
-const renderItemActions = () =>
-    <Grid container justify="flex-end">
-        <Popover triggerComponent={ItemActionsTrigger}>
-            <List dense>
-                {[{
-                    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" })}
-            </List>
-        </Popover>
-    </Grid>;
+    onRowClick,
 
-const renderAction = (action: { label: string, icon: string }, index?: number) =>
-    <ListItem button key={index}>
-        <ListItemIcon>
-            <i className={action.icon} />
-        </ListItemIcon>
-        <ListItemText>
-            {action.label}
-        </ListItemText>
-    </ListItem>;
+    onContextAction
+});
 
-const ItemActionsTrigger: React.SFC<IconButtonProps> = (props) =>
-    <IconButton {...props}>
-        <MoreVertIcon />
-    </IconButton>;
+export default connect(mapStateToProps, mapDispatchToProps)(DataExplorer);
 
-export default DataExplorer;
