diff options
Diffstat (limited to 'web/src/js/components/Modal')
-rw-r--r-- | web/src/js/components/Modal/OptionMaster.jsx | 65 | ||||
-rw-r--r-- | web/src/js/components/Modal/OptionModal.jsx | 20 |
2 files changed, 39 insertions, 46 deletions
diff --git a/web/src/js/components/Modal/OptionMaster.jsx b/web/src/js/components/Modal/OptionMaster.jsx index e16319fb..c25dda72 100644 --- a/web/src/js/components/Modal/OptionMaster.jsx +++ b/web/src/js/components/Modal/OptionMaster.jsx @@ -1,6 +1,4 @@ import PropTypes from 'prop-types' -import { connect } from 'react-redux' -import { update as updateOptions } from '../../ducks/options' PureBooleanOption.PropTypes = { value: PropTypes.bool.isRequired, @@ -9,16 +7,14 @@ PureBooleanOption.PropTypes = { function PureBooleanOption({ value, onChange, name, help}) { return ( - <div className="menu-entry"> <label> + { name } <input type="checkbox" checked={value} onChange={onChange} title={help} /> - { name } </label> - </div> ) } @@ -30,7 +26,6 @@ PureStringOption.PropTypes = { function PureStringOption( { value, onChange, name, help }) { let onKeyDown = (e) => {e.stopPropagation()} return ( - <div className="menu-entry"> <label> { name } <input type="text" @@ -40,7 +35,6 @@ function PureStringOption( { value, onChange, name, help }) { onKeyDown={onKeyDown} /> </label> - </div> ) } @@ -52,7 +46,6 @@ PureNumberOption.PropTypes = { function PureNumberOption( {value, onChange, name, help }) { let onKeyDown = (e) => {e.stopPropagation()} return ( - <div className="menu-entry"> <label> { name } <input type="number" @@ -62,7 +55,6 @@ function PureNumberOption( {value, onChange, name, help }) { onKeyDown={onKeyDown} /> </label> - </div> ) } @@ -73,16 +65,14 @@ PureChoicesOption.PropTypes = { function PureChoicesOption( { value, onChange, name, help, choices }) { return ( - <div className="menu-entry"> <label htmlFor=""> { name } <select name={name} onChange={onChange} title={help} selected={value}> - { choices.map(choice => ( - <option value={choice}> {choice} </option> + { choices.map((choice, index) => ( + <option key={index} value={choice}> {choice} </option> ))} </select> </label> - </div> ) } @@ -94,45 +84,36 @@ const OptionTypes = { "sequence of str": PureStringOption, } -Wrapper.displayName = 'OptionWrapper' - - -function Wrapper({option, options, updateOptions, ...props}) { - let optionObj = options[option], - WrappedComponent = null - if (optionObj.choices) { +export default function OptionMaster({option, name, updateOptions, ...props}) { + let WrappedComponent = null + if (option.choices) { WrappedComponent = PureChoicesOption } else { - WrappedComponent = OptionTypes[optionObj.type] + WrappedComponent = OptionTypes[option.type] } let onChange = (e) => { - switch (optionObj.type) { + switch (option.type) { case 'bool' : - updateOptions({[option]: !optionObj.value}) + updateOptions({[name]: !option.value}) break case 'int': - updateOptions({[option]: parseInt(e.target.value)}) + updateOptions({[name]: parseInt(e.target.value)}) break default: - updateOptions({[option]: e.target.value}) + updateOptions({[name]: e.target.value}) } } - return <WrappedComponent - children={props.children} - value={optionObj.value} - onChange={onChange} - name={option} - help={optionObj.help} - choices={optionObj.choices} - /> + return ( + <div className="menu-entry"> + <WrappedComponent + children={props.children} + value={option.value} + onChange={onChange} + name={name} + help={option.help} + choices={option.choices} + /> + </div> + ) } - -export default connect( - state => ({ - options: state.options, - }), - { - updateOptions, - } -)(Wrapper) diff --git a/web/src/js/components/Modal/OptionModal.jsx b/web/src/js/components/Modal/OptionModal.jsx index 582ac55f..ef3a224a 100644 --- a/web/src/js/components/Modal/OptionModal.jsx +++ b/web/src/js/components/Modal/OptionModal.jsx @@ -1,6 +1,7 @@ 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 { @@ -28,9 +29,17 @@ class PureOptionModal extends Component { <div className="modal-body"> { - Object.keys(options).sort().map((key) => ( - <Option option={key}/> - )) + Object.keys(options).sort() + .map((key, index) => { + let option = options[key]; + return ( + <Option + key={index} + name={key} + updateOptions={updateOptions} + option={option} + />) + }) } </div> @@ -46,5 +55,8 @@ export default connect( state => ({ options: state.options }), - { hideModal: modalAction.hideModal } + { + hideModal: modalAction.hideModal, + updateOptions: updateOptions, + } )(PureOptionModal) |