14720: Better login button, tell you what cluster you're logging in to.
[arvados-workbench2.git] / src / store / auth / auth-reducer.ts
index a2822f100c37b6421b465f3b7a2312d2c5b00362..0504dd480086dde66b56ca606070686f6583948a 100644 (file)
@@ -13,40 +13,54 @@ export interface AuthState {
     apiToken?: string;
     sshKeys: SshKeyResource[];
     sessions: Session[];
+    localCluster: string;
+    homeCluster: string;
+    remoteHosts: { [key: string]: string };
 }
 
 const initialState: AuthState = {
     user: undefined,
     apiToken: undefined,
     sshKeys: [],
-    sessions: []
+    sessions: [],
+    localCluster: "",
+    homeCluster: "",
+    remoteHosts: {}
 };
 
 export const authReducer = (services: ServiceRepository) => (state = initialState, action: AuthAction) => {
     return authActions.match(action, {
         SAVE_API_TOKEN: (token: string) => {
-            return {...state, apiToken: token};
+            return { ...state, apiToken: token };
+        },
+        CONFIG: ({ uuidPrefix, remoteHosts }) => {
+            return {
+                ...state, localCluster: uuidPrefix, remoteHosts, homeCluster: uuidPrefix
+            };
         },
         INIT: ({ user, token }) => {
-            return { ...state, user, apiToken: token };
+            return { ...state, user, apiToken: token, homeCluster: user.uuid.substr(0, 5) };
         },
         LOGIN: () => {
             return state;
         },
         LOGOUT: () => {
-            return {...state, apiToken: undefined};
+            return { ...state, apiToken: undefined };
         },
         USER_DETAILS_SUCCESS: (user: User) => {
-            return {...state, user};
+            return { ...state, user };
         },
         SET_SSH_KEYS: (sshKeys: SshKeyResource[]) => {
-            return {...state, sshKeys};
+            return { ...state, sshKeys };
         },
         ADD_SSH_KEY: (sshKey: SshKeyResource) => {
             return { ...state, sshKeys: state.sshKeys.concat(sshKey) };
         },
         REMOVE_SSH_KEY: (uuid: string) => {
-            return { ...state, sshKeys: state.sshKeys.filter((sshKey) => sshKey.uuid !== uuid )};
+            return { ...state, sshKeys: state.sshKeys.filter((sshKey) => sshKey.uuid !== uuid) };
+        },
+        SET_HOME_CLUSTER: (homeCluster: string) => {
+            return { ...state, homeCluster };
         },
         SET_SESSIONS: (sessions: Session[]) => {
             return { ...state, sessions };
@@ -59,14 +73,16 @@ export const authReducer = (services: ServiceRepository) => (state = initialStat
                 ...state,
                 sessions: state.sessions.filter(
                     session => session.clusterId !== clusterId
-                )};
+                )
+            };
         },
         UPDATE_SESSION: (session: Session) => {
             return {
                 ...state,
                 sessions: state.sessions.map(
                     s => s.clusterId === session.clusterId ? session : s
-                )};
+                )
+            };
         },
         default: () => state
     });