Skip to content

Commit

Permalink
Use auth default namespace in namespace reducer (#1190)
Browse files Browse the repository at this point in the history
* Use auth default namespace in namespace reducer

* Fix test
  • Loading branch information
Andres Martinez Gotor authored Sep 30, 2019
1 parent 3371873 commit dad7325
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions dashboard/src/reducers/namespace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
11 changes: 8 additions & 3 deletions dashboard/src/reducers/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ import { getType } from "typesafe-actions";

import actions from "../actions";
import { NamespaceAction } from "../actions/namespace";
import { Auth } from "../shared/Auth";

export interface INamespaceState {
current: string;
namespaces: string[];
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,
Expand Down

0 comments on commit dad7325

Please sign in to comment.