]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9499 Secondary locations unclickable when code is not loaded
authorStas Vilchik <stas.vilchik@sonarsource.com>
Mon, 2 Oct 2017 14:21:41 +0000 (16:21 +0200)
committerStas Vilchik <stas.vilchik@sonarsource.com>
Tue, 3 Oct 2017 07:12:07 +0000 (09:12 +0200)
server/sonar-web/src/main/js/apps/issues/components/IssuesSourceViewer.js

index ef5904ea7045ef7864646fa1d4e2121441b657d3..06ba694e1cdb9a1029552277ab754bb11622490b 100644 (file)
@@ -75,17 +75,28 @@ export default class IssuesSourceViewer extends React.PureComponent {
         ? openIssue.flows[selectedFlowIndex]
         : openIssue.flows.length > 0 ? openIssue.flows[0] : openIssue.secondaryLocations;
 
-    const locationMessage =
+    let locationMessage = undefined;
+    let locationLine = undefined;
+    if (
       locations != null &&
       selectedLocationIndex != null &&
       locations.length >= selectedLocationIndex
-        ? { index: selectedLocationIndex, text: locations[selectedLocationIndex].msg }
-        : undefined;
+    ) {
+      locationMessage = {
+        index: selectedLocationIndex,
+        text: locations[selectedLocationIndex].msg
+      };
+      locationLine = locations[selectedLocationIndex].textRange.startLine;
+    }
+
+    // if location is selected, show (and load) code around it
+    // otherwise show code around the open issue
+    const aroundLine = locationLine || (openIssue.textRange && openIssue.textRange.endLine);
 
     return (
       <div ref={node => (this.node = node)}>
         <SourceViewer
-          aroundLine={openIssue.textRange ? openIssue.textRange.endLine : undefined}
+          aroundLine={aroundLine}
           branch={this.props.branch}
           component={openIssue.component}
           displayAllIssues={true}