diff options
author | Grégoire Aubert <gregoire.aubert@sonarsource.com> | 2017-08-11 14:08:21 +0200 |
---|---|---|
committer | Grégoire Aubert <gregoire.aubert@sonarsource.com> | 2017-08-14 11:44:44 +0200 |
commit | d1feeda71f72903179446ba1d3c170414bd1ff2b (patch) | |
tree | 83a59235ea12d4b6af6ecf70abc34a2caca73f3b /server/sonar-web/src | |
parent | 17d12ea757e29e084ab61e4071e80a249e45e225 (diff) | |
download | sonarqube-d1feeda71f72903179446ba1d3c170414bd1ff2b.tar.gz sonarqube-d1feeda71f72903179446ba1d3c170414bd1ff2b.zip |
SONAR-9608 Close measures facets by default
Diffstat (limited to 'server/sonar-web/src')
4 files changed, 31 insertions, 15 deletions
diff --git a/server/sonar-web/src/main/js/apps/component-measures/sidebar/Sidebar.js b/server/sonar-web/src/main/js/apps/component-measures/sidebar/Sidebar.js index 441491a518f..f74f751656d 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/sidebar/Sidebar.js +++ b/server/sonar-web/src/main/js/apps/component-measures/sidebar/Sidebar.js @@ -21,7 +21,7 @@ import React from 'react'; import ProjectOverviewFacet from './ProjectOverviewFacet'; import DomainFacet from './DomainFacet'; -import { groupByDomains, PROJECT_OVERVEW } from '../utils'; +import { groupByDomains, KNOWN_DOMAINS, PROJECT_OVERVEW } from '../utils'; import type { MeasureEnhanced } from '../../../components/measure/types'; import type { Query } from '../types'; @@ -32,7 +32,7 @@ type Props = {| |}; type State = {| - closedFacets: { [string]: boolean } + openFacets: { [string]: boolean } |}; export default class Sidebar extends React.PureComponent { @@ -41,12 +41,29 @@ export default class Sidebar extends React.PureComponent { constructor(props: Props) { super(props); - this.state = { closedFacets: {} }; + this.state = { openFacets: this.getOpenFacets({}, props) }; } + componentWillReceiveProps(nextProps: Props) { + if (nextProps.selectedMetric !== this.props.selectedMetric) { + this.setState(state => this.getOpenFacets(state.openFacets, nextProps)); + } + } + + getOpenFacets = (openFacets: { [string]: boolean }, { measures, selectedMetric }: Props) => { + const newOpenFacets = { ...openFacets }; + const measure = measures.find(measure => measure.metric.key === selectedMetric); + if (measure && measure.metric && measure.metric.domain) { + newOpenFacets[measure.metric.domain] = true; + } else if (KNOWN_DOMAINS.includes(selectedMetric)) { + newOpenFacets[selectedMetric] = true; + } + return newOpenFacets; + }; + toggleFacet = (name: string) => { - this.setState(({ closedFacets }) => ({ - closedFacets: { ...closedFacets, [name]: !closedFacets[name] } + this.setState(({ openFacets }: State) => ({ + openFacets: { ...openFacets, [name]: !openFacets[name] } })); }; @@ -68,7 +85,7 @@ export default class Sidebar extends React.PureComponent { domain={domain} onChange={this.changeMetric} onToggle={this.toggleFacet} - open={!this.state.closedFacets[domain.name]} + open={this.state.openFacets[domain.name]} selected={this.props.selectedMetric} /> )} diff --git a/server/sonar-web/src/main/js/apps/component-measures/sidebar/__tests__/Sidebar-test.js b/server/sonar-web/src/main/js/apps/component-measures/sidebar/__tests__/Sidebar-test.js index aa993cfc71b..d03ce105879 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/sidebar/__tests__/Sidebar-test.js +++ b/server/sonar-web/src/main/js/apps/component-measures/sidebar/__tests__/Sidebar-test.js @@ -59,7 +59,7 @@ const MEASURES = [ const PROPS = { measures: MEASURES, - selectedMetric: 'foo', + selectedMetric: 'duplicated_lines_density', updateQuery: () => {} }; @@ -69,9 +69,9 @@ it('should display two facets', () => { it('should correctly toggle facets', () => { const wrapper = shallow(<Sidebar {...PROPS} />); - expect(wrapper.state('closedFacets').bugs).toBeUndefined(); + expect(wrapper.state('openFacets').bugs).toBeUndefined(); wrapper.instance().toggleFacet('bugs'); - expect(wrapper.state('closedFacets').bugs).toBeTruthy(); + expect(wrapper.state('openFacets').bugs).toBeTruthy(); wrapper.instance().toggleFacet('bugs'); - expect(wrapper.state('closedFacets').bugs).toBeFalsy(); + expect(wrapper.state('openFacets').bugs).toBeFalsy(); }); diff --git a/server/sonar-web/src/main/js/apps/component-measures/sidebar/__tests__/__snapshots__/Sidebar-test.js.snap b/server/sonar-web/src/main/js/apps/component-measures/sidebar/__tests__/__snapshots__/Sidebar-test.js.snap index 5e7477f09e1..96c4d1701a7 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/sidebar/__tests__/__snapshots__/Sidebar-test.js.snap +++ b/server/sonar-web/src/main/js/apps/component-measures/sidebar/__tests__/__snapshots__/Sidebar-test.js.snap @@ -6,7 +6,7 @@ exports[`should display two facets 1`] = ` > <ProjectOverviewFacet onChange={[Function]} - selected="foo" + selected="duplicated_lines_density" value="project_overview" /> <DomainFacet @@ -51,8 +51,7 @@ exports[`should display two facets 1`] = ` } onChange={[Function]} onToggle={[Function]} - open={true} - selected="foo" + selected="duplicated_lines_density" /> <DomainFacet domain={ @@ -81,7 +80,7 @@ exports[`should display two facets 1`] = ` onChange={[Function]} onToggle={[Function]} open={true} - selected="foo" + selected="duplicated_lines_density" /> </div> `; diff --git a/server/sonar-web/src/main/js/apps/component-measures/utils.js b/server/sonar-web/src/main/js/apps/component-measures/utils.js index 0a3da4859fd..a1cd1d3c2ac 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/utils.js +++ b/server/sonar-web/src/main/js/apps/component-measures/utils.js @@ -32,7 +32,7 @@ import type { MeasureEnhanced } from '../../components/measure/types'; export const PROJECT_OVERVEW = 'project_overview'; export const DEFAULT_VIEW = 'list'; export const DEFAULT_METRIC = PROJECT_OVERVEW; -const KNOWN_DOMAINS = [ +export const KNOWN_DOMAINS = [ 'Releasability', 'Reliability', 'Security', |