import { translate } from '../../../helpers/l10n';
import { getComponentUrl } from '../../../helpers/urls';
+const VIEW_METRICS = [
+ 'releasability_rating',
+ 'alert_status',
+ 'reliability_rating',
+ 'security_rating',
+ 'sqale_rating',
+ 'ncloc'
+];
+
const METRICS = [
'ncloc',
'code_smells',
return '/' + encodeURIComponent(componentKey);
}
-function expandRootDir ({ children, total, ...other }) {
- const rootDir = children.find(component => component.qualifier === 'DIR' && component.name === '/');
- if (rootDir) {
- return getChildren(rootDir.key, METRICS_WITH_COVERAGE).then(r => {
- const nextChildren = _.without([...children, ...r.components], rootDir);
- const nextTotal = total + r.components.length - /* root dir */ 1;
- return { children: nextChildren, total: nextTotal, ...other };
- });
- } else {
- return { children, total, ...other };
+function expandRootDir (metrics) {
+ return function ({ children, total, ...other }) {
+ const rootDir = children.find(component => component.qualifier === 'DIR' && component.name === '/');
+ if (rootDir) {
+ return getChildren(rootDir.key, metrics).then(r => {
+ const nextChildren = _.without([...children, ...r.components], rootDir);
+ const nextTotal = total + r.components.length - /* root dir */ 1;
+ return { children: nextChildren, total: nextTotal, ...other };
+ });
+ } else {
+ return { children, total, ...other };
+ }
}
}
});
}
-function retrieveComponentBase (componentKey, candidate) {
+function retrieveComponentBase (componentKey, candidate, metrics) {
return candidate ?
Promise.resolve(candidate) :
- getComponent(componentKey, METRICS_WITH_COVERAGE);
+ getComponent(componentKey, metrics);
}
-function retrieveComponentChildren (componentKey, candidate) {
+function retrieveComponentChildren (componentKey, candidate, metrics) {
return candidate && candidate.children ?
Promise.resolve({ children: candidate.children, total: candidate.total }) :
- getChildren(componentKey, METRICS_WITH_COVERAGE, { ps: PAGE_SIZE }).then(prepareChildren).then(expandRootDir);
+ getChildren(componentKey, metrics, { ps: PAGE_SIZE }).then(prepareChildren).then(expandRootDir(metrics));
}
function retrieveComponentBreadcrumbs (componentKey, candidate) {
getBreadcrumbs({ key: componentKey }).then(skipRootDir);
}
-function retrieveComponent (componentKey, bucket) {
+function retrieveComponent (componentKey, bucket, isView) {
const candidate = _.findWhere(bucket, { key: componentKey });
+ const metrics = isView ? VIEW_METRICS : METRICS_WITH_COVERAGE;
return Promise.all([
- retrieveComponentBase(componentKey, candidate),
- retrieveComponentChildren(componentKey, candidate),
+ retrieveComponentBase(componentKey, candidate, metrics),
+ retrieveComponentChildren(componentKey, candidate, metrics),
retrieveComponentBreadcrumbs(componentKey, candidate)
]);
}
}
}
-export function initComponent (componentKey, breadcrumbs) {
+export function initComponent (component, breadcrumbs) {
return dispatch => {
+ const componentKey = component.key;
+ const isView = component.qualifier === 'VW' || component.qualifier === 'SVW';
+ const metrics = isView ? VIEW_METRICS : METRICS_WITH_COVERAGE;
dispatch(startFetching());
- return getComponent(componentKey, METRICS_WITH_COVERAGE)
+ return getComponent(componentKey, metrics)
.then(component => dispatch(initComponentAction(component, breadcrumbs)))
.then(() => dispatch(replacePath(getPath(componentKey))))
.then(() => dispatch(stopFetching()));
export function browse (componentKey) {
return (dispatch, getState) => {
- const { bucket } = getState();
+ const { bucket, current } = getState();
dispatch(startFetching());
- return retrieveComponent(componentKey, bucket)
+ return retrieveComponent(componentKey, bucket, current.isView)
.then(([component, children, breadcrumbs]) => {
if (component.refKey) {
window.location = getComponentUrl(component.refKey);
componentDidMount () {
const { dispatch, component, routing } = this.props;
const selectedKey = (routing.path && decodeURIComponent(routing.path.substr(1))) || component.key;
- dispatch(initComponent(component.key, component.breadcrumbs))
+ dispatch(initComponent(component, component.breadcrumbs))
.then(() => dispatch(browse(selectedKey)));
}
}
}
- /* eslint object-shorthand: 0 */
+ const columns = isView ? [
+ { metric: 'releasability_rating', type: 'RATING' },
+ { metric: 'reliability_rating', type: 'RATING' },
+ { metric: 'security_rating', type: 'RATING' },
+ { metric: 'sqale_rating', type: 'RATING' },
+ { metric: 'ncloc', type: 'SHORT_INT' },
+ ] : [
+ { metric: 'ncloc', type: 'SHORT_INT' },
+ { metric: 'bugs', type: 'SHORT_INT' },
+ { metric: 'vulnerabilities', type: 'SHORT_INT' },
+ { metric: 'code_smells', type: 'SHORT_INT' },
+ { metric: coverageMetric, type: 'PERCENT' },
+ { metric: 'duplicated_lines_density', type: 'PERCENT' }
+ ];
+
return (
<tr className={classNames({ selected })}>
<td className="thin nowrap">
</span>
</td>
<td className="code-name-cell">
- {isView && (
- <ComponentQualityGate
- component={component}/>
- )}
<ComponentName
component={component}
previous={previous}
onBrowse={onBrowse}/>
</td>
- <td className="thin nowrap text-right">
- <div className="code-components-cell">
- <ComponentMeasure
- component={component}
- metricKey="ncloc"
- metricType="SHORT_INT"/>
- </div>
- </td>
- <td className="thin nowrap text-right">
- <div className="code-components-cell">
- <ComponentMeasure
- component={component}
- metricKey="bugs"
- metricType="SHORT_INT"/>
- </div>
- </td>
- <td className="thin nowrap text-right">
- <div className="code-components-cell">
- <ComponentMeasure
- component={component}
- metricKey="vulnerabilities"
- metricType="SHORT_INT"/>
- </div>
- </td>
- <td className="thin nowrap text-right">
- <div className="code-components-cell">
- <ComponentMeasure
- component={component}
- metricKey="code_smells"
- metricType="SHORT_INT"/>
- </div>
- </td>
- <td className="thin nowrap text-right">
- <div className="code-components-cell">
- <ComponentMeasure
- component={component}
- metricKey={coverageMetric}
- metricType="PERCENT"/>
- </div>
- </td>
- <td className="thin nowrap text-right">
- <div className="code-components-cell">
- <ComponentMeasure
- component={component}
- metricKey="duplicated_lines_density"
- metricType="PERCENT"/>
- </div>
- </td>
+
+ {columns.map(column => (
+ <td key={column.metric} className="thin nowrap text-right">
+ <div className="code-components-cell">
+ <ComponentMeasure
+ component={component}
+ metricKey={column.metric}
+ metricType={column.type}/>
+ </div>
+ </td>
+ ))}
</tr>
);
}
*/
import _ from 'underscore';
import React from 'react';
-
-import { formatMeasure } from '../../../helpers/measures';
+import Measure from '../../component-measures/components/Measure';
const ComponentMeasure = ({ component, metricKey, metricType }) => {
- const measure = _.findWhere(component.measures, { metric: metricKey });
+ const isProject = component.qualifier === 'TRK';
+ const isReleasability = metricKey === 'releasability_rating';
+
+ const finalMetricKey = (isProject && isReleasability) ? 'alert_status' : metricKey;
+ const finalMetricType = (isProject && isReleasability) ? 'LEVEL' : metricType;
+
+ const measure = _.findWhere(component.measures, { metric: finalMetricKey });
+
+ if (!measure) {
+ return <span/>;
+ }
+
return (
- <span>
- {measure ? formatMeasure(measure.value, metricType) : ''}
- </span>
+ <Measure measure={measure} metric={{ key: finalMetricKey, type: finalMetricType }}/>
);
};
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import React from 'react';
-
+import { connect } from 'react-redux';
import { translate } from '../../../helpers/l10n';
-const ComponentsHeader = ({ baseComponent }) => (
- <thead>
- <tr>
- <th className="thin nowrap"> </th>
- <th> </th>
- <th className="thin nowrap text-right code-components-cell">
- {baseComponent && translate('metric.ncloc.name')}
- </th>
- <th className="thin nowrap text-right code-components-cell">
- {baseComponent && translate('metric.bugs.name')}
- </th>
- <th className="thin nowrap text-right code-components-cell">
- {baseComponent && translate('metric.vulnerabilities.name')}
- </th>
- <th className="thin nowrap text-right code-components-cell">
- {baseComponent && translate('metric.code_smells.name')}
- </th>
- <th className="thin nowrap text-right code-components-cell">
- {baseComponent && translate('metric.coverage.name')}
- </th>
- <th className="thin nowrap text-right code-components-cell">
- {baseComponent && translate('metric.duplicated_lines_density.short_name')}
- </th>
- </tr>
- </thead>
-);
+const ComponentsHeader = ({ baseComponent, isView }) => {
+ const columns = isView ? [
+ translate('metric_domain.Releasability'),
+ translate('metric_domain.Reliability'),
+ translate('metric_domain.Security'),
+ translate('metric_domain.Maintainability'),
+ translate('metric', 'ncloc', 'name')
+ ] : [
+ translate('metric', 'ncloc', 'name'),
+ translate('metric', 'bugs', 'name'),
+ translate('metric', 'vulnerabilities', 'name'),
+ translate('metric', 'code_smells', 'name'),
+ translate('metric', 'coverage', 'name'),
+ translate('metric', 'duplicated_lines_density', 'short_name')
+ ];
+
+ return (
+ <thead>
+ <tr>
+ <th className="thin nowrap"> </th>
+ <th> </th>
+ {columns.map(column => (
+ <th key={column} className="thin nowrap text-right code-components-cell">
+ {baseComponent && column}
+ </th>
+ ))}
+ </tr>
+ </thead>
+ );
+};
+
+function mapStateToProps (state) {
+ return {
+ isView: state.current.isView
+ };
+}
+
+export default connect(mapStateToProps)(ComponentsHeader);
-export default ComponentsHeader;
import sinonChai from 'sinon-chai';
import { shallow } from 'enzyme';
import React from 'react';
-import TestUtils from 'react-addons-test-utils';
import Breadcrumb from '../../../src/main/js/apps/code/components/Breadcrumb';
import Breadcrumbs from '../../../src/main/js/apps/code/components/Breadcrumbs';
<ComponentMeasure
component={exampleComponent}
metricKey="ncloc"
- metricType="SHORT_INT"/>);
+ metricType="SHORT_INT"/>
+ ).find('Measure');
- expect(output.text())
- .to.equal('9.8k');
+ expect(output.length).to.equal(1);
+ expect(output.prop('measure')).to.deep.equal({ metric: 'ncloc', value: 9757 });
+ expect(output.prop('metric')).to.deep.equal({ key: 'ncloc', type: 'SHORT_INT' });
});
it('should not render measure', () => {
metric_domain.Integration Tests=Integration Tests
metric_domain.Issues=Issues
metric_domain.Maintainability=Maintainability
+metric_domain.Releasability=Releasability
metric_domain.Reliability=Reliability
metric_domain.Rules=Rules
metric_domain.SCM=SCM