X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/42db83a0075f9704dcbfb2cd29821c97ff0fe34b..fe5d65e4e704358fab18d91dae5a97ff7659f5df:/src/store/auth/auth-reducer.ts diff --git a/src/store/auth/auth-reducer.ts b/src/store/auth/auth-reducer.ts index 8f234dad35..a2822f100c 100644 --- a/src/store/auth/auth-reducer.ts +++ b/src/store/auth/auth-reducer.ts @@ -6,26 +6,29 @@ import { authActions, AuthAction } from "./auth-action"; import { User } from "~/models/user"; import { ServiceRepository } from "~/services/services"; import { SshKeyResource } from '~/models/ssh-key'; +import { Session } from "~/models/session"; export interface AuthState { user?: User; apiToken?: string; - sshKeys?: SshKeyResource[]; + sshKeys: SshKeyResource[]; + sessions: Session[]; } const initialState: AuthState = { user: undefined, apiToken: undefined, - sshKeys: [] + sshKeys: [], + sessions: [] }; -export const authReducer = (services: ServiceRepository) => (state: AuthState = initialState, action: AuthAction) => { +export const authReducer = (services: ServiceRepository) => (state = initialState, action: AuthAction) => { return authActions.match(action, { SAVE_API_TOKEN: (token: string) => { return {...state, apiToken: token}; }, INIT: ({ user, token }) => { - return { user, apiToken: token }; + return { ...state, user, apiToken: token }; }, LOGIN: () => { return state; @@ -40,7 +43,30 @@ export const authReducer = (services: ServiceRepository) => (state: AuthState = return {...state, sshKeys}; }, ADD_SSH_KEY: (sshKey: SshKeyResource) => { - return { ...state, sshKeys: state.sshKeys!.concat(sshKey) }; + return { ...state, sshKeys: state.sshKeys.concat(sshKey) }; + }, + REMOVE_SSH_KEY: (uuid: string) => { + return { ...state, sshKeys: state.sshKeys.filter((sshKey) => sshKey.uuid !== uuid )}; + }, + SET_SESSIONS: (sessions: Session[]) => { + return { ...state, sessions }; + }, + ADD_SESSION: (session: Session) => { + return { ...state, sessions: state.sessions.concat(session) }; + }, + REMOVE_SESSION: (clusterId: string) => { + return { + ...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 });