mon-entreprise/containers/Explorer.js

63 lines
1.5 KiB
JavaScript
Raw Normal View History

2016-06-29 10:27:04 +00:00
import React from 'react'
import {selectVariables, selectTagStats} from '../selectors'
import {connect} from 'react-redux'
import {bindActionCreators} from 'redux'
import * as actions from '../actions'
const Variable = ({data: {variable, tags}}) => <li className="variable">
<h3>{variable}</h3>
<ul>{Object.keys(tags).map(name => <li key={name}>
{name + ': ' + tags[name]}
</li>)}</ul>
</li>
class Explorer extends React.Component {
2016-06-29 10:27:04 +00:00
render() {
let {tags, actions, variables} = this.props
2016-06-29 16:57:56 +00:00
return (
<div>
<h1>Les prélèvements sociaux sur les salaires</h1>
<ul id="tags">
{tags.map(tag =>
<TagSelect selectTag={actions.selectTag} key={tag.name} tag={tag} />
)}
</ul>
<ul id="variables">
{variables.map((v, i) => <Variable key={i} data={v}/>)}
</ul>
</div>
2016-06-29 16:57:56 +00:00
)
2016-06-29 10:27:04 +00:00
}
}
2016-06-30 10:16:47 +00:00
class TagSelect extends React.Component {
render(){
let {tag: {name, choices, number}, selectTag} = this.props
2016-06-30 10:16:47 +00:00
return (<li>
<span className="name">{`${name} (${number} variables)`}</span>
<ul className="choices">
{[...choices].map(c =>
<li key={c} onClick={() => selectTag(name, c)}>
2016-06-30 10:16:47 +00:00
{c}
</li>
)}
2016-06-30 10:16:47 +00:00
</ul>
</li>)
}
}
const mapStateToProps = state => (
{
variables: selectVariables(state),
tags: selectTagStats(state)
}
)
const actionsToProps = dispatch => ({
actions: bindActionCreators(actions, dispatch),
})
const VariableExplorer = connect(mapStateToProps, actionsToProps)(Explorer)
export default VariableExplorer