Reset focus to CEO after deleting a threshold or hitting max thresholds

Previously the UI would lose focus and keyboard events no longer fire
pull/2869/head
Alex P 2018-02-27 13:45:56 -08:00
parent e8f80a15ac
commit 13770e31cb
4 changed files with 25 additions and 6 deletions

View File

@ -249,6 +249,10 @@ class CellEditorOverlay extends Component {
} }
} }
handleResetFocus = () => {
this.overlayRef.focus()
}
render() { render() {
const { const {
onCancel, onCancel,
@ -313,6 +317,7 @@ class CellEditorOverlay extends Component {
queryConfigs={queriesWorkingDraft} queryConfigs={queriesWorkingDraft}
onToggleStaticLegend={this.handleToggleStaticLegend} onToggleStaticLegend={this.handleToggleStaticLegend}
staticLegend={staticLegend} staticLegend={staticLegend}
onResetFocus={this.handleResetFocus}
/> />
: <QueryMaker : <QueryMaker
source={this.getSource()} source={this.getSource()}

View File

@ -35,12 +35,17 @@ class DisplayOptions extends Component {
} }
renderOptions = () => { renderOptions = () => {
const {cell: {type}, staticLegend, onToggleStaticLegend} = this.props const {
cell: {type},
staticLegend,
onToggleStaticLegend,
onResetFocus,
} = this.props
switch (type) { switch (type) {
case 'gauge': case 'gauge':
return <GaugeOptions /> return <GaugeOptions onResetFocus={onResetFocus} />
case 'single-stat': case 'single-stat':
return <SingleStatOptions /> return <SingleStatOptions onResetFocus={onResetFocus} />
default: default:
return ( return (
<AxesOptions <AxesOptions
@ -77,6 +82,7 @@ DisplayOptions.propTypes = {
queryConfigs: arrayOf(shape()).isRequired, queryConfigs: arrayOf(shape()).isRequired,
onToggleStaticLegend: func.isRequired, onToggleStaticLegend: func.isRequired,
staticLegend: bool, staticLegend: bool,
onResetFocus: func.isRequired,
} }
const mapStateToProps = ({cellEditorOverlay: {cell, cell: {axes}}}) => ({ const mapStateToProps = ({cellEditorOverlay: {cell, cell: {axes}}}) => ({

View File

@ -22,7 +22,7 @@ import {
class GaugeOptions extends Component { class GaugeOptions extends Component {
handleAddThreshold = () => { handleAddThreshold = () => {
const {gaugeColors, handleUpdateGaugeColors} = this.props const {gaugeColors, handleUpdateGaugeColors, onResetFocus} = this.props
const sortedColors = _.sortBy(gaugeColors, color => color.value) const sortedColors = _.sortBy(gaugeColors, color => color.value)
if (sortedColors.length <= MAX_THRESHOLDS) { if (sortedColors.length <= MAX_THRESHOLDS) {
@ -47,16 +47,19 @@ class GaugeOptions extends Component {
} }
handleUpdateGaugeColors([...gaugeColors, newThreshold]) handleUpdateGaugeColors([...gaugeColors, newThreshold])
} else {
onResetFocus()
} }
} }
handleDeleteThreshold = threshold => () => { handleDeleteThreshold = threshold => () => {
const {handleUpdateGaugeColors} = this.props const {handleUpdateGaugeColors, onResetFocus} = this.props
const gaugeColors = this.props.gaugeColors.filter( const gaugeColors = this.props.gaugeColors.filter(
color => color.id !== threshold.id color => color.id !== threshold.id
) )
handleUpdateGaugeColors(gaugeColors) handleUpdateGaugeColors(gaugeColors)
onResetFocus()
} }
handleChooseColor = threshold => chosenColor => { handleChooseColor = threshold => chosenColor => {
@ -217,6 +220,7 @@ GaugeOptions.propTypes = {
handleUpdateGaugeColors: func.isRequired, handleUpdateGaugeColors: func.isRequired,
handleUpdateAxes: func.isRequired, handleUpdateAxes: func.isRequired,
axes: shape({}).isRequired, axes: shape({}).isRequired,
onResetFocus: func.isRequired,
} }
const mapStateToProps = ({cellEditorOverlay: {gaugeColors, cell: {axes}}}) => ({ const mapStateToProps = ({cellEditorOverlay: {gaugeColors, cell: {axes}}}) => ({

View File

@ -42,6 +42,7 @@ class SingleStatOptions extends Component {
singleStatColors, singleStatColors,
singleStatType, singleStatType,
handleUpdateSingleStatColors, handleUpdateSingleStatColors,
onResetFocus,
} = this.props } = this.props
const randomColor = _.random(0, GAUGE_COLORS.length - 1) const randomColor = _.random(0, GAUGE_COLORS.length - 1)
@ -67,16 +68,18 @@ class SingleStatOptions extends Component {
} }
handleUpdateSingleStatColors([...singleStatColors, newThreshold]) handleUpdateSingleStatColors([...singleStatColors, newThreshold])
onResetFocus()
} }
handleDeleteThreshold = threshold => () => { handleDeleteThreshold = threshold => () => {
const {handleUpdateSingleStatColors} = this.props const {handleUpdateSingleStatColors, onResetFocus} = this.props
const singleStatColors = this.props.singleStatColors.filter( const singleStatColors = this.props.singleStatColors.filter(
color => color.id !== threshold.id color => color.id !== threshold.id
) )
handleUpdateSingleStatColors(singleStatColors) handleUpdateSingleStatColors(singleStatColors)
onResetFocus()
} }
handleChooseColor = threshold => chosenColor => { handleChooseColor = threshold => chosenColor => {
@ -242,6 +245,7 @@ SingleStatOptions.propTypes = {
handleUpdateSingleStatColors: func.isRequired, handleUpdateSingleStatColors: func.isRequired,
handleUpdateAxes: func.isRequired, handleUpdateAxes: func.isRequired,
axes: shape({}).isRequired, axes: shape({}).isRequired,
onResetFocus: func.isRequired,
} }
const mapStateToProps = ({ const mapStateToProps = ({