Wire up OptIn into DisplayOptions

pull/1858/head
Jared Scheib 2017-08-07 21:02:49 -07:00
parent bb928e0668
commit 1ae6a624a9
4 changed files with 58 additions and 50 deletions

View File

@ -1,8 +1,15 @@
import React, {PropTypes} from 'react' import React, {PropTypes} from 'react'
import _ from 'lodash' import _ from 'lodash'
import OptIn from 'shared/components/OptIn'
// TODO: add logic for for Prefix, Suffix, Scale, and Multiplier // TODO: add logic for for Prefix, Suffix, Scale, and Multiplier
const AxesOptions = ({onSetRange, onSetLabel, axes}) => { const AxesOptions = ({
onSetYAxisBoundMin,
onSetYAxisBoundMax,
onSetLabel,
axes,
}) => {
const min = _.get(axes, ['y', 'bounds', '0'], '') const min = _.get(axes, ['y', 'bounds', '0'], '')
const max = _.get(axes, ['y', 'bounds', '1'], '') const max = _.get(axes, ['y', 'bounds', '1'], '')
const label = _.get(axes, ['y', 'label'], '') const label = _.get(axes, ['y', 'label'], '')
@ -12,44 +19,29 @@ const AxesOptions = ({onSetRange, onSetLabel, axes}) => {
<h5 className="display-options--header">Y Axis Controls</h5> <h5 className="display-options--header">Y Axis Controls</h5>
<form autoComplete="off" style={{margin: '0 -6px'}}> <form autoComplete="off" style={{margin: '0 -6px'}}>
<div className="form-group col-sm-12"> <div className="form-group col-sm-12">
<label htmlFor="prefix">Title</label> <OptIn
<input rightLabel={'label'}
className="form-control input-sm"
type="text"
name="label"
id="label"
value={label} value={label}
onChange={onSetLabel} onSetValue={onSetLabel}
placeholder="auto" type="text"
/> />
</div> </div>
<div className="form-group col-sm-6"> <div className="form-group col-sm-6">
<label htmlFor="min">Min</label> <OptIn
<input rightLabel={'min'}
className="form-control input-sm"
type="number"
name="min"
id="min"
value={min} value={min}
onChange={onSetRange} onSetValue={onSetYAxisBoundMin}
placeholder="auto" type="number"
/> />
</div> </div>
<div className="form-group col-sm-6"> <div className="form-group col-sm-6">
<label htmlFor="max">Max</label> <OptIn
<input rightLabel={'max'}
className="form-control input-sm"
type="number"
name="max"
id="max"
value={max} value={max}
onChange={onSetRange} onSetValue={onSetYAxisBoundMax}
placeholder="auto" type="number"
/> />
</div> </div>
<p className="display-options--footnote">
Values left blank will be set automatically
</p>
{/* <div className="form-group col-sm-6"> {/* <div className="form-group col-sm-6">
<label htmlFor="prefix">Labels Prefix</label> <label htmlFor="prefix">Labels Prefix</label>
<input <input
@ -90,7 +82,8 @@ const AxesOptions = ({onSetRange, onSetLabel, axes}) => {
const {arrayOf, func, shape, string} = PropTypes const {arrayOf, func, shape, string} = PropTypes
AxesOptions.propTypes = { AxesOptions.propTypes = {
onSetRange: func.isRequired, onSetYAxisBoundMin: func.isRequired,
onSetYAxisBoundMax: func.isRequired,
onSetLabel: func.isRequired, onSetLabel: func.isRequired,
axes: shape({ axes: shape({
y: shape({ y: shape({

View File

@ -32,7 +32,8 @@ class CellEditorOverlay extends Component {
this.handleClickDisplayOptionsTab = ::this.handleClickDisplayOptionsTab this.handleClickDisplayOptionsTab = ::this.handleClickDisplayOptionsTab
this.handleSetActiveQueryIndex = ::this.handleSetActiveQueryIndex this.handleSetActiveQueryIndex = ::this.handleSetActiveQueryIndex
this.handleEditRawText = ::this.handleEditRawText this.handleEditRawText = ::this.handleEditRawText
this.handleSetYAxisBounds = ::this.handleSetYAxisBounds this.handleSetYAxisBoundMin = ::this.handleSetYAxisBoundMin
this.handleSetYAxisBoundMax = ::this.handleSetYAxisBoundMax
this.handleSetLabel = ::this.handleSetLabel this.handleSetLabel = ::this.handleSetLabel
const {cell: {name, type, queries, axes}} = props const {cell: {name, type, queries, axes}} = props
@ -93,22 +94,28 @@ class CellEditorOverlay extends Component {
} }
} }
handleSetYAxisBounds(e) { handleSetYAxisBoundMin(min) {
const {min, max} = e.target.form
const {axes} = this.state const {axes} = this.state
const {y: {bounds: [, max]}} = axes
this.setState({ this.setState({
axes: {...axes, y: {...axes.y, bounds: [min.value, max.value]}}, axes: {...axes, y: {...axes.y, bounds: [min, max]}},
}) })
e.preventDefault()
} }
handleSetLabel(e) { handleSetYAxisBoundMax(max) {
const {label} = e.target.form const {axes} = this.state
const {y: {bounds: [min]}} = axes
this.setState({
axes: {...axes, y: {...axes.y, bounds: [min, max]}},
})
}
handleSetLabel(value) {
const {axes} = this.state const {axes} = this.state
this.setState({axes: {...axes, y: {...axes.y, label: label.value}}}) this.setState({axes: {...axes, y: {...axes.y, label: value}}})
e.preventDefault()
} }
handleAddQuery(options) { handleAddQuery(options) {
@ -245,7 +252,8 @@ class CellEditorOverlay extends Component {
? <DisplayOptions ? <DisplayOptions
selectedGraphType={cellWorkingType} selectedGraphType={cellWorkingType}
onSelectGraphType={this.handleSelectGraphType} onSelectGraphType={this.handleSelectGraphType}
onSetRange={this.handleSetYAxisBounds} onSetYAxisBoundMin={this.handleSetYAxisBoundMin}
onSetYAxisBoundMax={this.handleSetYAxisBoundMax}
onSetLabel={this.handleSetLabel} onSetLabel={this.handleSetLabel}
axes={axes} axes={axes}
/> />

View File

@ -7,7 +7,8 @@ const DisplayOptions = ({
selectedGraphType, selectedGraphType,
onSelectGraphType, onSelectGraphType,
onSetLabel, onSetLabel,
onSetRange, onSetYAxisBoundMin,
onSetYAxisBoundMax,
axes, axes,
}) => }) =>
<div className="display-options"> <div className="display-options">
@ -15,7 +16,12 @@ const DisplayOptions = ({
selectedGraphType={selectedGraphType} selectedGraphType={selectedGraphType}
onSelectGraphType={onSelectGraphType} onSelectGraphType={onSelectGraphType}
/> />
<AxesOptions onSetLabel={onSetLabel} onSetRange={onSetRange} axes={axes} /> <AxesOptions
onSetLabel={onSetLabel}
onSetYAxisBoundMin={onSetYAxisBoundMin}
onSetYAxisBoundMax={onSetYAxisBoundMax}
axes={axes}
/>
</div> </div>
const {func, shape, string} = PropTypes const {func, shape, string} = PropTypes
@ -23,7 +29,8 @@ const {func, shape, string} = PropTypes
DisplayOptions.propTypes = { DisplayOptions.propTypes = {
selectedGraphType: string.isRequired, selectedGraphType: string.isRequired,
onSelectGraphType: func.isRequired, onSelectGraphType: func.isRequired,
onSetRange: func.isRequired, onSetYAxisBoundMin: func.isRequired,
onSetYAxisBoundMax: func.isRequired,
onSetLabel: func.isRequired, onSetLabel: func.isRequired,
axes: shape({}).isRequired, axes: shape({}).isRequired,
} }

View File

@ -114,12 +114,11 @@ class OptIn extends Component {
setValue() { setValue() {
const {onSetValue} = this.props const {onSetValue} = this.props
const {useRightValue, leftValue, rightValue} = this.state const {useRightValue, leftValue, rightValue} = this.state
if (useRightValue) { if (useRightValue) {
onSetValue({value: rightValue}) onSetValue(rightValue)
} else { } else {
this.setState({rightValue: ''}) this.setState({rightValue: ''})
onSetValue({value: leftValue}) onSetValue(leftValue)
} }
// reset UI interaction state-tracking values & prevent blur + click // reset UI interaction state-tracking values & prevent blur + click
@ -129,7 +128,7 @@ class OptIn extends Component {
} }
render() { render() {
const {leftLabel, rightLabel} = this.props const {leftLabel, rightLabel, type} = this.props
const {useRightValue, rightValue} = this.state const {useRightValue, rightValue} = this.state
return ( return (
@ -150,9 +149,9 @@ class OptIn extends Component {
</div> </div>
<input <input
className="form-control input-sm" className="form-control input-sm"
type="number" type={type}
name="rightValueInput" name={rightLabel}
id="rightValueInput" id={rightLabel}
ref={el => (this.rightValueInput = el)} ref={el => (this.rightValueInput = el)}
value={rightValue} value={rightValue}
onClick={() => { onClick={() => {
@ -176,7 +175,7 @@ OptIn.defaultProps = {
rightLabel: 'Custom Value', rightLabel: 'Custom Value',
value: '', value: '',
} }
const {func, string} = PropTypes const {func, oneOf, string} = PropTypes
OptIn.propTypes = { OptIn.propTypes = {
leftLabel: string, leftLabel: string,
@ -184,6 +183,7 @@ OptIn.propTypes = {
rightLabel: string, rightLabel: string,
value: string, value: string,
onSetValue: func.isRequired, onSetValue: func.isRequired,
type: oneOf(['text', 'number']),
} }
export default OptIn export default OptIn