fix: persist local feature flag overrides (#17882)

pull/17885/head
Alex Boatwright 2020-04-28 11:04:49 -07:00 committed by GitHub
parent 7568ade1ca
commit 0d48f4c09a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 2 deletions

View File

@ -25,6 +25,10 @@ export const localState: LocalStorage = {
theme: 'dark',
},
},
flags: {
original: {},
override: {},
},
VERSION: '2.0.0',
ranges: {
'0349ecda531ea000': pastFifteenMinTimeRange,

View File

@ -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),

View File

@ -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

View File

@ -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