Add tree structure rendering
[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}`,
37         open: false,
38         data: {
39             name: t[0],
40             createdAt: '2018-05-05',
41         },
42         items: t.length > 1 ? buildProjectTree(t[1], level + 1) : []
43     }));
44     return projects;
45 }
46
47
48 const history = createBrowserHistory();
49 const projects = buildProjectTree(sampleProjects);
50
51 const store = configureStore({
52     projects,
53     router: {
54         location: null
55     }
56 }, history);
57
58 const App = () =>
59     <Provider store={store}>
60         <ConnectedRouter history={history}>
61             <div>
62                 <Route path="/" component={Workbench}/>
63             </div>
64         </ConnectedRouter>
65     </Provider>;
66
67 ReactDOM.render(
68     <App/>,
69     document.getElementById('root') as HTMLElement
70 );