diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2015-12-16 15:23:40 +0100 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2015-12-16 15:23:40 +0100 |
commit | f7c1c7a08a7fecdfb339493830ecd122bfd481ab (patch) | |
tree | 19c67712ed1d17822bf8bb6d58e36e117c204599 /server/sonar-web/src/main/js/apps | |
parent | 5af187a6a0bda4f14de5d8ba5c6088c3a00d3e4e (diff) | |
download | sonarqube-f7c1c7a08a7fecdfb339493830ecd122bfd481ab.tar.gz sonarqube-f7c1c7a08a7fecdfb339493830ecd122bfd481ab.zip |
SONAR-7143 display different types of coverage
Diffstat (limited to 'server/sonar-web/src/main/js/apps')
5 files changed, 53 insertions, 14 deletions
diff --git a/server/sonar-web/src/main/js/apps/code/actions/index.js b/server/sonar-web/src/main/js/apps/code/actions/index.js index 9e9df67cfea..135c77758ab 100644 --- a/server/sonar-web/src/main/js/apps/code/actions/index.js +++ b/server/sonar-web/src/main/js/apps/code/actions/index.js @@ -7,10 +7,14 @@ const METRICS = [ 'ncloc', 'sqale_index', 'violations', - // TODO handle other types of coverage - 'coverage', 'duplicated_lines_density' ]; +const METRICS_WITH_COVERAGE = [ + ...METRICS, + 'coverage', + 'it_coverage', + 'overall_coverage' +]; export const INIT = 'INIT'; @@ -44,18 +48,22 @@ export function showSource (component) { } -function fetchChildren (dispatch, baseComponent) { +function fetchChildren (dispatch, getState, baseComponent) { dispatch(requestComponents(baseComponent)); - return getChildren(baseComponent.key, METRICS) + + const { coverageMetric } = getState(); + const metrics = [...METRICS, coverageMetric]; + + return getChildren(baseComponent.key, metrics) .then(components => _.sortBy(components, 'name')) .then(components => dispatch(receiveComponents(baseComponent, components))); } export function initComponent (baseComponent) { - return dispatch => { - return getComponent(baseComponent.key, METRICS) - .then(component => fetchChildren(dispatch, component)); + return (dispatch, getState) => { + return getComponent(baseComponent.key, METRICS_WITH_COVERAGE) + .then(component => fetchChildren(dispatch, getState, component)); }; } @@ -64,7 +72,7 @@ export function fetchComponents (baseComponent) { return (dispatch, getState) => { const { fetching } = getState(); if (!fetching) { - return fetchChildren(dispatch, baseComponent); + return fetchChildren(dispatch, getState, baseComponent); } }; } diff --git a/server/sonar-web/src/main/js/apps/code/components/Code.js b/server/sonar-web/src/main/js/apps/code/components/Code.js index d894ab8c952..4c5b2785033 100644 --- a/server/sonar-web/src/main/js/apps/code/components/Code.js +++ b/server/sonar-web/src/main/js/apps/code/components/Code.js @@ -36,7 +36,7 @@ class Code extends Component { } render () { - const { fetching, baseComponent, components, breadcrumbs, sourceViewer } = this.props; + const { fetching, baseComponent, components, breadcrumbs, sourceViewer, coverageMetric } = this.props; const shouldShowBreadcrumbs = Array.isArray(breadcrumbs) && breadcrumbs.length > 1; const shouldShowComponents = !sourceViewer && components; const shouldShowSourceViewer = sourceViewer; @@ -65,6 +65,7 @@ class Code extends Component { <Components baseComponent={baseComponent} components={components} + coverageMetric={coverageMetric} onBrowse={this.handleBrowse.bind(this)}/> </div> )} diff --git a/server/sonar-web/src/main/js/apps/code/components/Component.js b/server/sonar-web/src/main/js/apps/code/components/Component.js index e319d9ef826..00a752cb591 100644 --- a/server/sonar-web/src/main/js/apps/code/components/Component.js +++ b/server/sonar-web/src/main/js/apps/code/components/Component.js @@ -5,7 +5,7 @@ import ComponentMeasure from './ComponentMeasure'; import ComponentDetach from './ComponentDetach'; -const Component = ({ component, onBrowse }) => ( +const Component = ({ component, coverageMetric, onBrowse }) => ( <tr> <td className="thin nowrap"> <span className="spacer-right"> @@ -45,7 +45,7 @@ const Component = ({ component, onBrowse }) => ( <div className="code-components-cell"> <ComponentMeasure component={component} - metricKey="coverage" + metricKey={coverageMetric} metricType="PERCENT"/> </div> </td> diff --git a/server/sonar-web/src/main/js/apps/code/components/Components.js b/server/sonar-web/src/main/js/apps/code/components/Components.js index 1167e319296..79a83c3e51a 100644 --- a/server/sonar-web/src/main/js/apps/code/components/Components.js +++ b/server/sonar-web/src/main/js/apps/code/components/Components.js @@ -4,7 +4,7 @@ import Component from './Component'; import ComponentsEmpty from './ComponentsEmpty'; -const Components = ({ baseComponent, components, onBrowse }) => ( +const Components = ({ baseComponent, components, coverageMetric, onBrowse }) => ( <table className="data zebra"> <thead> <tr> @@ -18,7 +18,9 @@ const Components = ({ baseComponent, components, onBrowse }) => ( </tr> </thead> <tbody> - <Component component={baseComponent}/> + <Component + component={baseComponent} + coverageMetric={coverageMetric}/> <tr className="blank"> <td colSpan="7"> </td> </tr> @@ -29,6 +31,7 @@ const Components = ({ baseComponent, components, onBrowse }) => ( <Component key={component.key} component={component} + coverageMetric={coverageMetric} onBrowse={onBrowse}/> )) ) : ( diff --git a/server/sonar-web/src/main/js/apps/code/reducers/index.js b/server/sonar-web/src/main/js/apps/code/reducers/index.js index d75ca950409..3a86e706e8d 100644 --- a/server/sonar-web/src/main/js/apps/code/reducers/index.js +++ b/server/sonar-web/src/main/js/apps/code/reducers/index.js @@ -1,3 +1,4 @@ +import _ from 'underscore'; import { combineReducers } from 'redux'; import { BROWSE, RECEIVE_COMPONENTS, SHOW_SOURCE } from '../actions'; @@ -70,12 +71,38 @@ export function sourceViewer (state = null, action) { } +function selectCoverageMetric (component) { + const coverage = _.findWhere(component.msr, { key: 'coverage' }); + const itCoverage = _.findWhere(component.msr, { key: 'it_coverage' }); + const overallCoverage = _.findWhere(component.msr, { key: 'overall_coverage' }); + + if (coverage != null && itCoverage != null && overallCoverage != null) { + return 'overall_coverage'; + } else if (coverage != null) { + return 'coverage'; + } else { + return 'it_coverage'; + } +} + + +export function coverageMetric (state = null, action) { + switch (action.type) { + case BROWSE: + return state !== null ? state : selectCoverageMetric(action.baseComponent); + default: + return state; + } +} + + const rootReducer = combineReducers({ fetching, baseComponent, components, breadcrumbs, - sourceViewer + sourceViewer, + coverageMetric }); |