}
export function getChildren (componentKey, metrics = []) {
- const url = baseUrl + '/api/resources/index';
- const data = { resource: componentKey, metrics: metrics.join(','), depth: 1 };
- return getJSON(url, data);
+ const url = baseUrl + '/api/measures/component_tree';
+ const data = {
+ baseComponentKey: componentKey,
+ metricKeys: metrics.join(','),
+ strategy: 'children'
+ };
+ return getJSON(url, data).then(r => r.components);
}
-export function getFiles (componentKey, metrics = []) {
- // due to the limitation of the WS we can not ask qualifiers=FIL,
- // in this case the WS does not return measures
- // so the filtering by a qualifier is done manually
-
- const url = baseUrl + '/api/resources/index';
- const data = { resource: componentKey, metrics: metrics.join(','), depth: -1 };
- return getJSON(url, data).then(r => {
- return r.filter(component => component.qualifier === 'FIL');
+export function getFiles (componentKey, metrics = [], additional = {}) {
+ const url = baseUrl + '/api/measures/component_tree';
+ const data = Object.assign({}, additional, {
+ baseComponentKey: componentKey,
+ metricKeys: metrics.join(','),
+ strategy: 'leaves'
});
+ return getJSON(url, data).then(r => r.components);
}
export function getComponent (componentKey, metrics = []) {
- const url = baseUrl + '/api/resources/index';
- const data = { resource: componentKey, metrics: metrics.join(',') };
- return getJSON(url, data).then(r => r[0]);
+ const url = baseUrl + '/api/measures/component';
+ const data = { componentKey, metricKeys: metrics.join(',') };
+ return getJSON(url, data).then(r => r.component);
}
export function getTree (baseComponentKey, options = {}) {
import { getChildren, getComponent, getTree, getBreadcrumbs } from '../../../api/components';
import { translate } from '../../../helpers/l10n';
+import { getComponentUrl } from '../../../helpers/urls';
const METRICS = [
dispatch(startFetching());
return retrieveComponent(componentKey, bucket)
.then(([component, children, breadcrumbs]) => {
- dispatch(browseAction(component, children, breadcrumbs));
+ if (component.refKey) {
+ window.location = getComponentUrl(component.refKey);
+ return new Promise();
+ } else {
+ dispatch(browseAction(component, children, breadcrumbs));
+ }
})
.then(() => dispatch(pushPath(getPath(componentKey))))
.then(() => dispatch(stopFetching()))
let componentAction = null;
- switch (component.qualifier) {
- case 'FIL':
- case 'UTS':
- componentAction = <ComponentPin component={component}/>;
- break;
- default:
- componentAction = <ComponentDetach component={component}/>;
+ if (!component.refKey) {
+ switch (component.qualifier) {
+ case 'FIL':
+ case 'UTS':
+ componentAction = <ComponentPin component={component}/>;
+ break;
+ default:
+ componentAction = <ComponentDetach component={component}/>;
+ }
}
return (
<a
className="icon-detach"
title={translate('code.open_component_page')}
- href={getComponentUrl(component.copy || component.key)}/>
+ href={getComponentUrl(component.refKey || component.key)}/>
);
const ComponentMeasure = ({ component, metricKey, metricType }) => {
- const measure = _.findWhere(component.msr, { key: metricKey });
+ const measure = _.findWhere(component.measures, { metric: metricKey });
return (
<span>
- {measure ? formatMeasure(measure.val, metricType) : ''}
+ {measure ? formatMeasure(measure.value, metricType) : ''}
</span>
);
};
<span>{component.name.substr(prefix.length)}</span>
</span>
) : component.name;
- const canBrowse = !!onBrowse && !component.copy;
+ const canBrowse = !!onBrowse;
return (
<Truncated title={getTooltip(component)}>
const ComponentPin = ({ component }) => {
const handleClick = (e) => {
e.preventDefault();
- Workspace.openComponent({ uuid: component.uuid || component.id });
+ Workspace.openComponent({ uuid: component.id });
};
return (
const METRIC = 'alert_status';
const ComponentQualityGate = ({ component }) => {
- const measure = _.findWhere(component.msr, { key: METRIC });
+ const measure = _.findWhere(component.measures, { metric: METRIC });
return measure ? (
<span
className="spacer-right"
- title={translate('metric.level', measure.data)}
+ title={translate('metric.level', measure.value)}
style={{ position: 'relative', top: '-1px' }}>
- <i className={`icon-alert-${measure.data.toLowerCase()}`}/>
+ <i className={`icon-alert-${measure.value.toLowerCase()}`}/>
</span>
) : <span/>;
};
}
shouldComponentUpdate (nextProps) {
- return nextProps.component.uuid !== this.props.component.uuid;
+ return nextProps.component.id !== this.props.component.id;
}
componentWillUpdate () {
renderSourceViewer () {
this.sourceViewer = new BaseSourceViewer();
this.sourceViewer.render().$el.appendTo(this.refs.container);
- this.sourceViewer.open(this.props.component.uuid);
+ this.sourceViewer.open(this.props.component.id);
}
destroySourceViewer () {
}
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' });
+ const coverage = _.findWhere(component.measures, { metric: 'coverage' });
+ const itCoverage = _.findWhere(component.measures, { metric: 'it_coverage' });
+ const overallCoverage = _.findWhere(component.measures, { metric: 'overall_coverage' });
if (coverage != null && itCoverage != null && overallCoverage != null) {
return 'overall_coverage';
function getMeasure (component, metric) {
- return component.measures[metric] || 0;
+ return Number(component.measures[metric]) || 0;
}
}
requestFiles () {
- let metrics = [].concat(this.props.xMetric, this.props.yMetric, this.props.sizeMetrics);
- return getFiles(this.props.component.key, metrics).then(r => {
+ const metrics = [].concat(this.props.xMetric, this.props.yMetric, this.props.sizeMetrics);
+ const options = {
+ s: 'metric',
+ metricSort: this.props.sizeMetrics,
+ asc: false,
+ ps: BUBBLES_LIMIT
+ };
+ return getFiles(this.props.component.key, metrics, options).then(r => {
let files = r.map(file => {
let measures = {};
- (file.msr || []).forEach(measure => {
- measures[measure.key] = measure.val;
+ (file.measures || []).forEach(measure => {
+ measures[measure.metric] = measure.value;
});
return _.extend(file, { measures });
});
this.setState({
loading: false,
- files: this.limitFiles(files),
+ files: files,
total: files.length
});
});
}
- limitFiles (files) {
- const comparator = file => -1 * this.getSizeMetricsValue(file);
- return _.sortBy(files, comparator).slice(0, BUBBLES_LIMIT);
- }
-
getMetricObject (metrics, metricKey) {
return _.findWhere(metrics, { key: metricKey });
}
/* eslint max-len: 0 */
let inner = [
component.name,
- `${this.state.xMetric.name}: ${formatMeasure(getMeasure(component, this.props.xMetric), this.state.xMetric.type)}`,
- `${this.state.yMetric.name}: ${formatMeasure(getMeasure(component, this.props.yMetric), this.state.yMetric.type)}`,
+ `${this.state.xMetric.name}: ${formatMeasure(getMeasure(component, this.props.xMetric),
+ this.state.xMetric.type)}`,
+ `${this.state.yMetric.name}: ${formatMeasure(getMeasure(component, this.props.yMetric),
+ this.state.yMetric.type)}`,
`${sizeMetricsTitle}: ${formatMeasure(this.getSizeMetricsValue(component), sizeMetricsType)}`
].join('<br>');
return `<div class="text-left">${inner}</div>`;
}
- handleBubbleClick (uuid) {
- Workspace.openComponent({ uuid });
+ handleBubbleClick (id) {
+ Workspace.openComponent({ uuid: id });
}
renderLoading () {
x: getMeasure(component, this.props.xMetric),
y: getMeasure(component, this.props.yMetric),
size: this.getSizeMetricsValue(component),
- link: component.uuid,
+ link: component.id,
tooltip: this.getTooltip(component)
};
});
{this.state.xMetric.name}
</div>
{this.state.total > BUBBLES_LIMIT &&
- <div className="note text-center">{translateWithParameters('overview.chart.files.limit_message', BUBBLES_LIMIT)}</div>}
+ <div className="note text-center">{translateWithParameters('overview.chart.files.limit_message',
+ BUBBLES_LIMIT)}</div>}
</div>
</div>;
}
return getChildren(componentKey, metrics).then(r => {
let components = r.map(component => {
let measures = {};
- (component.msr || []).forEach(measure => {
- measures[measure.key] = measure.val;
+ (component.measures || []).forEach(measure => {
+ measures[measure.metric] = measure.value;
});
return _.extend(component, {
measures,
- key: component.copy ? `${component.copy}` : component.key
+ key: component.refKey || component.key
});
});
this.setState({ loading: false, components });
return getChildren(this.props.component.key, metrics).then(r => {
let components = r.map(component => {
let measures = {};
- (component.msr || []).forEach(measure => {
- measures[measure.key] = measure.val;
+ (component.measures || []).forEach(measure => {
+ measures[measure.metric] = measure.value;
});
return _.extend(component, { measures });
});
let data = this.state.components.map((component, index) => {
return {
- x: parseInt(component.measures[METRIC], 10),
+ x: component.measures[METRIC] ? parseInt(component.measures[METRIC], 10) : 0,
y: index,
value: component.name,
component: component
const measures = [
- { key: 'ncloc', val: 9757 }
+ { metric: 'ncloc', value: 9757 }
];
const exampleComponent = {
uuid: 'A1',
key: 'A',
name: 'AA',
qualifier: 'TRK',
- msr: measures
+ measures: measures
};
const exampleComponent2 = { uuid: 'B2', key: 'B' };
const exampleComponent3 = { uuid: 'C3', key: 'C' };
it('should be set to "coverage"', () => {
const componentWithCoverage = {
...exampleComponent,
- msr: [
- { key: 'coverage', val: 13 }
+ measures: [
+ { metric: 'coverage', value: 13 }
]
};
it('should be set to "it_coverage"', () => {
const componentWithCoverage = {
...exampleComponent,
- msr: [
- { key: 'it_coverage', val: 13 }
+ measures: [
+ { metric: 'it_coverage', value: 13 }
]
};
it('should be set to "overall_coverage"', () => {
const componentWithCoverage = {
...exampleComponent,
- msr: [
- { key: 'coverage', val: 11 },
- { key: 'it_coverage', val: 12 },
- { key: 'overall_coverage', val: 13 }
+ measures: [
+ { metric: 'coverage', value: 11 },
+ { metric: 'it_coverage', value: 12 },
+ { metric: 'overall_coverage', value: 13 }
]
};
it('should fallback to "it_coverage"', () => {
const componentWithCoverage = {
...exampleComponent,
- msr: []
+ measures: []
};
expect(current(initialState, initComponentAction(componentWithCoverage)).coverageMetric)