]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9174 Display issue box on the last line of its primary location (#2047)
authorStas Vilchik <stas-vilchik@users.noreply.github.com>
Thu, 11 May 2017 08:04:50 +0000 (10:04 +0200)
committerGitHub <noreply@github.com>
Thu, 11 May 2017 08:04:50 +0000 (10:04 +0200)
server/sonar-web/src/main/js/apps/issues/components/App.js
server/sonar-web/src/main/js/apps/issues/components/IssuesSourceViewer.js
server/sonar-web/src/main/js/components/SourceViewer/SourceViewerCode.js
server/sonar-web/src/main/js/components/SourceViewer/helpers/indexing.js
server/sonar-web/src/main/js/components/SourceViewer/helpers/loadIssues.js
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/js/components/issue/types.js

index 4a9dca21d04f1fe077a3102903bef2f6f5313060..e56811d72c36a8bf80368c44ab915274f32757f5 100644 (file)
@@ -453,7 +453,7 @@ export default class App extends React.PureComponent {
       if (lastIssue.component !== openIssue.component) {
         return true;
       }
-      return lastIssue.line != null && lastIssue.line > to;
+      return lastIssue.textRange != null && lastIssue.textRange.endLine > to;
     };
 
     if (done(issues, paging)) {
index 062d8530e6d8e7283d294d49d5606c54fb4479a4..8580fcff5b6ffd0691baefcc909e3f7909568c31 100644 (file)
@@ -78,7 +78,7 @@ export default class IssuesSourceViewer extends React.PureComponent {
     return (
       <div ref={node => (this.node = node)}>
         <SourceViewer
-          aroundLine={openIssue.line}
+          aroundLine={openIssue.textRange ? openIssue.textRange.endLine : undefined}
           component={openIssue.component}
           displayAllIssues={true}
           highlightedLocations={locations}
index 59a21aa332dbb3ab922ba1d4918dae94f584ca41..69af047648cda5a104dca6251b508b1e10cebc79 100644 (file)
@@ -189,7 +189,7 @@ export default class SourceViewerCode extends React.PureComponent {
     const displayFiltered = this.props.filterLine != null;
     const hasIssues = this.props.issues.length > 0;
 
-    const hasFileIssues = hasIssues && this.props.issues.some(issue => !issue.line);
+    const hasFileIssues = hasIssues && this.props.issues.some(issue => !issue.textRange);
 
     return (
       <div>
index 0047ee41fefc3782f5aaa4fddd7efabae9f330ea..eac2170df15abebed28cd5853b85213346fcbfbd 100644 (file)
@@ -46,7 +46,7 @@ export type IndexedIssueLocationMessage = {
 export const issuesByLine = (issues: Array<Issue>) => {
   const index = {};
   issues.forEach(issue => {
-    const line = issue.line || 0;
+    const line = issue.textRange ? issue.textRange.endLine : 0;
     if (!(line in index)) {
       index[line] = [];
     }
index 0e56ceab7b92a0e312e53fa04ccf82d5f3c0c636..737b9aceddabac9e1f7b03c508bbbd9680927e31 100644 (file)
@@ -62,7 +62,10 @@ export const loadPageAndNext = (
 
     const lastIssue = issues[issues.length - 1];
 
-    if ((lastIssue.line != null && lastIssue.line > toLine) || issues.length < pageSize) {
+    if (
+      (lastIssue.textRange != null && lastIssue.textRange.endLine > toLine) ||
+      issues.length < pageSize
+    ) {
       return issues;
     }
 
index 8621fce9439b74f9b2d6d5d8d1bb0c0d829be70e..6e0fe943f07cb0a4e5f66bde7d805d5fb2183dd3 100644 (file)
@@ -86,10 +86,10 @@ export default function IssueTitleBar(props: Props) {
                   onFail={props.onFail}
                 />
               </li>
-              {issue.line != null &&
+              {issue.textRange != null &&
                 <li className="issue-meta">
                   <span className="issue-meta-label" title={translate('line_number')}>
-                    L{issue.line}
+                    L{issue.textRange.endLine}
                   </span>
                 </li>}
               {locationsCount > 0 &&
index f09d709908fb658007415ecfafe877475de1f430..407b05eb18958fc93ebbba3be7fb3b482b0c6e2a 100644 (file)
@@ -22,7 +22,13 @@ import React from 'react';
 import IssueTitleBar from '../IssueTitleBar';
 
 const issue = {
-  line: 26,
+  line: 25,
+  textRange: {
+    startLine: 25,
+    endLine: 26,
+    startOffset: 0,
+    endOffset: 15
+  },
   creationDate: '2017-03-01T09:36:01+0100',
   organization: 'myorg',
   project: 'myproject',
index 2a7d3bdbcea7041dcddc569f0e6ecd5532a834b9..5d61fbfb7d20b62f523a39dd09f91750a8768e2f 100644 (file)
@@ -30,12 +30,18 @@ exports[`should render the titlebar correctly 1`] = `
                   "creationDate": "2017-03-01T09:36:01+0100",
                   "flows": Array [],
                   "key": "AVsae-CQS-9G3txfbFN2",
-                  "line": 26,
+                  "line": 25,
                   "message": "Reduce the number of conditional operators (4) used in the expression",
                   "organization": "myorg",
                   "project": "myproject",
                   "rule": "javascript:S1067",
                   "secondaryLocations": Array [],
+                  "textRange": Object {
+                    "endLine": 26,
+                    "endOffset": 15,
+                    "startLine": 25,
+                    "startOffset": 0,
+                  },
                 }
               }
               onFail={[Function]}
@@ -111,12 +117,18 @@ exports[`should render the titlebar with the filter 1`] = `
                   "creationDate": "2017-03-01T09:36:01+0100",
                   "flows": Array [],
                   "key": "AVsae-CQS-9G3txfbFN2",
-                  "line": 26,
+                  "line": 25,
                   "message": "Reduce the number of conditional operators (4) used in the expression",
                   "organization": "myorg",
                   "project": "myproject",
                   "rule": "javascript:S1067",
                   "secondaryLocations": Array [],
+                  "textRange": Object {
+                    "endLine": 26,
+                    "endOffset": 15,
+                    "startLine": 25,
+                    "startOffset": 0,
+                  },
                 }
               }
               onFail={[Function]}
@@ -165,12 +177,18 @@ exports[`should render the titlebar with the filter 1`] = `
                   "creationDate": "2017-03-01T09:36:01+0100",
                   "flows": Array [],
                   "key": "AVsae-CQS-9G3txfbFN2",
-                  "line": 26,
+                  "line": 25,
                   "message": "Reduce the number of conditional operators (4) used in the expression",
                   "organization": "myorg",
                   "project": "myproject",
                   "rule": "javascript:S1067",
                   "secondaryLocations": Array [],
+                  "textRange": Object {
+                    "endLine": 26,
+                    "endOffset": 15,
+                    "startLine": 25,
+                    "startOffset": 0,
+                  },
                 }
               }
               onFail={[Function]}
index 45fb150ad3074a3a5655b57d095d0a33e00f748f..8788dc4d206e00abf799622bf67d731f34bb0b55 100644 (file)
@@ -77,7 +77,7 @@ export type Issue = {
   subProjectName?: string,
   subProjectUuid?: string,
   tags?: Array<string>,
-  textRange: TextRange,
+  textRange?: TextRange,
   transitions?: Array<string>,
   type: string
 };