From dad732574ea35c188f5280162fa99586b1a3d0c0 Mon Sep 17 00:00:00 2001 From: Andres Martinez Gotor Date: Mon, 30 Sep 2019 11:03:13 +0200 Subject: [PATCH] Use auth default namespace in namespace reducer (#1190) * Use auth default namespace in namespace reducer * Fix test --- dashboard/src/reducers/namespace.test.ts | 4 ++-- dashboard/src/reducers/namespace.ts | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/dashboard/src/reducers/namespace.test.ts b/dashboard/src/reducers/namespace.test.ts index 11e99e96215..e5f1867f37d 100644 --- a/dashboard/src/reducers/namespace.test.ts +++ b/dashboard/src/reducers/namespace.test.ts @@ -54,11 +54,11 @@ describe("namespaceReducer", () => { context("when CLEAR_NAMESPACES", () => { const clearedState = { - current: "", + current: "default", namespaces: [], }; - it("clears any namespaces state", () => { + it("returns to the default namespace", () => { expect( namespaceReducer(initialState, { type: getType(actions.namespace.clearNamespaces), diff --git a/dashboard/src/reducers/namespace.ts b/dashboard/src/reducers/namespace.ts index bc2582d6548..90bcfa9f267 100644 --- a/dashboard/src/reducers/namespace.ts +++ b/dashboard/src/reducers/namespace.ts @@ -3,6 +3,7 @@ import { getType } from "typesafe-actions"; import actions from "../actions"; import { NamespaceAction } from "../actions/namespace"; +import { Auth } from "../shared/Auth"; export interface INamespaceState { current: string; @@ -10,10 +11,14 @@ export interface INamespaceState { errorMsg?: string; } -const initialState: INamespaceState = { - current: "", - namespaces: [], +const getInitialState: () => INamespaceState = (): INamespaceState => { + const token = Auth.getAuthToken() || ""; + return { + current: Auth.defaultNamespaceFromToken(token), + namespaces: [], + }; }; +const initialState: INamespaceState = getInitialState(); const namespaceReducer = ( state: INamespaceState = initialState,