diff --git a/ui/src/mockState.tsx b/ui/src/mockState.tsx index 2610bc275f..673d449961 100644 --- a/ui/src/mockState.tsx +++ b/ui/src/mockState.tsx @@ -25,6 +25,10 @@ export const localState: LocalStorage = { theme: 'dark', }, }, + flags: { + original: {}, + override: {}, + }, VERSION: '2.0.0', ranges: { '0349ecda531ea000': pastFifteenMinTimeRange, diff --git a/ui/src/normalizers/localStorage/localStorage.ts b/ui/src/normalizers/localStorage/localStorage.ts index 9dd1a5e94e..97b051a67a 100644 --- a/ui/src/normalizers/localStorage/localStorage.ts +++ b/ui/src/normalizers/localStorage/localStorage.ts @@ -34,11 +34,12 @@ export const normalizeGetLocalStorage = (state: LocalStorage): LocalStorage => { } export const normalizeSetLocalStorage = (state: LocalStorage): LocalStorage => { - const {app, ranges, autoRefresh, userSettings} = state + const {app, flags, ranges, autoRefresh, userSettings} = state return { VERSION, autoRefresh, userSettings, + flags, app: normalizeApp(app), ranges: setLocalStateRanges(ranges), resources: normalizeResources(state), diff --git a/ui/src/shared/utils/featureFlag.ts b/ui/src/shared/utils/featureFlag.ts index dc67914f86..2630df0a7b 100644 --- a/ui/src/shared/utils/featureFlag.ts +++ b/ui/src/shared/utils/featureFlag.ts @@ -51,10 +51,12 @@ export const set = (flagName: string, value: string | boolean) => { store.dispatch(setOverride(flagName, value)) } -export const toggle = (flagName: string) => { +export const toggle = (flagName: string): boolean => { const flags = getUserFlags() set(flagName, !flags[flagName]) + + return !flags[flagName] } // Expose utility in dev tools console for convenience diff --git a/ui/src/types/localStorage.ts b/ui/src/types/localStorage.ts index 3ecf1eb380..fffc7cafc8 100644 --- a/ui/src/types/localStorage.ts +++ b/ui/src/types/localStorage.ts @@ -1,11 +1,13 @@ import {UserSettingsState} from 'src/userSettings/reducers' import {AutoRefreshState} from 'src/shared/reducers/autoRefresh' +import {FlagState} from 'src/shared/reducers/flags' import {RangeState} from 'src/dashboards/reducers/ranges' import {AppState, ResourceState} from 'src/types' export interface LocalStorage { VERSION: string app: AppState['app'] + flags: FlagState ranges: RangeState autoRefresh: AutoRefreshState userSettings: UserSettingsState