From 1303234b07bb41889c5511c9cbe4fb316ed10789 Mon Sep 17 00:00:00 2001 From: Andrew Watkins Date: Mon, 16 Mar 2020 12:58:24 -0700 Subject: [PATCH] refactor(theme): remove currentPage from localStorage --- ui/src/App.tsx | 3 ++- .../components/DashboardContainer.tsx | 2 +- ui/src/mockState.tsx | 1 - ui/src/shared/actions/app.ts | 6 +----- ui/src/shared/reducers/app.ts | 6 ------ ui/src/shared/reducers/currentPage.ts | 20 +++++++++++++++++++ ui/src/store/configureStore.ts | 2 ++ ui/src/types/stores.ts | 2 ++ 8 files changed, 28 insertions(+), 14 deletions(-) create mode 100644 ui/src/shared/reducers/currentPage.ts diff --git a/ui/src/App.tsx b/ui/src/App.tsx index f8538b98b9a..11643fe09d4 100644 --- a/ui/src/App.tsx +++ b/ui/src/App.tsx @@ -62,8 +62,9 @@ const mstp = (state: AppState): StateProps => { const { app: { ephemeral: {inPresentationMode}, - persisted: {currentPage, theme}, + persisted: {theme}, }, + currentPage, } = state return {inPresentationMode, currentPage, theme} diff --git a/ui/src/dashboards/components/DashboardContainer.tsx b/ui/src/dashboards/components/DashboardContainer.tsx index 66c05273afe..b9597f2611f 100644 --- a/ui/src/dashboards/components/DashboardContainer.tsx +++ b/ui/src/dashboards/components/DashboardContainer.tsx @@ -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' diff --git a/ui/src/mockState.tsx b/ui/src/mockState.tsx index 081b66f169e..51741a26ee3 100644 --- a/ui/src/mockState.tsx +++ b/ui/src/mockState.tsx @@ -22,7 +22,6 @@ export const localState: LocalStorage = { showTemplateControlBar: false, timeZone: 'Local' as TimeZone, theme: 'dark', - currentPage: 'not set', }, }, VERSION: '2.0.0', diff --git a/ui/src/shared/actions/app.ts b/ui/src/shared/actions/app.ts index c1c76323bb3..8a239449704 100644 --- a/ui/src/shared/actions/app.ts +++ b/ui/src/shared/actions/app.ts @@ -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', @@ -22,10 +22,6 @@ export type Action = | ReturnType | ReturnType | ReturnType - | ReturnType - -export const setCurrentPage = (currentPage: CurrentPage) => - ({type: 'SET_CURRENT_PAGE', currentPage} as const) export const setTheme = (theme: Theme) => ({type: 'SET_THEME', theme} as const) diff --git a/ui/src/shared/reducers/app.ts b/ui/src/shared/reducers/app.ts index 541ad748369..07053cc9e55 100644 --- a/ui/src/shared/reducers/app.ts +++ b/ui/src/shared/reducers/app.ts @@ -14,7 +14,6 @@ export interface AppState { showTemplateControlBar: boolean timeZone: TimeZone theme: 'dark' | 'light' - currentPage: 'dashboard' | 'not set' } } @@ -24,7 +23,6 @@ const initialState: AppState = { }, persisted: { theme: 'dark', - currentPage: 'not set', autoRefresh: AUTOREFRESH_DEFAULT_INTERVAL, showTemplateControlBar: false, timeZone: 'Local', @@ -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} } diff --git a/ui/src/shared/reducers/currentPage.ts b/ui/src/shared/reducers/currentPage.ts new file mode 100644 index 00000000000..007ae612a68 --- /dev/null +++ b/ui/src/shared/reducers/currentPage.ts @@ -0,0 +1,20 @@ +export type CurrentPage = 'dashboard' | 'not set' + +export type Action = ReturnType + +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 diff --git a/ui/src/store/configureStore.ts b/ui/src/store/configureStore.ts index 28e481fb775..47b7c1dbb22 100644 --- a/ui/src/store/configureStore.ts +++ b/ui/src/store/configureStore.ts @@ -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' @@ -56,6 +57,7 @@ export const rootReducer = combineReducers({ autoRefresh: autoRefreshReducer, alertBuilder: alertBuilderReducer, cloud: combineReducers<{limits: LimitsState}>({limits: limitsReducer}), + currentPage: currentPageReducer, currentDashboard: currentDashboardReducer, dataLoading: dataLoadingReducer, me: meReducer, diff --git a/ui/src/types/stores.ts b/ui/src/types/stores.ts index 7ee6372baf2..a8ba267a911 100644 --- a/ui/src/types/stores.ts +++ b/ui/src/types/stores.ts @@ -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' @@ -30,6 +31,7 @@ export interface AppState { app: AppPresentationState autoRefresh: AutoRefreshState cloud: {limits: LimitsState} + currentPage: CurrentPage currentDashboard: CurrentDashboardState dataLoading: DataLoadingState links: Links