<SourceViewerWrapper
branchLike={branchLike}
component={sourceViewer.key}
+ componentMeasures={sourceViewer.measures}
isFile={true}
location={location}
onGoToParent={this.handleGoToParent}
interface Props {
branchLike?: T.BranchLike;
component: string;
+ componentMeasures: T.Measure[] | undefined;
location: Pick<Location, 'query'>;
onIssueChange?: (issue: T.Issue) => void;
}
};
render() {
- const { branchLike, component, location } = this.props;
+ const { branchLike, component, componentMeasures, location } = this.props;
const { line } = location.query;
const finalLine = line ? Number(line) : undefined;
aroundLine={finalLine}
branchLike={branchLike}
component={component}
+ componentMeasures={componentMeasures}
highlightedLine={finalLine}
onIssueChange={this.props.onIssueChange}
onLoaded={this.scrollToLine}
aroundLine?: number;
branchLike: T.BranchLike | undefined;
component: string;
+ componentMeasures?: T.Measure[];
displayAllIssues?: boolean;
displayIssueLocationsCount?: boolean;
displayIssueLocationsLink?: boolean;
{({ openComponent }) => (
<SourceViewerHeader
branchLike={this.props.branchLike}
- issues={this.state.issues}
+ componentMeasures={this.props.componentMeasures}
openComponent={openComponent}
showMeasures={this.props.showMeasures}
sourceViewerFile={sourceViewerFile}
interface Props {
branchLike: T.BranchLike | undefined;
- issues?: T.Issue[];
+ componentMeasures?: T.Measure[];
openComponent: WorkspaceContextShape['openComponent'];
showMeasures?: boolean;
sourceViewerFile: T.SourceViewerFile;
measuresOverlay: boolean;
}
+const METRIC_KEY_FOR_ISSUE_TYPE: { [type in T.IssueType]: string } = {
+ BUG: 'bugs',
+ VULNERABILITY: 'vulnerabilities',
+ CODE_SMELL: 'code_smells',
+ SECURITY_HOTSPOT: 'security_hotspots'
+};
+
export default class SourceViewerHeader extends React.PureComponent<Props, State> {
state: State = { measuresOverlay: false };
};
renderIssueMeasures = () => {
- const { branchLike, issues, sourceViewerFile } = this.props;
+ const { branchLike, componentMeasures, sourceViewerFile } = this.props;
return (
- issues &&
- issues.length > 0 && (
+ componentMeasures &&
+ componentMeasures.length > 0 && (
<>
<div className="source-viewer-header-measure-separator" />
types: type
};
- const total = issues.filter(issue => issue.type === type).length;
+ const measure = componentMeasures.find(
+ m => m.metric === METRIC_KEY_FOR_ISSUE_TYPE[type]
+ );
return (
<div className="source-viewer-header-measure" key={type}>
<span className="source-viewer-header-measure-label">
</span>
<span className="source-viewer-header-measure-value">
<Link to={getComponentIssuesUrl(sourceViewerFile.project, params)}>
- {formatMeasure(total, 'INT')}
+ {formatMeasure((measure && measure.value) || 0, 'INT')}
</Link>
</span>
</div>
*/
import { shallow } from 'enzyme';
import * as React from 'react';
-import { mockIssue, mockMainBranch, mockSourceViewerFile } from '../../../helpers/testMocks';
+import { mockMainBranch, mockSourceViewerFile } from '../../../helpers/testMocks';
import SourceViewerHeader from '../SourceViewerHeader';
it('should render correctly for a regular file', () => {
});
it('should render correctly if issue details are passed', () => {
- const issues = [
- mockIssue(false, { type: 'VULNERABILITY' }),
- mockIssue(false, { type: 'VULNERABILITY' }),
- mockIssue(false, { type: 'CODE_SMELL' }),
- mockIssue(false, { type: 'SECURITY_HOTSPOT' }),
- mockIssue(false, { type: 'SECURITY_HOTSPOT' })
+ const componentMeasures: T.Measure[] = [
+ { metric: 'code_smells', value: '1' },
+ { metric: 'unused_metric_to_be_ignored', value: '42' },
+ { metric: 'security_hotspots', value: '2' },
+ { metric: 'vulnerabilities', value: '2' }
];
expect(
shallowRender({
- issues,
+ componentMeasures,
showMeasures: true
})
).toMatchSnapshot();
expect(
shallowRender({
- issues,
+ componentMeasures,
showMeasures: false
})
.find('.source-viewer-header-measure')