create action and reducer for updating the redux store

Co-authored-by: Deniz Kusefoglu <deniz@influxdata.com>
pull/10616/head
Iris Scholten 2018-03-08 16:01:43 -08:00
parent 076e47b9e5
commit 7cb3132a09
5 changed files with 25 additions and 8 deletions

View File

@ -50,3 +50,10 @@ export const updateAxes = axes => ({
axes,
},
})
export const updateOptions = options => ({
type: 'UPDATE_OPTIONS',
payload: {
options,
},
})

View File

@ -26,10 +26,12 @@ class GraphOptionsTimeFormat extends Component {
}
handleChooseFormat = formatOption => {
const {onTimeFormatChange} = this.props
if (formatOption.text === 'Custom') {
this.setState({customFormat: true})
} else {
this.setState({format: formatOption.text, customFormat: false})
onTimeFormatChange(formatOption.text)
}
}

View File

@ -18,7 +18,7 @@ import {MAX_THRESHOLDS} from 'src/dashboards/constants/gaugeColors'
import {
updateSingleStatType,
updateSingleStatColors,
updateAxes,
updateOptions,
} from 'src/dashboards/actions/cellEditorOverlay'
const formatColor = color => {
@ -40,7 +40,8 @@ class TableOptions extends Component {
handleChooseSortBy = () => {}
handleTimeFormatChange = timeFormat => {
this.setState({...this.state, timeFormat})
const {options, handleUpdateOptions} = this.props
handleUpdateOptions({...options, timeFormat})
}
handleToggleTimeAxis = () => {}
@ -151,16 +152,16 @@ TableOptions.propTypes = {
),
handleUpdateSingleStatType: func.isRequired,
handleUpdateSingleStatColors: func.isRequired,
handleUpdateAxes: func.isRequired,
axes: shape({}).isRequired,
handleUpdateOptions: func.isRequired,
options: shape({}).isRequired,
}
const mapStateToProps = ({
cellEditorOverlay: {singleStatType, singleStatColors, cell: {axes}},
cellEditorOverlay: {singleStatType, singleStatColors, cell: {options}},
}) => ({
singleStatType,
singleStatColors,
axes,
options,
})
const mapDispatchToProps = dispatch => ({
@ -172,7 +173,7 @@ const mapDispatchToProps = dispatch => ({
updateSingleStatColors,
dispatch
),
handleUpdateAxes: bindActionCreators(updateAxes, dispatch),
handleUpdateOptions: bindActionCreators(updateOptions, dispatch),
})
export default connect(mapStateToProps, mapDispatchToProps)(TableOptions)

View File

@ -132,7 +132,7 @@ export const DEFAULT_TABLE_COLORS = [
]
export const DEFAULT_TABLE_OPTIONS = {
timeFormat: '',
timeFormat: 'MM/DD/YYYY HH:mm:ss.ss',
verticalTimeAxis: false,
sortBy: 'time',
wrapping: 'truncate',

View File

@ -84,6 +84,13 @@ export default function cellEditorOverlay(state = initialState, action) {
return {...state, cell}
}
case 'UPDATE_OPTIONS': {
const {options} = action.payload
const cell = {...state.cell, options}
return {...state, cell}
}
}
return state