Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix template variable control bar not persisting whether it was open #4234

Merged
merged 3 commits into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

### Bug Fixes
1. [#4231](https://github.com/influxdata/chronograf/pull/4231): Fix notifying user to press ESC to exit presentation mode
1. [#4234](https://github.com/influxdata/chronograf/pull/4234): Fix persisting whether or not template variable control bar is open

## v1.6.1 [2018-08-02]

Expand Down
26 changes: 11 additions & 15 deletions ui/src/dashboards/containers/DashboardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ interface Props extends ManualRefreshProps, WithRouterProps {
timeRange: QueriesModels.TimeRange
zoomedTimeRange: QueriesModels.TimeRange
inPresentationMode: boolean
showTemplateVariableControlBar: boolean
toggleTemplateVariableControlBar: typeof appActions.toggleTemplateVariableControlBar
handleClickPresentationButton: AppActions.DelayEnablePresentationModeDispatcher
cellQueryStatus: {
queryID: string
Expand Down Expand Up @@ -126,7 +128,6 @@ interface State {
windowHeight: number
selectedCell: DashboardsModels.Cell | null
dashboardLinks: DashboardsModels.DashboardSwitcherLinks
showTempVarControls: boolean
showAnnotationControls: boolean
}

Expand All @@ -141,7 +142,6 @@ class DashboardPage extends Component<Props, State> {
windowHeight: window.innerHeight,
dashboardLinks: EMPTY_LINKS,
showAnnotationControls: false,
showTempVarControls: false,
}
}

Expand Down Expand Up @@ -217,10 +217,12 @@ class DashboardPage extends Component<Props, State> {
thresholdsListType,
thresholdsListColors,
inPresentationMode,
showTemplateVariableControlBar,
handleChooseAutoRefresh,
handleShowCellEditorOverlay,
handleHideCellEditorOverlay,
handleClickPresentationButton,
toggleTemplateVariableControlBar,
} = this.props
const low = zoomedLower || lower
const up = zoomedUpper || upper
Expand Down Expand Up @@ -267,11 +269,7 @@ class DashboardPage extends Component<Props, State> {
templatesIncludingDashTime = []
}

const {
dashboardLinks,
showTempVarControls,
showAnnotationControls,
} = this.state
const {dashboardLinks, showAnnotationControls} = this.state

return (
<div className="page dashboard-page">
Expand Down Expand Up @@ -307,15 +305,15 @@ class DashboardPage extends Component<Props, State> {
dashboardLinks={dashboardLinks}
activeDashboard={dashboard ? dashboard.name : ''}
showAnnotationControls={showAnnotationControls}
showTempVarControls={showTempVarControls}
showTempVarControls={showTemplateVariableControlBar}
handleChooseAutoRefresh={handleChooseAutoRefresh}
handleChooseTimeRange={this.handleChooseTimeRange}
onToggleShowTempVarControls={this.toggleTempVarControls}
onToggleShowTempVarControls={toggleTemplateVariableControlBar}
onToggleShowAnnotationControls={this.toggleAnnotationControls}
handleClickPresentationButton={handleClickPresentationButton}
/>
{!inPresentationMode &&
showTempVarControls && (
showTemplateVariableControlBar && (
<TemplateControlBar
templates={dashboard && dashboard.templates}
meRole={meRole}
Expand Down Expand Up @@ -526,10 +524,6 @@ class DashboardPage extends Component<Props, State> {
}
}

private toggleTempVarControls = () => {
this.setState({showTempVarControls: !this.state.showTempVarControls})
}

private toggleAnnotationControls = () => {
this.setState({showAnnotationControls: !this.state.showAnnotationControls})
}
Expand Down Expand Up @@ -572,7 +566,7 @@ const mstp = (state, {params: {dashboardID}}) => {
const {
app: {
ephemeral: {inPresentationMode},
persisted: {autoRefresh},
persisted: {autoRefresh, showTemplateVariableControlBar},
},
dashboardUI: {dashboards, cellQueryStatus, zoomedTimeRange},
sources,
Expand Down Expand Up @@ -618,6 +612,7 @@ const mstp = (state, {params: {dashboardID}}) => {
thresholdsListColors,
gaugeColors,
lineColors,
showTemplateVariableControlBar,
}
}

Expand All @@ -634,6 +629,7 @@ const mdtp = {
cloneDashboardCellAsync: dashboardActions.cloneDashboardCellAsync,
deleteDashboardCellAsync: dashboardActions.deleteDashboardCellAsync,
templateVariableLocalSelected: dashboardActions.templateVariableLocalSelected,
toggleTemplateVariableControlBar: appActions.toggleTemplateVariableControlBar,
getDashboardWithTemplatesAsync:
dashboardActions.getDashboardWithTemplatesAsync,
rehydrateTemplatesAsync: dashboardActions.rehydrateTemplatesAsync,
Expand Down
5 changes: 5 additions & 0 deletions ui/src/shared/actions/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ActionTypes,
EnablePresentationModeAction,
DisablePresentationModeAction,
ToggleTemplateVariableControlBarAction,
DelayEnablePresentationModeDispatcher,
SetAutoRefreshActionCreator,
SetAutoRefreshAction,
Expand Down Expand Up @@ -42,3 +43,7 @@ export const setAutoRefresh: SetAutoRefreshActionCreator = (
milliseconds,
},
})

export const toggleTemplateVariableControlBar = (): ToggleTemplateVariableControlBarAction => ({
type: ActionTypes.ToggleTemplateVariableControlBar,
})
1 change: 1 addition & 0 deletions ui/src/shared/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ export const HTTP_FORBIDDEN = 403
export const HTTP_NOT_FOUND = 404

export const AUTOREFRESH_DEFAULT = 0 // in milliseconds
export const SHOW_TEMP_VAR_CONTROL_BAR_DEFAULT = false

export const GRAPH = 'graph'
export const TABLE = 'table'
Expand Down
15 changes: 14 additions & 1 deletion ui/src/shared/reducers/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {combineReducers} from 'redux'

import {AUTOREFRESH_DEFAULT} from 'src/shared/constants'
import {
AUTOREFRESH_DEFAULT,
SHOW_TEMP_VAR_CONTROL_BAR_DEFAULT,
} from 'src/shared/constants'
import {ActionTypes, Action} from 'src/types/actions/app'

interface State {
Expand All @@ -9,6 +12,7 @@ interface State {
}
persisted: {
autoRefresh: number
showTemplateVariableControlBar: boolean
}
}

Expand All @@ -18,6 +22,7 @@ const initialState: State = {
},
persisted: {
autoRefresh: AUTOREFRESH_DEFAULT,
showTemplateVariableControlBar: SHOW_TEMP_VAR_CONTROL_BAR_DEFAULT,
},
}

Expand Down Expand Up @@ -62,6 +67,14 @@ const appPersistedReducer = (
}
}

case ActionTypes.ToggleTemplateVariableControlBar: {
const update = !state.showTemplateVariableControlBar
return {
...state,
showTemplateVariableControlBar: update,
}
}

default:
return state
}
Expand Down
7 changes: 6 additions & 1 deletion ui/src/types/actions/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ export enum ActionTypes {
EnablePresentationMode = 'ENABLE_PRESENTATION_MODE',
DisablePresentationMode = 'DISABLE_PRESENTATION_MODE',
SetAutoRefresh = 'SET_AUTOREFRESH',
TemplateControlBarVisibilityToggled = 'TemplateControlBarVisibilityToggledAction',
ToggleTemplateVariableControlBar = 'TOGGLE_TEMPLATE_VARIABLE_CONTROL_BAR',
Noop = 'NOOP',
}

export type Action =
| EnablePresentationModeAction
| DisablePresentationModeAction
| SetAutoRefreshAction
| ToggleTemplateVariableControlBarAction

export type EnablePresentationModeActionCreator = () => EnablePresentationModeAction

Expand All @@ -23,6 +24,10 @@ export interface DisablePresentationModeAction {
type: ActionTypes.DisablePresentationMode
}

export interface ToggleTemplateVariableControlBarAction {
type: ActionTypes.ToggleTemplateVariableControlBar
}

export type DelayEnablePresentationModeDispatcher = () => DelayEnablePresentationModeThunk

export type DelayEnablePresentationModeThunk = (
Expand Down
11 changes: 11 additions & 0 deletions ui/test/shared/reducers/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
enablePresentationMode,
disablePresentationMode,
setAutoRefresh,
toggleTemplateVariableControlBar,
} from 'src/shared/actions/app'

describe('Shared.Reducers.appReducer', () => {
Expand All @@ -12,6 +13,7 @@ describe('Shared.Reducers.appReducer', () => {
},
persisted: {
autoRefresh: 0,
showTemplateVariableControlBar: false,
},
}

Expand All @@ -36,4 +38,13 @@ describe('Shared.Reducers.appReducer', () => {

expect(reducedState.persisted.autoRefresh).toBe(expectedMs)
})

it('should handle TOGGLE_TEMPLATE_VARIABLE_CONTROL_BAR', () => {
const reducedState = appReducer(
initialState,
toggleTemplateVariableControlBar()
)

expect(reducedState.persisted.showTemplateVariableControlBar).toBe(true)
})
})