From ddbc9bdf8275557a8ff9e139d0d47477d262eb20 Mon Sep 17 00:00:00 2001 From: Mael Thomas Date: Mon, 4 Jul 2016 18:34:18 +0200 Subject: [PATCH] =?UTF-8?q?Affichage=20des=20tags=20s=C3=A9lectionn=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/TagNavigation.js | 60 +++++++++++++++++++++++++++++++++++++ containers/App.css | 23 ++++++++++---- containers/Explorer.js | 35 ++++------------------ selectors.js | 16 ++++++---- 4 files changed, 92 insertions(+), 42 deletions(-) create mode 100644 components/TagNavigation.js diff --git a/components/TagNavigation.js b/components/TagNavigation.js new file mode 100644 index 000000000..8b329a803 --- /dev/null +++ b/components/TagNavigation.js @@ -0,0 +1,60 @@ +import React from 'react' +import {connect} from 'react-redux' +import * as actions from '../actions' +import {bindActionCreators} from 'redux' +import {getSelectedTags, getTagsToSelect} from '../selectors' + + +export default class TagNavigation extends React.Component { + render(){ + let {tagsToSelect, selectedTags, actions: {selectTag}} = this.props + return ( +
+ + + +
+ ) + } +} + +class Tag extends React.Component { + render(){ + let {tag: {name, choices, number}, selectTag} = this.props + return (
  • + {`${name} (${number} variables)`} + +
  • ) + } +} + + + + +const mapStateToProps = state => ( + { + selectedTags: state.selectedTags, + tagsToSelect: getTagsToSelect(state) + } +) + +const actionsToProps = dispatch => ({ + actions: bindActionCreators(actions, dispatch) +}) + +export default connect(mapStateToProps, actionsToProps)(TagNavigation) diff --git a/containers/App.css b/containers/App.css index 1223f8156..173c93fb9 100644 --- a/containers/App.css +++ b/containers/App.css @@ -15,7 +15,11 @@ ul { margin: 0; } -#tags { +li { + margin: 0; +} + +#tag-navigation { text-transform: capitalize; font-size: 140%; font-weight: 300; @@ -25,30 +29,37 @@ ul { display: inline-block; } -#tags li { - margin-top: 1em; +#to-select > li { + margin-bottom: 1.5em; } .choices { - + margin-top: .6em; } .choices li { font-size: 75%; font-weight: 400; display: inline-block; text-align: right; - margin-left: 1em; + margin-right: 1em; background: #16a085; color: white; - padding: .05em .5em; + padding: .05em .6em; cursor: pointer; border-radius: .1em } +#selected { + border-bottom: 1px solid #ccc; + padding-bottom: .6em; + margin-bottom: 2em; +} + #variables { width: 70%; display: inline-block; padding: 3%; + position: absolute; } .variable { diff --git a/containers/Explorer.js b/containers/Explorer.js index 0447083d5..bf7c804b1 100644 --- a/containers/Explorer.js +++ b/containers/Explorer.js @@ -1,8 +1,7 @@ import React from 'react' -import {selectVariables, selectTagStats} from '../selectors' import {connect} from 'react-redux' -import {bindActionCreators} from 'redux' -import * as actions from '../actions' +import {getVariables} from '../selectors' +import TagNavigation from '../components/TagNavigation' const Variable = ({data: {variable, tags}}) =>
  • {variable}

    @@ -17,11 +16,7 @@ class Explorer extends React.Component { return (

    Les prélèvements sociaux sur les salaires

    -
      - {tags.map(tag => - - )} -
    +
      {variables.map((v, i) => )}
    @@ -30,33 +25,13 @@ class Explorer extends React.Component { } } -class TagSelect extends React.Component { - render(){ - let {tag: {name, choices, number}, selectTag} = this.props - return (
  • - {`${name} (${number} variables)`} - -
  • ) - } -} const mapStateToProps = state => ( { - variables: selectVariables(state), - tags: selectTagStats(state) + variables: getVariables(state) } ) -const actionsToProps = dispatch => ({ - actions: bindActionCreators(actions, dispatch), -}) - -const VariableExplorer = connect(mapStateToProps, actionsToProps)(Explorer) +const VariableExplorer = connect(mapStateToProps)(Explorer) export default VariableExplorer diff --git a/selectors.js b/selectors.js index 14f050755..2f8f8a61f 100644 --- a/selectors.js +++ b/selectors.js @@ -20,7 +20,7 @@ const unorderedTagStats = finalVariables => .sort((a, b) => b.number - a.number) -export const selectVariables = createSelector( +export const getVariables = createSelector( [state => state.selectedTags], tags => finalVariables.filter(variable => @@ -29,9 +29,13 @@ export const selectVariables = createSelector( ) ) -export const selectTagStats = createSelector( - [selectVariables], - variables => { - return tagStats(unorderedTagStats(variables)) - } +const getTagStats = createSelector( + [getVariables], + variables => tagStats(unorderedTagStats(variables)) +) + +export const getTagsToSelect = createSelector( + [getTagStats, state => state.selectedTags], + (availableTags, selectedTags) => + availableTags.filter(t => !selectedTags.find(([name]) => t.name === name)) )