1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from "react";
6 import ReactDOM from "react-dom";
7 import { Provider } from "react-redux";
8 import { MainPanel } from "views/main-panel/main-panel";
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, logout } 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 servicesProvider from "common/service-provider";
23 import { addMenuActionSet, ContextMenuKind } from "views-components/context-menu/context-menu";
24 import { rootProjectActionSet } from "views-components/context-menu/action-sets/root-project-action-set";
29 readOnlyProjectActionSet,
30 } from "views-components/context-menu/action-sets/project-action-set";
31 import { resourceActionSet } from "views-components/context-menu/action-sets/resource-action-set";
32 import { favoriteActionSet } from "views-components/context-menu/action-sets/favorite-action-set";
33 import { collectionFilesActionSet, readOnlyCollectionFilesActionSet } from "views-components/context-menu/action-sets/collection-files-action-set";
35 collectionDirectoryItemActionSet,
36 collectionFileItemActionSet,
37 readOnlyCollectionDirectoryItemActionSet,
38 readOnlyCollectionFileItemActionSet,
39 } from "views-components/context-menu/action-sets/collection-files-item-action-set";
40 import { collectionFilesNotSelectedActionSet } from "views-components/context-menu/action-sets/collection-files-not-selected-action-set";
43 collectionAdminActionSet,
44 oldCollectionVersionActionSet,
45 readOnlyCollectionActionSet,
46 } from "views-components/context-menu/action-sets/collection-action-set";
47 import { loadWorkbench } from "store/workbench/workbench-actions";
48 import { Routes } from "routes/routes";
49 import { trashActionSet } from "views-components/context-menu/action-sets/trash-action-set";
50 import { ServiceRepository } from "services/services";
51 import { initWebSocket } from "websocket/websocket";
52 import { Config } from "common/config";
53 import { addRouteChangeHandlers } from "./routes/route-change-handlers";
54 import { setTokenDialogApiHost } from "store/token-dialog/token-dialog-actions";
56 processResourceActionSet,
57 processResourceAdminActionSet,
58 readOnlyProcessResourceActionSet,
59 } from "views-components/context-menu/action-sets/process-resource-action-set";
60 import { progressIndicatorActions } from "store/progress-indicator/progress-indicator-actions";
61 import { trashedCollectionActionSet } from "views-components/context-menu/action-sets/trashed-collection-action-set";
62 import { setBuildInfo } from "store/app-info/app-info-actions";
63 import { getBuildInfo } from "common/app-info";
64 import { DragDropContextProvider } from "react-dnd";
65 import HTML5Backend from "react-dnd-html5-backend";
66 import { initAdvancedFormProjectsTree } from "store/search-bar/search-bar-actions";
67 import { repositoryActionSet } from "views-components/context-menu/action-sets/repository-action-set";
68 import { sshKeyActionSet } from "views-components/context-menu/action-sets/ssh-key-action-set";
69 import { keepServiceActionSet } from "views-components/context-menu/action-sets/keep-service-action-set";
70 import { loadVocabulary } from "store/vocabulary/vocabulary-actions";
71 import { virtualMachineActionSet } from "views-components/context-menu/action-sets/virtual-machine-action-set";
72 import { userActionSet } from "views-components/context-menu/action-sets/user-action-set";
73 import { apiClientAuthorizationActionSet } from "views-components/context-menu/action-sets/api-client-authorization-action-set";
74 import { groupActionSet } from "views-components/context-menu/action-sets/group-action-set";
75 import { groupMemberActionSet } from "views-components/context-menu/action-sets/group-member-action-set";
76 import { linkActionSet } from "views-components/context-menu/action-sets/link-action-set";
77 import { loadFileViewersConfig } from "store/file-viewers/file-viewers-actions";
79 filterGroupAdminActionSet,
81 projectAdminActionSet,
82 } from "views-components/context-menu/action-sets/project-admin-action-set";
83 import { permissionEditActionSet } from "views-components/context-menu/action-sets/permission-edit-action-set";
84 import { workflowActionSet } from "views-components/context-menu/action-sets/workflow-action-set";
85 import { snackbarActions, SnackbarKind } from "store/snackbar/snackbar-actions";
86 import { openNotFoundDialog } from "./store/not-found-panel/not-found-panel-action";
87 import { storeRedirects } from "./common/redirect-to";
88 import { searchResultsActionSet } from "views-components/context-menu/action-sets/search-results-action-set";
90 console.log(`Starting arvados [${getBuildInfo()}]`);
92 addMenuActionSet(ContextMenuKind.ROOT_PROJECT, rootProjectActionSet);
93 addMenuActionSet(ContextMenuKind.PROJECT, projectActionSet);
94 addMenuActionSet(ContextMenuKind.READONLY_PROJECT, readOnlyProjectActionSet);
95 addMenuActionSet(ContextMenuKind.FILTER_GROUP, filterGroupActionSet);
96 addMenuActionSet(ContextMenuKind.RESOURCE, resourceActionSet);
97 addMenuActionSet(ContextMenuKind.FAVORITE, favoriteActionSet);
98 addMenuActionSet(ContextMenuKind.COLLECTION_FILES, collectionFilesActionSet);
99 addMenuActionSet(ContextMenuKind.READONLY_COLLECTION_FILES, readOnlyCollectionFilesActionSet);
100 addMenuActionSet(ContextMenuKind.COLLECTION_FILES_NOT_SELECTED, collectionFilesNotSelectedActionSet);
101 addMenuActionSet(ContextMenuKind.COLLECTION_DIRECTORY_ITEM, collectionDirectoryItemActionSet);
102 addMenuActionSet(ContextMenuKind.READONLY_COLLECTION_DIRECTORY_ITEM, readOnlyCollectionDirectoryItemActionSet);
103 addMenuActionSet(ContextMenuKind.COLLECTION_FILE_ITEM, collectionFileItemActionSet);
104 addMenuActionSet(ContextMenuKind.READONLY_COLLECTION_FILE_ITEM, readOnlyCollectionFileItemActionSet);
105 addMenuActionSet(ContextMenuKind.COLLECTION, collectionActionSet);
106 addMenuActionSet(ContextMenuKind.READONLY_COLLECTION, readOnlyCollectionActionSet);
107 addMenuActionSet(ContextMenuKind.OLD_VERSION_COLLECTION, oldCollectionVersionActionSet);
108 addMenuActionSet(ContextMenuKind.TRASHED_COLLECTION, trashedCollectionActionSet);
109 addMenuActionSet(ContextMenuKind.PROCESS_RESOURCE, processResourceActionSet);
110 addMenuActionSet(ContextMenuKind.READONLY_PROCESS_RESOURCE, readOnlyProcessResourceActionSet);
111 addMenuActionSet(ContextMenuKind.TRASH, trashActionSet);
112 addMenuActionSet(ContextMenuKind.REPOSITORY, repositoryActionSet);
113 addMenuActionSet(ContextMenuKind.SSH_KEY, sshKeyActionSet);
114 addMenuActionSet(ContextMenuKind.VIRTUAL_MACHINE, virtualMachineActionSet);
115 addMenuActionSet(ContextMenuKind.KEEP_SERVICE, keepServiceActionSet);
116 addMenuActionSet(ContextMenuKind.USER, userActionSet);
117 addMenuActionSet(ContextMenuKind.LINK, linkActionSet);
118 addMenuActionSet(ContextMenuKind.API_CLIENT_AUTHORIZATION, apiClientAuthorizationActionSet);
119 addMenuActionSet(ContextMenuKind.GROUPS, groupActionSet);
120 addMenuActionSet(ContextMenuKind.GROUP_MEMBER, groupMemberActionSet);
121 addMenuActionSet(ContextMenuKind.COLLECTION_ADMIN, collectionAdminActionSet);
122 addMenuActionSet(ContextMenuKind.PROCESS_ADMIN, processResourceAdminActionSet);
123 addMenuActionSet(ContextMenuKind.PROJECT_ADMIN, projectAdminActionSet);
124 addMenuActionSet(ContextMenuKind.FROZEN_PROJECT, frozenActionSet);
125 addMenuActionSet(ContextMenuKind.FROZEN_PROJECT_ADMIN, frozenAdminActionSet);
126 addMenuActionSet(ContextMenuKind.FILTER_GROUP_ADMIN, filterGroupAdminActionSet);
127 addMenuActionSet(ContextMenuKind.PERMISSION_EDIT, permissionEditActionSet);
128 addMenuActionSet(ContextMenuKind.WORKFLOW, workflowActionSet);
129 addMenuActionSet(ContextMenuKind.SEARCH_RESULTS, searchResultsActionSet);
133 fetchConfig().then(({ config, apiHost }) => {
134 const history = createBrowserHistory();
136 // Provide browser's history access to Cypress to allow programmatic
138 if ((window as any).Cypress) {
139 (window as any).appHistory = history;
142 const services = createServices(config, {
143 progressFn: (id, working) => {
144 store.dispatch(progressIndicatorActions.TOGGLE_WORKING({ id, working }));
146 errorFn: (id, error, showSnackBar: boolean) => {
148 console.error("Backend error:", error);
150 if (error.status === 404) {
151 store.dispatch(openNotFoundDialog());
152 } else if (error.status === 401 && error.errors[0].indexOf("Not logged in") > -1) {
153 // Catch auth errors when navigating and redirect to login preserving url location
154 store.dispatch(logout(false, true));
155 } else if (error.status !== 422) {
157 snackbarActions.OPEN_SNACKBAR({
158 message: `${error.errors ? error.errors[0] : error.message}`,
159 kind: SnackbarKind.ERROR,
168 // be sure this is initiated before the app starts
169 servicesProvider.setServices(services);
171 const store = configureStore(history, services, config);
173 servicesProvider.setStore(store);
175 store.subscribe(initListener(history, store, services, config));
176 store.dispatch(initAuth(config));
177 store.dispatch(setBuildInfo());
178 store.dispatch(setTokenDialogApiHost(apiHost));
179 store.dispatch(loadVocabulary);
180 store.dispatch(loadFileViewersConfig);
182 const TokenComponent = (props: any) => (
184 authService={services.authService}
190 const AddSessionComponent = (props: any) => <AddSession {...props} />;
191 const FedTokenComponent = (props: any) => (
193 authService={services.authService}
199 const MainPanelComponent = (props: any) => <MainPanel {...props} />;
202 <MuiThemeProvider theme={CustomTheme}>
203 <DragDropContextProvider backend={HTML5Backend}>
204 <Provider store={store}>
205 <ConnectedRouter history={history}>
209 component={TokenComponent}
212 path={Routes.FED_LOGIN}
213 component={FedTokenComponent}
216 path={Routes.ADD_SESSION}
217 component={AddSessionComponent}
221 component={MainPanelComponent}
226 </DragDropContextProvider>
230 ReactDOM.render(<App />, document.getElementById("root") as HTMLElement);
233 const initListener = (history: History, store: RootStore, services: ServiceRepository, config: Config) => {
234 let initialized = false;
236 const { router, auth } = store.getState();
237 if (router.location && auth.user && services.authService.getApiToken() && !initialized) {
239 initWebSocket(config, services.authService, store);
240 await store.dispatch(loadWorkbench());
241 addRouteChangeHandlers(history, store);
242 // ToDo: move to searchBar component
243 store.dispatch(initAdvancedFormProjectsTree());