20c6df55b118571196205c636da73f939aadbbda
[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, findTreeItem } 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 projectActions from "../../store/project/project-action";
13 import { DataColumns } from "../../components/data-table/data-table";
14 import { DataItem } from "../../views-components/data-explorer/data-item";
15 import DataExplorer from "../../views-components/data-explorer/data-explorer";
16 import { mapProjectTreeItem } from "../../views-selectors/data-explorer/data-explorer";
17
18 interface DataExplorerViewDataProps {
19     projects: ProjectState;
20 }
21
22 type DataExplorerViewProps = DataExplorerViewDataProps & RouteComponentProps<{ name: string }> & DispatchProp;
23 type DataExplorerViewState = DataColumns<Project>;
24
25 class DataExplorerView extends React.Component<DataExplorerViewProps, DataExplorerViewState> {
26
27     render() {
28         const project = findTreeItem(this.props.projects, this.props.match.params.name);
29         const projectItems = project && project.items || [];
30         return (
31             <DataExplorer
32                 items={projectItems.map(mapProjectTreeItem)}
33                 onItemClick={this.goToProject}
34             />
35         );
36     }
37
38     goToProject = (item: DataItem) => {
39         this.props.dispatch(push(`/project/${item.uuid}`));
40         this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM(item.uuid));
41     }
42 }
43
44 export default connect(
45     (state: RootState) => ({
46         projects: state.projects
47     })
48 )(DataExplorerView);