16683: Take count out from list params. Fix getPublicGroupUuid
[arvados-workbench2.git] / src / store / auth / auth-reducer.ts
index 0335752678c56421336751dfd79eaef11316db94..946407fe24172610fbc3aaf9cff7b95052a43af8 100644 (file)
@@ -7,6 +7,7 @@ import { User } from "~/models/user";
 import { ServiceRepository } from "~/services/services";
 import { SshKeyResource } from '~/models/ssh-key';
 import { Session } from "~/models/session";
+import { Config, mockConfig } from '~/common/config';
 
 export interface AuthState {
     user?: User;
@@ -15,7 +16,10 @@ export interface AuthState {
     sessions: Session[];
     localCluster: string;
     homeCluster: string;
+    loginCluster: string;
     remoteHosts: { [key: string]: string };
+    remoteHostsConfig: { [key: string]: Config };
+    config: Config;
 }
 
 const initialState: AuthState = {
@@ -25,23 +29,32 @@ const initialState: AuthState = {
     sessions: [],
     localCluster: "",
     homeCluster: "",
-    remoteHosts: {}
+    loginCluster: "",
+    remoteHosts: {},
+    remoteHostsConfig: {},
+    config: mockConfig({})
 };
 
 export const authReducer = (services: ServiceRepository) => (state = initialState, action: AuthAction) => {
     return authActions.match(action, {
-        SAVE_API_TOKEN: (token: string) => {
-            return { ...state, apiToken: token };
-        },
-        CONFIG: ({ config }) => {
+        SET_CONFIG: ({ config }) => {
             return {
                 ...state,
+                config,
                 localCluster: config.uuidPrefix,
                 remoteHosts: { ...config.remoteHosts, [config.uuidPrefix]: new URL(config.rootUrl).host },
-                homeCluster: config.uuidPrefix
+                homeCluster: config.loginCluster || config.uuidPrefix,
+                loginCluster: config.loginCluster,
+                remoteHostsConfig: { ...state.remoteHostsConfig, [config.uuidPrefix]: config }
+            };
+        },
+        REMOTE_CLUSTER_CONFIG: ({ config }) => {
+            return {
+                ...state,
+                remoteHostsConfig: { ...state.remoteHostsConfig, [config.uuidPrefix]: config },
             };
         },
-        INIT: ({ user, token }) => {
+        INIT_USER: ({ user, token }) => {
             return { ...state, user, apiToken: token, homeCluster: user.uuid.substr(0, 5) };
         },
         LOGIN: () => {
@@ -51,7 +64,7 @@ export const authReducer = (services: ServiceRepository) => (state = initialStat
             return { ...state, apiToken: undefined };
         },
         USER_DETAILS_SUCCESS: (user: User) => {
-            return { ...state, user };
+            return { ...state, user, homeCluster: user.uuid.substr(0, 5) };
         },
         SET_SSH_KEYS: (sshKeys: SshKeyResource[]) => {
             return { ...state, sshKeys };