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