]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9063 Add the number of multiple locations on issue box (#1972)
authorStas Vilchik <stas-vilchik@users.noreply.github.com>
Mon, 24 Apr 2017 08:38:44 +0000 (10:38 +0200)
committerGitHub <noreply@github.com>
Mon, 24 Apr 2017 08:38:44 +0000 (10:38 +0200)
server/sonar-web/src/main/js/components/common/LocationIndex.css
server/sonar-web/src/main/js/components/issue/components/IssueTitleBar.js
server/sonar-web/src/main/js/components/issue/components/__tests__/IssueTitleBar-test.js
server/sonar-web/src/main/js/components/issue/components/__tests__/__snapshots__/IssueTitleBar-test.js.snap
server/sonar-web/src/main/less/components/issues.less

index 58ef49ee7d55388d6b3530e9cddd0e6a496145c3..d796e251a4332315fea87f121c1ef335166475c6 100644 (file)
@@ -25,7 +25,8 @@
   cursor: pointer;
 }
 
-.location-index[tabindex]:hover {
+.location-index[tabindex]:hover,
+a:hover > .location-index {
   background-color: #bc5e5e;
 }
 
   outline: none;
 }
 
-.source-line-code .location-index {
+.source-line-code-inner .location-index {
   line-height: 16px;
   margin: 1px;
   margin-left: 4px;
   margin-right: 4px;
 }
 
-.source-line-code .location-index + .location-index {
+.source-line-code-inner .location-index + .location-index {
   margin-left: 0;
 }
\ No newline at end of file
index 901ae80febfcccb6b5d62ec01cccff191080f578..90ddd3a73c6f08249294964f82621eb6e8838d42 100644 (file)
@@ -23,8 +23,11 @@ import { Link } from 'react-router';
 import IssueChangelog from './IssueChangelog';
 import IssueMessage from './IssueMessage';
 import SimilarIssuesFilter from './SimilarIssuesFilter';
+import LocationIndex from '../../common/LocationIndex';
+import Tooltip from '../../controls/Tooltip';
 import { getSingleIssueUrl } from '../../../helpers/urls';
-import { translate } from '../../../helpers/l10n';
+import { formatMeasure } from '../../../helpers/measures';
+import { translate, translateWithParameters } from '../../../helpers/l10n';
 import type { Issue } from '../types';
 
 type Props = {|
@@ -41,6 +44,24 @@ export default function IssueTitleBar(props: Props) {
   const { issue } = props;
   const hasSimilarIssuesFilter = props.onFilter != null;
 
+  const locationsCount =
+    issue.secondaryLocations.length +
+    issue.flows.reduce((sum, locations) => sum + locations.length, 0);
+
+  const locationsBadge = (
+    <Tooltip
+      overlay={translateWithParameters(
+        'issue.this_issue_involves_x_code_locations',
+        formatMeasure(locationsCount)
+      )}
+      placement="left">
+      <LocationIndex>{locationsCount}</LocationIndex>
+    </Tooltip>
+  );
+
+  // dirty trick :(
+  const onIssuesPage = document.getElementById('issues-page') != null;
+
   return (
     <table className="issue-table">
       <tbody>
@@ -69,6 +90,14 @@ export default function IssueTitleBar(props: Props) {
                     L{issue.line}
                   </span>
                 </li>}
+              {locationsCount > 0 &&
+                <li className="issue-meta">
+                  {onIssuesPage
+                    ? locationsBadge
+                    : <Link onClick={stopPropagation} to={getSingleIssueUrl(issue.key)}>
+                        {locationsBadge}
+                      </Link>}
+                </li>}
               <li className="issue-meta">
                 <Link
                   className="js-issue-permalink icon-link"
index 1d3b7ac4e0e9c42236697586cda3a386fcd2a85c..8545979087b3c119623878034fd6a3e71c0ee57e 100644 (file)
@@ -27,7 +27,9 @@ const issue = {
   organization: 'myorg',
   key: 'AVsae-CQS-9G3txfbFN2',
   rule: 'javascript:S1067',
-  message: 'Reduce the number of conditional operators (4) used in the expression'
+  message: 'Reduce the number of conditional operators (4) used in the expression',
+  flows: [],
+  secondaryLocations: []
 };
 
 it('should render the titlebar correctly', () => {
@@ -49,3 +51,13 @@ it('should render the titlebar with the filter', () => {
   );
   expect(element).toMatchSnapshot();
 });
+
+it('should count all code locations', () => {
+  const issueWithLocations = {
+    ...issue,
+    flows: [[{}, {}, {}], [{}, {}]],
+    secondaryLocations: [{}, {}]
+  };
+  const element = shallow(<IssueTitleBar issue={issueWithLocations} />);
+  expect(element.find('LocationIndex').children().text()).toBe('7');
+});
index e00752935ca3145b574fe359ae6260b73c1ef4b6..a0f131c9fc5e61dd54562fe7aacb312273eeb252 100644 (file)
@@ -21,11 +21,13 @@ exports[`test should render the titlebar correctly 1`] = `
               issue={
                 Object {
                   "creationDate": "2017-03-01T09:36:01+0100",
+                  "flows": Array [],
                   "key": "AVsae-CQS-9G3txfbFN2",
                   "line": 26,
                   "message": "Reduce the number of conditional operators (4) used in the expression",
                   "organization": "myorg",
                   "rule": "javascript:S1067",
+                  "secondaryLocations": Array [],
                 }
               }
               onFail={[Function]}
@@ -86,11 +88,13 @@ exports[`test should render the titlebar with the filter 1`] = `
               issue={
                 Object {
                   "creationDate": "2017-03-01T09:36:01+0100",
+                  "flows": Array [],
                   "key": "AVsae-CQS-9G3txfbFN2",
                   "line": 26,
                   "message": "Reduce the number of conditional operators (4) used in the expression",
                   "organization": "myorg",
                   "rule": "javascript:S1067",
+                  "secondaryLocations": Array [],
                 }
               }
               onFail={[Function]}
@@ -128,11 +132,13 @@ exports[`test should render the titlebar with the filter 1`] = `
               issue={
                 Object {
                   "creationDate": "2017-03-01T09:36:01+0100",
+                  "flows": Array [],
                   "key": "AVsae-CQS-9G3txfbFN2",
                   "line": 26,
                   "message": "Reduce the number of conditional operators (4) used in the expression",
                   "organization": "myorg",
                   "rule": "javascript:S1067",
+                  "secondaryLocations": Array [],
                 }
               }
               onFail={[Function]}
index ba09fadce81a60d70a05730b25178ab83ada31d5..7d8eae94131ef3f417ce83f78e81296416af8c38 100644 (file)
@@ -361,3 +361,7 @@ input.issue-action-options-search {
   left: 50%;
   margin: -8px 0 0 -8px;
 }
+
+.issue:not(.selected) .location-index {
+  background-color: #ccc;
+}
\ No newline at end of file