Merge branch 'master' into 15088-merge-account
[arvados-workbench2.git] / src / store / auth / auth-reducer.ts
index 0504dd480086dde66b56ca606070686f6583948a..cded9f0e71816636ce1876d51c83d3976abb589c 100644 (file)
@@ -3,10 +3,11 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import { authActions, AuthAction } from "./auth-action";
-import { User } from "~/models/user";
+import { User, UserResource } from "~/models/user";
 import { ServiceRepository } from "~/services/services";
 import { SshKeyResource } from '~/models/ssh-key';
 import { Session } from "~/models/session";
+import { Config } from '~/common/config';
 
 export interface AuthState {
     user?: User;
@@ -16,6 +17,7 @@ export interface AuthState {
     localCluster: string;
     homeCluster: string;
     remoteHosts: { [key: string]: string };
+    remoteHostsConfig: { [key: string]: Config };
 }
 
 const initialState: AuthState = {
@@ -25,7 +27,8 @@ const initialState: AuthState = {
     sessions: [],
     localCluster: "",
     homeCluster: "",
-    remoteHosts: {}
+    remoteHosts: {},
+    remoteHostsConfig: {}
 };
 
 export const authReducer = (services: ServiceRepository) => (state = initialState, action: AuthAction) => {
@@ -33,9 +36,21 @@ export const authReducer = (services: ServiceRepository) => (state = initialStat
         SAVE_API_TOKEN: (token: string) => {
             return { ...state, apiToken: token };
         },
-        CONFIG: ({ uuidPrefix, remoteHosts }) => {
+        SAVE_USER: (user: UserResource) => {
+            return { ...state, user};
+        },
+        CONFIG: ({ config }) => {
+            return {
+                ...state,
+                localCluster: config.uuidPrefix,
+                remoteHosts: { ...config.remoteHosts, [config.uuidPrefix]: new URL(config.rootUrl).host },
+                homeCluster: config.uuidPrefix
+            };
+        },
+        REMOTE_CLUSTER_CONFIG: ({ config }) => {
             return {
-                ...state, localCluster: uuidPrefix, remoteHosts, homeCluster: uuidPrefix
+                ...state,
+                remoteHostsConfig: { ...state.remoteHostsConfig, [config.uuidPrefix]: config },
             };
         },
         INIT: ({ user, token }) => {