tree test
[arvados-workbench2.git] / src / index.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 * as ReactDOM from 'react-dom';
7 import { Provider } from "react-redux";
8 import Workbench from './views/workbench/workbench';
9 import ProjectList from './components/project-list/project-list';
10 import './index.css';
11 import { Route, Router } from "react-router";
12 import createBrowserHistory from "history/createBrowserHistory";
13 import configureStore from "./store/store";
14 import { ConnectedRouter } from "react-router-redux";
15 import { TreeItem } from "./components/tree/tree";
16 import { Project } from "./models/project";
17
18 const sampleProjects = [
19     [
20         'Project 1', [
21             ['Project 1.1', [['Project 1.1.1'], ['Project 1.1.2']]],
22             ['Project 1.2', [['Project 1.2.1'], ['Project 1.2.2'], ['Project 1.2.3']]]
23         ]
24     ],
25     [
26         'Project 2'
27     ],
28     [
29         'Project 3', [['Project 3.1'], ['Project 3.2']]
30     ]
31 ];
32
33
34 function buildProjectTree(tree: any[], level = 0): Array<TreeItem<Project>> {
35     const projects = tree.map((t, idx) => ({
36         id: `l${level}i${idx}${t[0]}`,
37         open: false,
38         active: false,
39         data: {
40             name: t[0],
41             icon: level === 0 ? <i className="fas fa-th"/> : <i className="fas fa-folder"/>,
42             createdAt: '2018-05-05',
43         },
44         items: t.length > 1 ? buildProjectTree(t[1], level + 1) : []
45     }));
46     return projects;
47 }
48
49
50 const history = createBrowserHistory();
51 const projects = buildProjectTree(sampleProjects);
52
53 const store = configureStore({
54     projects,
55     router: {
56         location: null
57     }
58 }, history);
59
60 const App = () =>
61     <Provider store={store}>
62         <ConnectedRouter history={history}>
63             <div>
64                 <Route path="/" component={Workbench} />
65             </div>
66         </ConnectedRouter>
67     </Provider>;
68
69 ReactDOM.render(
70     <App />,
71     document.getElementById('root') as HTMLElement
72 );