Skip to content

Commit

Permalink
refactor(theme): remove currentPage from localStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
121watts committed Mar 16, 2020
1 parent 4c2e1b5 commit 1303234
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 14 deletions.
3 changes: 2 additions & 1 deletion ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ const mstp = (state: AppState): StateProps => {
const {
app: {
ephemeral: {inPresentationMode},
persisted: {currentPage, theme},
persisted: {theme},
},
currentPage,
} = state

return {inPresentationMode, currentPage, theme}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/dashboards/components/DashboardContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import GetTimeRange from 'src/dashboards/components/GetTimeRange'
import DashboardRoute from 'src/shared/components/DashboardRoute'

// Actions
import {setCurrentPage} from 'src/shared/actions/app'
import {setCurrentPage} from 'src/shared/reducers/currentPage'

// Utils
import {GlobalAutoRefresher} from 'src/utils/AutoRefresher'
Expand Down
1 change: 0 additions & 1 deletion ui/src/mockState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export const localState: LocalStorage = {
showTemplateControlBar: false,
timeZone: 'Local' as TimeZone,
theme: 'dark',
currentPage: 'not set',
},
},
VERSION: '2.0.0',
Expand Down
6 changes: 1 addition & 5 deletions ui/src/shared/actions/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {presentationMode} from 'src/shared/copy/notifications'

import {Dispatch} from 'redux'

import {TimeZone, Theme, CurrentPage} from 'src/types'
import {TimeZone, Theme} from 'src/types'

export enum ActionTypes {
EnablePresentationMode = 'ENABLE_PRESENTATION_MODE',
Expand All @@ -22,10 +22,6 @@ export type Action =
| ReturnType<typeof setAutoRefresh>
| ReturnType<typeof setTimeZone>
| ReturnType<typeof setTheme>
| ReturnType<typeof setCurrentPage>

export const setCurrentPage = (currentPage: CurrentPage) =>
({type: 'SET_CURRENT_PAGE', currentPage} as const)

export const setTheme = (theme: Theme) => ({type: 'SET_THEME', theme} as const)

Expand Down
6 changes: 0 additions & 6 deletions ui/src/shared/reducers/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export interface AppState {
showTemplateControlBar: boolean
timeZone: TimeZone
theme: 'dark' | 'light'
currentPage: 'dashboard' | 'not set'
}
}

Expand All @@ -24,7 +23,6 @@ const initialState: AppState = {
},
persisted: {
theme: 'dark',
currentPage: 'not set',
autoRefresh: AUTOREFRESH_DEFAULT_INTERVAL,
showTemplateControlBar: false,
timeZone: 'Local',
Expand Down Expand Up @@ -65,10 +63,6 @@ const appPersistedReducer = (
action: Action
): AppState['persisted'] => {
switch (action.type) {
case 'SET_CURRENT_PAGE': {
return {...state, currentPage: action.currentPage}
}

case 'SET_THEME': {
return {...state, theme: action.theme}
}
Expand Down
20 changes: 20 additions & 0 deletions ui/src/shared/reducers/currentPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export type CurrentPage = 'dashboard' | 'not set'

export type Action = ReturnType<typeof setCurrentPage>

export const setCurrentPage = (currentPage: CurrentPage) =>
({type: 'SET_CURRENT_PAGE', currentPage} as const)

// This only exists until we have app-wide color themes.
const currentPage = (state: CurrentPage = 'not set', action: Action) => {
switch (action.type) {
case 'SET_CURRENT_PAGE': {
return action.currentPage
}

default:
return state
}
}

export default currentPage
2 changes: 2 additions & 0 deletions ui/src/store/configureStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import persistStateEnhancer from './persistStateEnhancer'
// v2 reducers
import meReducer from 'src/shared/reducers/me'
import currentDashboardReducer from 'src/shared/reducers/currentDashboard'
import currentPageReducer from 'src/shared/reducers/currentPage'
import tasksReducer from 'src/tasks/reducers'
import rangesReducer from 'src/dashboards/reducers/ranges'
import {dashboardsReducer} from 'src/dashboards/reducers/dashboards'
Expand Down Expand Up @@ -56,6 +57,7 @@ export const rootReducer = combineReducers<ReducerState>({
autoRefresh: autoRefreshReducer,
alertBuilder: alertBuilderReducer,
cloud: combineReducers<{limits: LimitsState}>({limits: limitsReducer}),
currentPage: currentPageReducer,
currentDashboard: currentDashboardReducer,
dataLoading: dataLoadingReducer,
me: meReducer,
Expand Down
2 changes: 2 additions & 0 deletions ui/src/types/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {OverlayState} from 'src/overlays/reducers/overlays'
import {AutoRefreshState} from 'src/shared/reducers/autoRefresh'
import {LimitsState} from 'src/cloud/reducers/limits'
import {AlertBuilderState} from 'src/alerting/reducers/alertBuilder'
import {CurrentPage} from 'src/shared/reducers/currentPage'

import {ResourceState} from 'src/types'

Expand All @@ -30,6 +31,7 @@ export interface AppState {
app: AppPresentationState
autoRefresh: AutoRefreshState
cloud: {limits: LimitsState}
currentPage: CurrentPage
currentDashboard: CurrentDashboardState
dataLoading: DataLoadingState
links: Links
Expand Down

0 comments on commit 1303234

Please sign in to comment.