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, axes,
}, },
}) })
export const updateOptions = options => ({
type: 'UPDATE_OPTIONS',
payload: {
options,
},
})

View File

@ -26,10 +26,12 @@ class GraphOptionsTimeFormat extends Component {
} }
handleChooseFormat = formatOption => { handleChooseFormat = formatOption => {
const {onTimeFormatChange} = this.props
if (formatOption.text === 'Custom') { if (formatOption.text === 'Custom') {
this.setState({customFormat: true}) this.setState({customFormat: true})
} else { } else {
this.setState({format: formatOption.text, customFormat: false}) 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 { import {
updateSingleStatType, updateSingleStatType,
updateSingleStatColors, updateSingleStatColors,
updateAxes, updateOptions,
} from 'src/dashboards/actions/cellEditorOverlay' } from 'src/dashboards/actions/cellEditorOverlay'
const formatColor = color => { const formatColor = color => {
@ -40,7 +40,8 @@ class TableOptions extends Component {
handleChooseSortBy = () => {} handleChooseSortBy = () => {}
handleTimeFormatChange = timeFormat => { handleTimeFormatChange = timeFormat => {
this.setState({...this.state, timeFormat}) const {options, handleUpdateOptions} = this.props
handleUpdateOptions({...options, timeFormat})
} }
handleToggleTimeAxis = () => {} handleToggleTimeAxis = () => {}
@ -151,16 +152,16 @@ TableOptions.propTypes = {
), ),
handleUpdateSingleStatType: func.isRequired, handleUpdateSingleStatType: func.isRequired,
handleUpdateSingleStatColors: func.isRequired, handleUpdateSingleStatColors: func.isRequired,
handleUpdateAxes: func.isRequired, handleUpdateOptions: func.isRequired,
axes: shape({}).isRequired, options: shape({}).isRequired,
} }
const mapStateToProps = ({ const mapStateToProps = ({
cellEditorOverlay: {singleStatType, singleStatColors, cell: {axes}}, cellEditorOverlay: {singleStatType, singleStatColors, cell: {options}},
}) => ({ }) => ({
singleStatType, singleStatType,
singleStatColors, singleStatColors,
axes, options,
}) })
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({
@ -172,7 +173,7 @@ const mapDispatchToProps = dispatch => ({
updateSingleStatColors, updateSingleStatColors,
dispatch dispatch
), ),
handleUpdateAxes: bindActionCreators(updateAxes, dispatch), handleUpdateOptions: bindActionCreators(updateOptions, dispatch),
}) })
export default connect(mapStateToProps, mapDispatchToProps)(TableOptions) export default connect(mapStateToProps, mapDispatchToProps)(TableOptions)

View File

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

View File

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