Add generic trash action
[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 './index.css';
10 import { Route } from 'react-router';
11 import createBrowserHistory from "history/createBrowserHistory";
12 import { History } from "history";
13 import { configureStore, RootStore } from './store/store';
14 import { ConnectedRouter } from "react-router-redux";
15 import { ApiToken } from "./views-components/api-token/api-token";
16 import { initAuth } from "./store/auth/auth-action";
17 import { createServices } from "./services/services";
18 import { MuiThemeProvider } from '@material-ui/core/styles';
19 import { CustomTheme } from './common/custom-theme';
20 import { fetchConfig } from './common/config';
21 import { addMenuActionSet, ContextMenuKind } from "./views-components/context-menu/context-menu";
22 import { rootProjectActionSet } from "./views-components/context-menu/action-sets/root-project-action-set";
23 import { projectActionSet } from "./views-components/context-menu/action-sets/project-action-set";
24 import { resourceActionSet } from './views-components/context-menu/action-sets/resource-action-set';
25 import { favoriteActionSet } from "./views-components/context-menu/action-sets/favorite-action-set";
26 import { collectionFilesActionSet } from './views-components/context-menu/action-sets/collection-files-action-set';
27 import { collectionFilesItemActionSet } from './views-components/context-menu/action-sets/collection-files-item-action-set';
28 import { collectionActionSet } from './views-components/context-menu/action-sets/collection-action-set';
29 import { collectionResourceActionSet } from './views-components/context-menu/action-sets/collection-resource-action-set';
30 import { processActionSet } from './views-components/context-menu/action-sets/process-action-set';
31 import { addRouteChangeHandlers } from './routes/routes';
32 import { loadWorkbench } from './store/workbench/workbench-actions';
33 import { Routes } from '~/routes/routes';
34 import { trashActionSet } from "~/views-components/context-menu/action-sets/trash-action-set";
35
36 const getBuildNumber = () => "BN-" + (process.env.REACT_APP_BUILD_NUMBER || "dev");
37 const getGitCommit = () => "GIT-" + (process.env.REACT_APP_GIT_COMMIT || "latest").substr(0, 7);
38 const getBuildInfo = () => getBuildNumber() + " / " + getGitCommit();
39
40 const buildInfo = getBuildInfo();
41
42 console.log(`Starting arvados [${buildInfo}]`);
43
44 addMenuActionSet(ContextMenuKind.ROOT_PROJECT, rootProjectActionSet);
45 addMenuActionSet(ContextMenuKind.PROJECT, projectActionSet);
46 addMenuActionSet(ContextMenuKind.RESOURCE, resourceActionSet);
47 addMenuActionSet(ContextMenuKind.FAVORITE, favoriteActionSet);
48 addMenuActionSet(ContextMenuKind.COLLECTION_FILES, collectionFilesActionSet);
49 addMenuActionSet(ContextMenuKind.COLLECTION_FILES_ITEM, collectionFilesItemActionSet);
50 addMenuActionSet(ContextMenuKind.COLLECTION, collectionActionSet);
51 addMenuActionSet(ContextMenuKind.COLLECTION_RESOURCE, collectionResourceActionSet);
52 addMenuActionSet(ContextMenuKind.PROCESS, processActionSet);
53 addMenuActionSet(ContextMenuKind.TRASH, trashActionSet);
54
55 fetchConfig()
56     .then((config) => {
57         const history = createBrowserHistory();
58         const services = createServices(config);
59         const store = configureStore(history, services);
60
61         store.subscribe(initListener(history, store));
62
63         store.dispatch(initAuth());
64
65         const TokenComponent = (props: any) => <ApiToken authService={services.authService} {...props} />;
66         const WorkbenchComponent = (props: any) => <Workbench authService={services.authService} buildInfo={buildInfo} {...props} />;
67
68         const App = () =>
69             <MuiThemeProvider theme={CustomTheme}>
70                 <Provider store={store}>
71                     <ConnectedRouter history={history}>
72                         <div>
73                             <Route path={Routes.TOKEN} component={TokenComponent} />
74                             <Route path={Routes.ROOT} component={WorkbenchComponent} />
75                         </div>
76                     </ConnectedRouter>
77                 </Provider>
78             </MuiThemeProvider>;
79
80         ReactDOM.render(
81             <App />,
82             document.getElementById('root') as HTMLElement
83         );
84
85
86     });
87
88 const initListener = (history: History, store: RootStore) => {
89     let initialized = false;
90     return async () => {
91         const { router, auth } = store.getState();
92         if (router.location && auth.user && !initialized) {
93             initialized = true;
94             await store.dispatch(loadWorkbench());
95             addRouteChangeHandlers(history, store);
96         }
97     };
98 };
99
100