diff --git a/web/src/js/components/Modal/OptionMaster.jsx b/web/src/js/components/Modal/OptionMaster.jsx
index ac65a22aa..32f5bb4b1 100644
--- a/web/src/js/components/Modal/OptionMaster.jsx
+++ b/web/src/js/components/Modal/OptionMaster.jsx
@@ -1,5 +1,8 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
+import { connect } from 'react-redux'
+import classnames from 'classnames'
+import { update as updateOptions } from '../../ducks/options'
PureBooleanOption.PropTypes = {
value: PropTypes.bool.isRequired,
@@ -7,16 +10,12 @@ PureBooleanOption.PropTypes = {
}
function PureBooleanOption({ value, onChange, ...props}) {
- let onFocus = () => { props.onFocus() },
- onBlur = () => { props.onBlur() },
- onMouseEnter = () => { props.onMouseEnter() },
+ let onMouseEnter = () => { props.onMouseEnter() },
onMouseLeave = () => { props.onMouseLeave() }
return (
@@ -35,8 +34,10 @@ function PureStringOption( { value, onChange, ...props }) {
onMouseEnter = () => { props.onMouseEnter() },
onMouseLeave = () => { props.onMouseLeave() }
return (
+
+
)
}
@@ -61,6 +63,7 @@ function PureNumberOption( {value, onChange, ...props }) {
return (
+
)
}
}
@@ -154,16 +173,16 @@ const OptionTypes = {
"sequence of str": PureStringSequenceOption,
}
-export default class OptionMaster extends Component {
+class OptionMaster extends Component {
constructor(props, context) {
super(props, context)
this.state = {
- updateOptions: this.props.updateOptions,
option: this.props.option,
name: this.props.name,
mousefocus: false,
focus: false,
+ error: false,
}
if (props.option.choices) {
@@ -179,11 +198,17 @@ export default class OptionMaster extends Component {
}
componentWillReceiveProps(nextProps) {
- this.setState({ option: nextProps.option })
+ if (nextProps.option.value !== this.state.option.value){
+ this.setState({ error: true })
+ }
+ else{
+ this.setState({ option: nextProps.option, error: false })
+ }
}
onChange(e) {
- const { updateOptions, option, name } = this.state
+ const { option, name } = this.state
+ this.setState({ option: {...option, value: e.target.value}})
switch (option.type) {
case 'bool' :
updateOptions({[name]: !option.value})
@@ -201,7 +226,6 @@ export default class OptionMaster extends Component {
}
onMouseEnter() {
- console.log(this.state)
this.setState({ mousefocus: true })
}
@@ -210,7 +234,6 @@ export default class OptionMaster extends Component {
}
onFocus() {
- console.log(this.state)
this.setState({ focus: true })
}
@@ -220,7 +243,7 @@ export default class OptionMaster extends Component {
render() {
const { name, children } = this.props
- const { option, focus, mousefocus } = this.state
+ const { option, focus, mousefocus, error } = this.state
const WrappedComponent = this.WrappedComponent
return (
@@ -238,6 +261,7 @@ export default class OptionMaster extends Component {
onBlur={this.onBlur}
onMouseEnter={this.onMouseEnter}
onMouseLeave={this.onMouseLeave}
+ error={error}
/>
{(focus || mousefocus) && (
@@ -250,3 +274,10 @@ export default class OptionMaster extends Component {
)
}
}
+
+export default connect(
+ null,
+ {
+ updateOptions: updateOptions
+ }
+)(OptionMaster)
diff --git a/web/src/js/components/Modal/OptionModal.jsx b/web/src/js/components/Modal/OptionModal.jsx
index ec59fa29b..a4dd95d05 100644
--- a/web/src/js/components/Modal/OptionModal.jsx
+++ b/web/src/js/components/Modal/OptionModal.jsx
@@ -1,7 +1,6 @@
import React, { Component } from 'react'
import { connect } from 'react-redux'
import * as modalAction from '../../ducks/ui/modal'
-import { update as updateOptions } from '../../ducks/options'
import Option from './OptionMaster'
class PureOptionModal extends Component {
@@ -37,7 +36,6 @@ class PureOptionModal extends Component {
)
})
@@ -58,6 +56,5 @@ export default connect(
}),
{
hideModal: modalAction.hideModal,
- updateOptions: updateOptions,
}
)(PureOptionModal)
diff --git a/web/src/js/ducks/options.js b/web/src/js/ducks/options.js
index 39c2f3fc0..ed82d7f3c 100644
--- a/web/src/js/ducks/options.js
+++ b/web/src/js/ducks/options.js
@@ -4,6 +4,7 @@ export const RECEIVE = 'OPTIONS_RECEIVE'
export const UPDATE = 'OPTIONS_UPDATE'
export const REQUEST_UPDATE = 'REQUEST_UPDATE'
export const UNKNOWN_CMD = 'OPTIONS_UNKNOWN_CMD'
+export const ERROR = 'OPTIONS_ERROR'
const defaultState = {
@@ -21,12 +22,26 @@ export default function reducer(state = defaultState, action) {
...action.data,
}
+ case ERROR:
+ return {
+ ...state,
+ ...action.data,
+ }
+
default:
return state
}
}
export function update(options) {
- fetchApi.put('/options', options)
- return { type: REQUEST_UPDATE }
+ let error = ''
+ fetchApi.put('/options', options).then(
+ (response) => {
+ response.text().then(errorMsg => {
+ error = errorMsg
+ console.log(error)
+ })
+ }
+ )
+ return {type: ERROR, error}
}