15088: Handles browser navigation during link account ops
[arvados-workbench2.git] / src / index.tsx
index e73f08c46ba8b48d2fab54bd5cbe0de89fb3b753..014627a9b2ea06e089e2e0bf7e902b51e29ce4f0 100644 (file)
@@ -14,6 +14,7 @@ import { configureStore, RootStore } from '~/store/store';
 import { ConnectedRouter } from "react-router-redux";
 import { ApiToken } from "~/views-components/api-token/api-token";
 import { initAuth } from "~/store/auth/auth-action";
+import { configActions } from "~/store/config/config-action";
 import { createServices } from "~/services/services";
 import { MuiThemeProvider } from '@material-ui/core/styles';
 import { CustomTheme } from '~/common/custom-theme';
@@ -56,7 +57,16 @@ import { virtualMachineActionSet } from '~/views-components/context-menu/action-
 import { userActionSet } from '~/views-components/context-menu/action-sets/user-action-set';
 import { computeNodeActionSet } from '~/views-components/context-menu/action-sets/compute-node-action-set';
 import { apiClientAuthorizationActionSet } from '~/views-components/context-menu/action-sets/api-client-authorization-action-set';
+import { groupActionSet } from '~/views-components/context-menu/action-sets/group-action-set';
+import { groupMemberActionSet } from '~/views-components/context-menu/action-sets/group-member-action-set';
 import { linkActionSet } from '~/views-components/context-menu/action-sets/link-action-set';
+import { loadFileViewersConfig } from '~/store/file-viewers/file-viewers-actions';
+import { collectionAdminActionSet } from '~/views-components/context-menu/action-sets/collection-admin-action-set';
+import { processResourceAdminActionSet } from '~/views-components/context-menu/action-sets/process-resource-admin-action-set';
+import { projectAdminActionSet } from '~/views-components/context-menu/action-sets/project-admin-action-set';
+import { ACCOUNT_LINK_STATUS_KEY } from '~/services/link-account-service/link-account-service';
+import { cancelLinking } from '~/store/link-account-panel/link-account-panel-actions';
+import { matchTokenRoute } from '~/routes/routes';
 
 console.log(`Starting arvados [${getBuildInfo()}]`);
 
@@ -81,6 +91,11 @@ addMenuActionSet(ContextMenuKind.USER, userActionSet);
 addMenuActionSet(ContextMenuKind.LINK, linkActionSet);
 addMenuActionSet(ContextMenuKind.NODE, computeNodeActionSet);
 addMenuActionSet(ContextMenuKind.API_CLIENT_AUTHORIZATION, apiClientAuthorizationActionSet);
+addMenuActionSet(ContextMenuKind.GROUPS, groupActionSet);
+addMenuActionSet(ContextMenuKind.GROUP_MEMBER, groupMemberActionSet);
+addMenuActionSet(ContextMenuKind.COLLECTION_ADMIN, collectionAdminActionSet);
+addMenuActionSet(ContextMenuKind.PROCESS_ADMIN, processResourceAdminActionSet);
+addMenuActionSet(ContextMenuKind.PROJECT_ADMIN, projectAdminActionSet);
 
 fetchConfig()
     .then(({ config, apiHost }) => {
@@ -96,14 +111,21 @@ fetchConfig()
         });
         const store = configureStore(history, services);
 
+        // Cancel any link account ops in progess unless the user has
+        // just logged in or there has been a successful link operation
+        const data = sessionStorage.getItem(ACCOUNT_LINK_STATUS_KEY);
+        if (!matchTokenRoute(history.location.pathname) && data === null) {
+            store.dispatch<any>(cancelLinking());
+        }
+
         store.subscribe(initListener(history, store, services, config));
-        store.dispatch(initAuth());
+        store.dispatch(initAuth(config));
         store.dispatch(setBuildInfo());
         store.dispatch(setCurrentTokenDialogApiHost(apiHost));
-        store.dispatch(setUuidPrefix(config.uuidPrefix));
         store.dispatch(loadVocabulary);
+        store.dispatch(loadFileViewersConfig);
 
-        const TokenComponent = (props: any) => <ApiToken authService={services.authService} {...props} />;
+        const TokenComponent = (props: any) => <ApiToken authService={services.authService} config={config} {...props} />;
         const MainPanelComponent = (props: any) => <MainPanel {...props} />;
 
         const App = () =>