16245: added calculated height and overflow y scroll to data table
[arvados.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 { MainPanel } from '~/views/main-panel/main-panel';
9 import '~/index.css';
10 import { Route, Switch } from 'react-router';
11 import { createBrowserHistory } from "history";
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 { AddSession } from "~/views-components/add-session/add-session";
17 import { initAuth } from "~/store/auth/auth-action";
18 import { createServices } from "~/services/services";
19 import { MuiThemeProvider } from '@material-ui/core/styles';
20 import { CustomTheme } from '~/common/custom-theme';
21 import { fetchConfig } from '~/common/config';
22 import { addMenuActionSet, ContextMenuKind } from '~/views-components/context-menu/context-menu';
23 import { rootProjectActionSet } from "~/views-components/context-menu/action-sets/root-project-action-set";
24 import { projectActionSet, readOnlyProjectActionSet } from "~/views-components/context-menu/action-sets/project-action-set";
25 import { resourceActionSet } from '~/views-components/context-menu/action-sets/resource-action-set';
26 import { favoriteActionSet } from "~/views-components/context-menu/action-sets/favorite-action-set";
27 import { collectionFilesActionSet, readOnlyCollectionFilesActionSet } from '~/views-components/context-menu/action-sets/collection-files-action-set';
28 import { collectionFilesItemActionSet, readOnlyCollectionFilesItemActionSet } from '~/views-components/context-menu/action-sets/collection-files-item-action-set';
29 import { collectionFilesNotSelectedActionSet } from '~/views-components/context-menu/action-sets/collection-files-not-selected-action-set';
30 import { collectionActionSet, readOnlyCollectionActionSet } from '~/views-components/context-menu/action-sets/collection-action-set';
31 import { collectionResourceActionSet } from '~/views-components/context-menu/action-sets/collection-resource-action-set';
32 import { processActionSet } from '~/views-components/context-menu/action-sets/process-action-set';
33 import { loadWorkbench } from '~/store/workbench/workbench-actions';
34 import { Routes } from '~/routes/routes';
35 import { trashActionSet } from "~/views-components/context-menu/action-sets/trash-action-set";
36 import { ServiceRepository } from '~/services/services';
37 import { initWebSocket } from '~/websocket/websocket';
38 import { Config } from '~/common/config';
39 import { addRouteChangeHandlers } from './routes/route-change-handlers';
40 import { setCurrentTokenDialogApiHost } from '~/store/current-token-dialog/current-token-dialog-actions';
41 import { processResourceActionSet } from '~/views-components/context-menu/action-sets/process-resource-action-set';
42 import { progressIndicatorActions } from '~/store/progress-indicator/progress-indicator-actions';
43 import { trashedCollectionActionSet } from '~/views-components/context-menu/action-sets/trashed-collection-action-set';
44 import { setBuildInfo } from '~/store/app-info/app-info-actions';
45 import { getBuildInfo } from '~/common/app-info';
46 import { DragDropContextProvider } from 'react-dnd';
47 import HTML5Backend from 'react-dnd-html5-backend';
48 import { initAdvancedFormProjectsTree } from '~/store/search-bar/search-bar-actions';
49 import { repositoryActionSet } from '~/views-components/context-menu/action-sets/repository-action-set';
50 import { sshKeyActionSet } from '~/views-components/context-menu/action-sets/ssh-key-action-set';
51 import { keepServiceActionSet } from '~/views-components/context-menu/action-sets/keep-service-action-set';
52 import { loadVocabulary } from '~/store/vocabulary/vocabulary-actions';
53 import { virtualMachineActionSet } from '~/views-components/context-menu/action-sets/virtual-machine-action-set';
54 import { userActionSet } from '~/views-components/context-menu/action-sets/user-action-set';
55 import { computeNodeActionSet } from '~/views-components/context-menu/action-sets/compute-node-action-set';
56 import { apiClientAuthorizationActionSet } from '~/views-components/context-menu/action-sets/api-client-authorization-action-set';
57 import { groupActionSet } from '~/views-components/context-menu/action-sets/group-action-set';
58 import { groupMemberActionSet } from '~/views-components/context-menu/action-sets/group-member-action-set';
59 import { linkActionSet } from '~/views-components/context-menu/action-sets/link-action-set';
60 import { loadFileViewersConfig } from '~/store/file-viewers/file-viewers-actions';
61 import { collectionAdminActionSet } from '~/views-components/context-menu/action-sets/collection-admin-action-set';
62 import { processResourceAdminActionSet } from '~/views-components/context-menu/action-sets/process-resource-admin-action-set';
63 import { projectAdminActionSet } from '~/views-components/context-menu/action-sets/project-admin-action-set';
64 import { snackbarActions, SnackbarKind } from "~/store/snackbar/snackbar-actions";
65 import { openNotFoundDialog } from './store/not-found-panel/not-found-panel-action';
66
67 console.log(`Starting arvados [${getBuildInfo()}]`);
68
69 addMenuActionSet(ContextMenuKind.ROOT_PROJECT, rootProjectActionSet);
70 addMenuActionSet(ContextMenuKind.PROJECT, projectActionSet);
71 addMenuActionSet(ContextMenuKind.READONLY_PROJECT, readOnlyProjectActionSet);
72 addMenuActionSet(ContextMenuKind.RESOURCE, resourceActionSet);
73 addMenuActionSet(ContextMenuKind.FAVORITE, favoriteActionSet);
74 addMenuActionSet(ContextMenuKind.COLLECTION_FILES, collectionFilesActionSet);
75 addMenuActionSet(ContextMenuKind.READONLY_COLLECTION_FILES, readOnlyCollectionFilesActionSet);
76 addMenuActionSet(ContextMenuKind.COLLECTION_FILES_NOT_SELECTED, collectionFilesNotSelectedActionSet);
77 addMenuActionSet(ContextMenuKind.COLLECTION_FILES_ITEM, collectionFilesItemActionSet);
78 addMenuActionSet(ContextMenuKind.READONLY_COLLECTION_FILES_ITEM, readOnlyCollectionFilesItemActionSet);
79 addMenuActionSet(ContextMenuKind.COLLECTION, collectionActionSet);
80 addMenuActionSet(ContextMenuKind.COLLECTION_RESOURCE, collectionResourceActionSet);
81 addMenuActionSet(ContextMenuKind.READONLY_COLLECTION, readOnlyCollectionActionSet);
82 addMenuActionSet(ContextMenuKind.TRASHED_COLLECTION, trashedCollectionActionSet);
83 addMenuActionSet(ContextMenuKind.PROCESS, processActionSet);
84 addMenuActionSet(ContextMenuKind.PROCESS_RESOURCE, processResourceActionSet);
85 addMenuActionSet(ContextMenuKind.TRASH, trashActionSet);
86 addMenuActionSet(ContextMenuKind.REPOSITORY, repositoryActionSet);
87 addMenuActionSet(ContextMenuKind.SSH_KEY, sshKeyActionSet);
88 addMenuActionSet(ContextMenuKind.VIRTUAL_MACHINE, virtualMachineActionSet);
89 addMenuActionSet(ContextMenuKind.KEEP_SERVICE, keepServiceActionSet);
90 addMenuActionSet(ContextMenuKind.USER, userActionSet);
91 addMenuActionSet(ContextMenuKind.LINK, linkActionSet);
92 addMenuActionSet(ContextMenuKind.NODE, computeNodeActionSet);
93 addMenuActionSet(ContextMenuKind.API_CLIENT_AUTHORIZATION, apiClientAuthorizationActionSet);
94 addMenuActionSet(ContextMenuKind.GROUPS, groupActionSet);
95 addMenuActionSet(ContextMenuKind.GROUP_MEMBER, groupMemberActionSet);
96 addMenuActionSet(ContextMenuKind.COLLECTION_ADMIN, collectionAdminActionSet);
97 addMenuActionSet(ContextMenuKind.PROCESS_ADMIN, processResourceAdminActionSet);
98 addMenuActionSet(ContextMenuKind.PROJECT_ADMIN, projectAdminActionSet);
99
100 fetchConfig()
101     .then(({ config, apiHost }) => {
102         const history = createBrowserHistory();
103         const services = createServices(config, {
104             progressFn: (id, working) => {
105                 store.dispatch(progressIndicatorActions.TOGGLE_WORKING({ id, working }));
106             },
107             errorFn: (id, error, showSnackBar) => {
108                 if (showSnackBar) {
109                     console.error("Backend error:", error);
110
111                     if (error.errors[0].indexOf("not found") > -1) {
112                         store.dispatch(openNotFoundDialog());
113                     } else {
114                         store.dispatch(snackbarActions.OPEN_SNACKBAR({
115                             message: `${error.errors
116                                 ? error.errors[0]
117                                 : error.message}`,
118                             kind: SnackbarKind.ERROR,
119                             hideDuration: 8000})
120                         );
121                     }
122                 }
123             }
124         });
125         const store = configureStore(history, services);
126
127         store.subscribe(initListener(history, store, services, config));
128         store.dispatch(initAuth(config));
129         store.dispatch(setBuildInfo());
130         store.dispatch(setCurrentTokenDialogApiHost(apiHost));
131         store.dispatch(loadVocabulary);
132         store.dispatch(loadFileViewersConfig);
133
134         const TokenComponent = (props: any) => <ApiToken authService={services.authService} config={config} loadMainApp={true} {...props} />;
135         const AddSessionComponent = (props: any) => <AddSession {...props} />;
136         const FedTokenComponent = (props: any) => <ApiToken authService={services.authService} config={config} loadMainApp={false} {...props} />;
137         const MainPanelComponent = (props: any) => <MainPanel {...props} />;
138
139         const App = () =>
140             <MuiThemeProvider theme={CustomTheme}>
141                 <DragDropContextProvider backend={HTML5Backend}>
142                     <Provider store={store}>
143                         <ConnectedRouter history={history}>
144                             <Switch>
145                                 <Route path={Routes.TOKEN} component={TokenComponent} />
146                                 <Route path={Routes.FED_LOGIN} component={FedTokenComponent} />
147                                 <Route path={Routes.ADD_SESSION} component={AddSessionComponent} />
148                                 <Route path={Routes.ROOT} component={MainPanelComponent} />
149                             </Switch>
150                         </ConnectedRouter>
151                     </Provider>
152                 </DragDropContextProvider>
153             </MuiThemeProvider>;
154
155         ReactDOM.render(
156             <App />,
157             document.getElementById('root') as HTMLElement
158         );
159     });
160
161 const initListener = (history: History, store: RootStore, services: ServiceRepository, config: Config) => {
162     let initialized = false;
163     return async () => {
164         const { router, auth } = store.getState();
165         if (router.location && auth.user && !initialized) {
166             initialized = true;
167             initWebSocket(config, services.authService, store);
168             await store.dispatch(loadWorkbench());
169             addRouteChangeHandlers(history, store);
170             // ToDo: move to searchBar component
171             store.dispatch(initAdvancedFormProjectsTree());
172         }
173     };
174 };