From 963bed34bf2ac828384bbbda737e0d8a540bddbb Mon Sep 17 00:00:00 2001 From: Alex Collins Date: Tue, 15 Jun 2021 10:33:03 -0700 Subject: [PATCH] fix(ui): Fix-up local storage namespaces. Fixes #6109 (#6144) --- ui/src/app/shared/utils.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ui/src/app/shared/utils.ts b/ui/src/app/shared/utils.ts index cf872f1587d5..123e0a47cef1 100644 --- a/ui/src/app/shared/utils.ts +++ b/ui/src/app/shared/utils.ts @@ -81,7 +81,14 @@ export const Utils = { }, get managedNamespace() { - return localStorage.getItem(managedNamespaceKey); + return this.fixLocalStorageString(localStorage.getItem(managedNamespaceKey)); + }, + + fixLocalStorageString(x: string): string { + // empty string is valid, so we cannot use `truthy` + if (x !== null && x !== 'null' && x !== 'undefined') { + return x; + } }, onNamespaceChange(value: string) { @@ -99,7 +106,7 @@ export const Utils = { get currentNamespace() { // we always prefer the managed namespace - return this.managedNamespace || localStorage.getItem(currentNamespaceKey); + return this.managedNamespace || this.fixLocalStorageString(localStorage.getItem(currentNamespaceKey)); }, // return a namespace, favoring managed namespace when set