import React, { Component } from "react"
import { connect } from "react-redux"
import * as modalAction from "../../ducks/ui/modal"
import Option from "./Option"
import _ from "lodash"
function PureOptionHelp({help}){
return
{help}
;
}
const OptionHelp = connect((state, {name}) => ({
help: state.options[name].help,
}))(PureOptionHelp);
function PureOptionError({error}){
if(!error) return null;
return {error}
;
}
const OptionError = connect((state, {name}) => ({
error: state.ui.optionsEditor[name] && state.ui.optionsEditor[name].error
}))(PureOptionError);
export function PureOptionDefault({value, defaultVal}){
if( value === defaultVal ) {
return null
} else {
if (typeof(defaultVal) === 'boolean') {
defaultVal = defaultVal ? 'true' : 'false'
} else if (Array.isArray(defaultVal)){
if (_.isEmpty(_.compact(value)) && // filter the empty string in array
_.isEmpty(defaultVal)){
return null
}
defaultVal = '[ ]'
} else if (defaultVal === ''){
defaultVal = '\"\"'
} else if (defaultVal === null){
defaultVal = 'null'
}
return Default: {defaultVal}
}
}
const OptionDefault = connect((state, {name}) => ({
value: state.options[name].value,
defaultVal: state.options[name].default
}))(PureOptionDefault)
class PureOptionModal extends Component {
constructor(props, context) {
super(props, context)
this.state = { title: 'Options' }
}
render() {
const { hideModal, options } = this.props
const { title } = this.state
return (
{
hideModal()
}}>
{ title }
{
options.map(name =>
)
}
)
}
}
export default connect(
state => ({
options: Object.keys(state.options).sort()
}),
{
hideModal: modalAction.hideModal,
}
)(PureOptionModal)