Added data selector for workbench data explorer
[arvados-workbench2.git] / src / views / data-explorer / data-explorer.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from 'react';
6 import { RouteComponentProps } from 'react-router';
7 import { Project } from '../../models/project';
8 import { ProjectState } from '../../store/project/project-reducer';
9 import { RootState } from '../../store/store';
10 import { connect, DispatchProp } from 'react-redux';
11 import { push } from 'react-router-redux';
12 import { DataColumns } from "../../components/data-table/data-table";
13 import DataExplorer, { DataExplorerContextActions } from "../../views-components/data-explorer/data-explorer";
14 import { projectExplorerItems } from "./data-explorer-selectors";
15 import { DataItem } from "../../views-components/data-explorer/data-item";
16 import { CollectionState } from "../../store/collection/collection-reducer";
17 import { ResourceKind } from "../../models/resource";
18 import projectActions from "../../store/project/project-action";
19 import { getCollectionList } from "../../store/collection/collection-action";
20
21 interface DataExplorerViewDataProps {
22     projects: ProjectState;
23     collections: CollectionState;
24 }
25
26 type DataExplorerViewProps = DataExplorerViewDataProps & RouteComponentProps<{ uuid: string }> & DispatchProp;
27 type DataExplorerViewState = DataColumns<Project>;
28
29 class DataExplorerView extends React.Component<DataExplorerViewProps, DataExplorerViewState> {
30     render() {
31         const treeItemId = this.props.match.params.uuid;
32         const items = projectExplorerItems(this.props.projects, treeItemId, this.props.collections);
33         return (
34             <DataExplorer
35                 items={items}
36                 onItemClick={this.goToItem}
37                 contextActions={this.contextActions}
38             />
39         );
40     }
41
42     contextActions: DataExplorerContextActions = {
43         onAddToFavourite: console.log,
44         onCopy: console.log,
45         onDownload: console.log,
46         onMoveTo: console.log,
47         onRemove: console.log,
48         onRename: console.log,
49         onShare: console.log
50     };
51
52     goToItem = (item: DataItem) => {
53         // FIXME: Unify project tree switch action
54         this.props.dispatch(push(item.url));
55         if (item.type === ResourceKind.PROJECT || item.type === ResourceKind.LEVEL_UP) {
56             this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM(item.uuid));
57         }
58         this.props.dispatch<any>(getCollectionList(item.uuid));
59     }
60 }
61
62 export default connect(
63     (state: RootState) => ({
64         projects: state.projects,
65         collections: state.collections
66     })
67 )(DataExplorerView);