16108: Query for favorites should filter on owner not tail_uuid
[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 } 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 } from '~/views-components/context-menu/action-sets/collection-files-action-set';
28 import { collectionFilesItemActionSet } 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 } 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
66 console.log(`Starting arvados [${getBuildInfo()}]`);
67
68 addMenuActionSet(ContextMenuKind.ROOT_PROJECT, rootProjectActionSet);
69 addMenuActionSet(ContextMenuKind.PROJECT, projectActionSet);
70 addMenuActionSet(ContextMenuKind.RESOURCE, resourceActionSet);
71 addMenuActionSet(ContextMenuKind.FAVORITE, favoriteActionSet);
72 addMenuActionSet(ContextMenuKind.COLLECTION_FILES, collectionFilesActionSet);
73 addMenuActionSet(ContextMenuKind.COLLECTION_FILES_NOT_SELECTED, collectionFilesNotSelectedActionSet);
74 addMenuActionSet(ContextMenuKind.COLLECTION_FILES_ITEM, collectionFilesItemActionSet);
75 addMenuActionSet(ContextMenuKind.COLLECTION, collectionActionSet);
76 addMenuActionSet(ContextMenuKind.COLLECTION_RESOURCE, collectionResourceActionSet);
77 addMenuActionSet(ContextMenuKind.TRASHED_COLLECTION, trashedCollectionActionSet);
78 addMenuActionSet(ContextMenuKind.PROCESS, processActionSet);
79 addMenuActionSet(ContextMenuKind.PROCESS_RESOURCE, processResourceActionSet);
80 addMenuActionSet(ContextMenuKind.TRASH, trashActionSet);
81 addMenuActionSet(ContextMenuKind.REPOSITORY, repositoryActionSet);
82 addMenuActionSet(ContextMenuKind.SSH_KEY, sshKeyActionSet);
83 addMenuActionSet(ContextMenuKind.VIRTUAL_MACHINE, virtualMachineActionSet);
84 addMenuActionSet(ContextMenuKind.KEEP_SERVICE, keepServiceActionSet);
85 addMenuActionSet(ContextMenuKind.USER, userActionSet);
86 addMenuActionSet(ContextMenuKind.LINK, linkActionSet);
87 addMenuActionSet(ContextMenuKind.NODE, computeNodeActionSet);
88 addMenuActionSet(ContextMenuKind.API_CLIENT_AUTHORIZATION, apiClientAuthorizationActionSet);
89 addMenuActionSet(ContextMenuKind.GROUPS, groupActionSet);
90 addMenuActionSet(ContextMenuKind.GROUP_MEMBER, groupMemberActionSet);
91 addMenuActionSet(ContextMenuKind.COLLECTION_ADMIN, collectionAdminActionSet);
92 addMenuActionSet(ContextMenuKind.PROCESS_ADMIN, processResourceAdminActionSet);
93 addMenuActionSet(ContextMenuKind.PROJECT_ADMIN, projectAdminActionSet);
94
95 fetchConfig()
96     .then(({ config, apiHost }) => {
97         const history = createBrowserHistory();
98         const services = createServices(config, {
99             progressFn: (id, working) => {
100                 store.dispatch(progressIndicatorActions.TOGGLE_WORKING({ id, working }));
101             },
102             errorFn: (id, error) => {
103                 console.error("Backend error:", error);
104                 if (error.errors) {
105                     store.dispatch(snackbarActions.OPEN_SNACKBAR({
106                         message: `${error.errors[0]}`,
107                         kind: SnackbarKind.ERROR,
108                         hideDuration: 8000
109                     }));
110                 } else {
111                     store.dispatch(snackbarActions.OPEN_SNACKBAR({
112                         message: `${error.message}`,
113                         kind: SnackbarKind.ERROR,
114                         hideDuration: 8000
115                     }));
116                 }
117             }
118         });
119         const store = configureStore(history, services);
120
121         store.subscribe(initListener(history, store, services, config));
122         store.dispatch(initAuth(config));
123         store.dispatch(setBuildInfo());
124         store.dispatch(setCurrentTokenDialogApiHost(apiHost));
125         store.dispatch(loadVocabulary);
126         store.dispatch(loadFileViewersConfig);
127
128         const TokenComponent = (props: any) => <ApiToken authService={services.authService} config={config} loadMainApp={true} {...props} />;
129         const AddSessionComponent = (props: any) => <AddSession {...props} />;
130         const FedTokenComponent = (props: any) => <ApiToken authService={services.authService} config={config} loadMainApp={false} {...props} />;
131         const MainPanelComponent = (props: any) => <MainPanel {...props} />;
132
133         const App = () =>
134             <MuiThemeProvider theme={CustomTheme}>
135                 <DragDropContextProvider backend={HTML5Backend}>
136                     <Provider store={store}>
137                         <ConnectedRouter history={history}>
138                             <Switch>
139                                 <Route path={Routes.TOKEN} component={TokenComponent} />
140                                 <Route path={Routes.FED_LOGIN} component={FedTokenComponent} />
141                                 <Route path={Routes.ADD_SESSION} component={AddSessionComponent} />
142                                 <Route path={Routes.ROOT} component={MainPanelComponent} />
143                             </Switch>
144                         </ConnectedRouter>
145                     </Provider>
146                 </DragDropContextProvider>
147             </MuiThemeProvider>;
148
149         ReactDOM.render(
150             <App />,
151             document.getElementById('root') as HTMLElement
152         );
153     });
154
155 const initListener = (history: History, store: RootStore, services: ServiceRepository, config: Config) => {
156     let initialized = false;
157     return async () => {
158         const { router, auth } = store.getState();
159         if (router.location && auth.user && !initialized) {
160             initialized = true;
161             initWebSocket(config, services.authService, store);
162             await store.dispatch(loadWorkbench());
163             addRouteChangeHandlers(history, store);
164             // ToDo: move to searchBar component
165             store.dispatch(initAdvancedFormProjectsTree());
166         }
167     };
168 };
169
170 // force build comment #1