From: Jeremy Davis Date: Wed, 13 Nov 2019 09:06:17 +0000 (+0900) Subject: SONAR-12367 Show total issues in codeviewer header X-Git-Tag: 8.1.0.31237~55 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5903d90c057cf58c17e32b4c5c20f87dd8e4f452;p=sonarqube.git SONAR-12367 Show total issues in codeviewer header --- diff --git a/server/sonar-web/src/main/js/apps/code/components/App.tsx b/server/sonar-web/src/main/js/apps/code/components/App.tsx index ce34389013d..7135d3fe6a0 100644 --- a/server/sonar-web/src/main/js/apps/code/components/App.tsx +++ b/server/sonar-web/src/main/js/apps/code/components/App.tsx @@ -327,6 +327,7 @@ export class App extends React.PureComponent { ; onIssueChange?: (issue: T.Issue) => void; } @@ -44,7 +45,7 @@ export class SourceViewerWrapper extends React.PureComponent { }; render() { - const { branchLike, component, location } = this.props; + const { branchLike, component, componentMeasures, location } = this.props; const { line } = location.query; const finalLine = line ? Number(line) : undefined; @@ -53,6 +54,7 @@ export class SourceViewerWrapper extends React.PureComponent { aroundLine={finalLine} branchLike={branchLike} component={component} + componentMeasures={componentMeasures} highlightedLine={finalLine} onIssueChange={this.props.onIssueChange} onLoaded={this.scrollToLine} diff --git a/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerBase.tsx b/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerBase.tsx index 22b82d5f11a..e66edd4fde0 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerBase.tsx +++ b/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerBase.tsx @@ -56,6 +56,7 @@ export interface Props { aroundLine?: number; branchLike: T.BranchLike | undefined; component: string; + componentMeasures?: T.Measure[]; displayAllIssues?: boolean; displayIssueLocationsCount?: boolean; displayIssueLocationsLink?: boolean; @@ -664,7 +665,7 @@ export default class SourceViewerBase extends React.PureComponent {({ openComponent }) => ( { state: State = { measuresOverlay: false }; @@ -68,10 +75,10 @@ export default class SourceViewerHeader extends React.PureComponent { - const { branchLike, issues, sourceViewerFile } = this.props; + const { branchLike, componentMeasures, sourceViewerFile } = this.props; return ( - issues && - issues.length > 0 && ( + componentMeasures && + componentMeasures.length > 0 && ( <>
@@ -83,7 +90,9 @@ export default class SourceViewerHeader extends React.PureComponent issue.type === type).length; + const measure = componentMeasures.find( + m => m.metric === METRIC_KEY_FOR_ISSUE_TYPE[type] + ); return (
@@ -91,7 +100,7 @@ export default class SourceViewerHeader extends React.PureComponent - {formatMeasure(total, 'INT')} + {formatMeasure((measure && measure.value) || 0, 'INT')}
diff --git a/server/sonar-web/src/main/js/components/SourceViewer/__tests__/SourceViewerHeader-test.tsx b/server/sonar-web/src/main/js/components/SourceViewer/__tests__/SourceViewerHeader-test.tsx index 3a78dea570a..385046e2078 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/__tests__/SourceViewerHeader-test.tsx +++ b/server/sonar-web/src/main/js/components/SourceViewer/__tests__/SourceViewerHeader-test.tsx @@ -19,7 +19,7 @@ */ 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', () => { @@ -36,24 +36,23 @@ it('should render correctly for a unit test', () => { }); 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')