From 18f20eed6127994e54d2fcc7f9772fdcafcfd25d Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Mon, 27 May 2019 10:41:30 +0200 Subject: SONAR-12114 Add Links in codeviewer header --- .../components/SourceViewer/SourceViewerHeader.tsx | 91 ++++++++++++---------- .../__snapshots__/SourceViewerHeader-test.tsx.snap | 72 ++++++++++++++++- 2 files changed, 118 insertions(+), 45 deletions(-) (limited to 'server') diff --git a/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerHeader.tsx b/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerHeader.tsx index c9f23440479..9a8a57bf77d 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerHeader.tsx +++ b/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerHeader.tsx @@ -21,19 +21,25 @@ import { stringify } from 'querystring'; import * as React from 'react'; import { Link } from 'react-router'; import MeasuresOverlay from './components/MeasuresOverlay'; -import QualifierIcon from '../icons-components/QualifierIcon'; import Dropdown from '../controls/Dropdown'; import Favorite from '../controls/Favorite'; import ListIcon from '../icons-components/ListIcon'; +import QualifierIcon from '../icons-components/QualifierIcon'; import { ButtonIcon } from '../ui/buttons'; import { PopupPlacement } from '../ui/popups'; import { WorkspaceContextShape } from '../workspace/context'; -import { getPathUrlAsString, getBranchLikeUrl, getBaseUrl, getCodeUrl } from '../../helpers/urls'; -import { collapsedDirFromPath, fileFromPath } from '../../helpers/path'; -import { translate } from '../../helpers/l10n'; import { getBranchLikeQuery, isMainBranch } from '../../helpers/branches'; +import { translate } from '../../helpers/l10n'; import { formatMeasure } from '../../helpers/measures'; +import { collapsedDirFromPath, fileFromPath } from '../../helpers/path'; import { omitNil } from '../../helpers/request'; +import { + getBranchLikeUrl, + getBaseUrl, + getCodeUrl, + getComponentIssuesUrl, + getPathUrlAsString +} from '../../helpers/urls'; interface Props { branchLike: T.BranchLike | undefined; @@ -65,8 +71,42 @@ export default class SourceViewerHeader extends React.PureComponent { + const { branchLike, issues, sourceViewerFile } = this.props; + if (issues && issues.length > 0) { + return ( + <> +
+ + {['BUG', 'VULNERABILITY', 'CODE_SMELL', 'SECURITY_HOTSPOT'].map((type: T.IssueType) => { + const params = { + ...getBranchLikeQuery(branchLike), + fileUuids: sourceViewerFile.uuid, + resolved: 'false', + types: type + }; + + const total = issues.filter(issue => issue.type === type).length; + return ( +
+ + {translate('issue.type', type)} + + + + {formatMeasure(total, 'INT')} + + +
+ ); + })} + + ); + } + }; + render() { - const { issues, showMeasures } = this.props; + const { showMeasures } = this.props; const { key, measures, @@ -77,7 +117,7 @@ export default class SourceViewerHeader extends React.PureComponent - {isUnitTest && ( + {measures[unitTestsOrLines] && (
- {translate('metric.tests.name')} + {translate(`metric.${unitTestsOrLines}.name`)} - {formatMeasure(measures.tests, 'SHORT_INT')} - -
- )} - - {!isUnitTest && ( -
- - {translate('metric.lines.name')} - - - {formatMeasure(measures.lines, 'SHORT_INT')} + {formatMeasure(measures[unitTestsOrLines], 'SHORT_INT')}
)} @@ -173,27 +202,7 @@ export default class SourceViewerHeader extends React.PureComponent )} - {issues && issues.length > 0 && ( - <> -
- - {['BUG', 'VULNERABILITY', 'CODE_SMELL', 'SECURITY_HOTSPOT'].map( - (type: T.IssueType) => { - const total = issues.filter(issue => issue.type === type).length; - return ( -
- - {translate('issue.type', type)} - - - {formatMeasure(total, 'INT')} - -
- ); - } - )} - - )} + {this.renderIssueMeasures()}
)} diff --git a/server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewerHeader-test.tsx.snap b/server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewerHeader-test.tsx.snap index f5b7d5831f9..73167d83070 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewerHeader-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewerHeader-test.tsx.snap @@ -346,7 +346,23 @@ exports[`should render correctly if issue details are passed 1`] = ` - 0 + + 0 +
- 2 + + 2 +
- 1 + + 1 +
- 2 + + 2 +
-- cgit v1.2.3