From 36286b60566501d35e7143d150d2ae8c150a98bd Mon Sep 17 00:00:00 2001 From: Grégoire Aubert Date: Mon, 13 Mar 2017 17:13:00 +0100 Subject: SONAR-8521 Improve size, duplication and coverage facets style (#1776) --- .../js/apps/projects/filters/CoverageFilter.js | 1 + .../js/apps/projects/filters/DuplicationsFilter.js | 1 + .../src/main/js/apps/projects/filters/Filter.js | 80 +++++++++++++--------- .../main/js/apps/projects/filters/IssuesFilter.js | 42 +++++------- .../main/js/apps/projects/filters/SizeFilter.js | 1 + 5 files changed, 66 insertions(+), 59 deletions(-) (limited to 'server/sonar-web/src') diff --git a/server/sonar-web/src/main/js/apps/projects/filters/CoverageFilter.js b/server/sonar-web/src/main/js/apps/projects/filters/CoverageFilter.js index 560af1eba08..8789a3aef5e 100644 --- a/server/sonar-web/src/main/js/apps/projects/filters/CoverageFilter.js +++ b/server/sonar-web/src/main/js/apps/projects/filters/CoverageFilter.js @@ -74,6 +74,7 @@ export default class CoverageFilter extends React.PureComponent { renderName={this.renderName} renderOption={this.renderOption} renderSort={this.renderSort} + highlightUnder={1} getFacetValueForOption={this.getFacetValueForOption} query={this.props.query} isFavorite={this.props.isFavorite} diff --git a/server/sonar-web/src/main/js/apps/projects/filters/DuplicationsFilter.js b/server/sonar-web/src/main/js/apps/projects/filters/DuplicationsFilter.js index ae1acc160ab..94e47088095 100644 --- a/server/sonar-web/src/main/js/apps/projects/filters/DuplicationsFilter.js +++ b/server/sonar-web/src/main/js/apps/projects/filters/DuplicationsFilter.js @@ -76,6 +76,7 @@ export default class DuplicationsFilter extends React.PureComponent { renderName={this.renderName} renderOption={this.renderOption} renderSort={this.renderSort} + highlightUnder={1} getFacetValueForOption={this.getFacetValueForOption} query={this.props.query} isFavorite={this.props.isFavorite} diff --git a/server/sonar-web/src/main/js/apps/projects/filters/Filter.js b/server/sonar-web/src/main/js/apps/projects/filters/Filter.js index 0c99e74dfff..7e407cb23c2 100644 --- a/server/sonar-web/src/main/js/apps/projects/filters/Filter.js +++ b/server/sonar-web/src/main/js/apps/projects/filters/Filter.js @@ -40,12 +40,11 @@ export default class Filter extends React.PureComponent { getFacetValueForOption: React.PropTypes.func, halfWidth: React.PropTypes.bool, - highlightUnder: React.PropTypes.func + highlightUnder: React.PropTypes.number }; static defaultProps = { - halfWidth: false, - highlightUnder: () => false + halfWidth: false }; isSelected (option) { @@ -53,6 +52,12 @@ export default class Filter extends React.PureComponent { return Array.isArray(value) ? value.includes(option) : option === value; } + highlightUnder (option) { + return this.props.highlightUnder != null && + option !== null && + option > this.props.highlightUnder; + } + getPath (option) { const { property, value } = this.props; let urlOption; @@ -71,10 +76,10 @@ export default class Filter extends React.PureComponent { renderHeader () { return ( -
- {this.props.renderName()} - {this.props.renderSort && this.props.renderSort()} -
+
+ {this.props.renderName()} + {this.props.renderSort && this.props.renderSort()} +
); } @@ -84,37 +89,46 @@ export default class Filter extends React.PureComponent { } return ( -
-
-
+
+
+
); } renderOption (option) { const { facet, getFacetValueForOption, value } = this.props; - const className = classNames('facet', 'search-navigator-facet', 'projects-facet', { - 'active': this.isSelected(option), - 'search-navigator-facet-half': this.props.halfWidth, - 'search-navigator-facet-highlight-under': this.props.highlightUnder(option) - }, this.props.optionClassName); + const className = classNames( + 'facet', + 'search-navigator-facet', + 'projects-facet', + { + 'active': this.isSelected(option), + 'search-navigator-facet-half': this.props.halfWidth, + 'search-navigator-facet-highlight-under': this.highlightUnder(option) + }, + this.props.optionClassName + ); const path = this.getPath(option); + const facetValue = facet && getFacetValueForOption + ? getFacetValueForOption(facet, option) + : null; - const facetValue = (facet && getFacetValueForOption) ? getFacetValueForOption(facet, option) : null; + const isUnderSelectedOption = this.highlightUnder(value) && option > value; return ( - - - {this.props.renderOption(option, this.isSelected(option), value)} - - {facetValue != null && ( - - {formatMeasure(facetValue, 'SHORT_INT')} - {this.renderOptionBar(facetValue)} - - )} - + + + {this.props.renderOption(option, this.isSelected(option) || isUnderSelectedOption)} + + {facetValue != null && + + {formatMeasure(facetValue, 'SHORT_INT')} + {this.renderOptionBar(facetValue)} + } + ); } @@ -148,11 +162,11 @@ export default class Filter extends React.PureComponent { render () { return ( -
- {this.renderHeader()} - {this.renderOptions()} - {this.renderFooter()} -
+
+ {this.renderHeader()} + {this.renderOptions()} + {this.renderFooter()} +
); } } diff --git a/server/sonar-web/src/main/js/apps/projects/filters/IssuesFilter.js b/server/sonar-web/src/main/js/apps/projects/filters/IssuesFilter.js index 7d5e6c9ad26..c39cf006769 100644 --- a/server/sonar-web/src/main/js/apps/projects/filters/IssuesFilter.js +++ b/server/sonar-web/src/main/js/apps/projects/filters/IssuesFilter.js @@ -31,18 +31,12 @@ export default class IssuesFilter extends React.PureComponent { organization: React.PropTypes.object }; - renderOption = (option, selected, value) => { - const isUnderSelectedOption = this.highlightUnder(value) && option > value; + renderOption = (option, selected) => { return ( - - - {option > 1 && option < 5 && ( - and worse - )} - + + + {option > 1 && option < 5 && and worse} + ); }; @@ -56,10 +50,6 @@ export default class IssuesFilter extends React.PureComponent { ); }; - highlightUnder (option) { - return option !== null && option > 1; - } - getFacetValueForOption = (facet, option) => { return facet[option]; }; @@ -70,17 +60,17 @@ export default class IssuesFilter extends React.PureComponent { render () { return ( - + ); } } diff --git a/server/sonar-web/src/main/js/apps/projects/filters/SizeFilter.js b/server/sonar-web/src/main/js/apps/projects/filters/SizeFilter.js index be13a07fd13..9b920f50c22 100644 --- a/server/sonar-web/src/main/js/apps/projects/filters/SizeFilter.js +++ b/server/sonar-web/src/main/js/apps/projects/filters/SizeFilter.js @@ -79,6 +79,7 @@ export default class SizeFilter extends React.PureComponent { renderName={this.renderName} renderOption={this.renderOption} renderSort={this.renderSort} + highlightUnder={1} getFacetValueForOption={this.getFacetValueForOption} query={this.props.query} isFavorite={this.props.isFavorite} -- cgit v1.2.3