]> source.dussan.org Git - sonarqube.git/commitdiff
do not load all issues for a file
authorStas Vilchik <vilchiks@gmail.com>
Thu, 27 Apr 2017 09:15:35 +0000 (11:15 +0200)
committerStas Vilchik <vilchiks@gmail.com>
Thu, 27 Apr 2017 09:44:56 +0000 (11:44 +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/SourceViewerBase.js

index a6745fa2adda670b2f68a2d5f942808bb66939b3..8d71be0d1ffeb08b20d7a04351b8d0241e53e508 100644 (file)
@@ -426,18 +426,32 @@ export default class App extends React.PureComponent {
     });
   };
 
-  fetchIssuesForComponent = (): Promise<Array<Issue>> => {
+  fetchIssuesForComponent = (
+    component: string,
+    from: number,
+    to: number
+  ): Promise<Array<Issue>> => {
     const { issues, openIssue, paging } = this.state;
 
+    /* eslint-disable no-console */
+    console.log(`loadin issues from line ${from} to line ${to}`);
+
     if (!openIssue || !paging) {
       return Promise.reject();
     }
 
     const isSameComponent = (issue: Issue): boolean => issue.component === openIssue.component;
 
-    const done = (issues: Array<Issue>, paging: Paging): boolean =>
-      paging.total <= paging.pageIndex * paging.pageSize ||
-      issues[issues.length - 1].component !== openIssue.component;
+    const done = (issues: Array<Issue>, paging: Paging): boolean => {
+      if (paging.total <= paging.pageIndex * paging.pageSize) {
+        return true;
+      }
+      const lastIssue = issues[issues.length - 1];
+      if (lastIssue.component !== openIssue.component) {
+        return true;
+      }
+      return lastIssue.line != null && lastIssue.line > to;
+    };
 
     if (done(issues, paging)) {
       return Promise.resolve(issues.filter(isSameComponent));
index 947be331377702deb59c97da0f1c04b3f2dbe212..062d8530e6d8e7283d294d49d5606c54fb4479a4 100644 (file)
@@ -24,7 +24,7 @@ import { scrollToElement } from '../../../helpers/scrolling';
 import type { Issue } from '../../../components/issue/types';
 
 type Props = {|
-  loadIssues: () => Promise<*>,
+  loadIssues: (string, number, number) => Promise<*>,
   onIssueChange: Issue => void,
   onIssueSelect: string => void,
   onLocationSelect: number => void,
index 8f29e6a59c79ebfe422d6239b5fc5aaf883c9c96..085c889bbb573a5c58b4ee3b5d2c06eeba1b08c7 100644 (file)
@@ -168,6 +168,16 @@ export default class SourceViewerBase extends React.PureComponent {
       this.isLineOutsideOfRange(this.props.aroundLine)
     ) {
       this.fetchSources();
+    } else {
+      const { selectedIssue } = this.props;
+      const { issues } = this.state;
+      if (
+        selectedIssue != null &&
+        issues != null &&
+        issues.find(issue => issue.key === selectedIssue) == null
+      ) {
+        this.reloadIssues();
+      }
     }
   }
 
@@ -273,6 +283,25 @@ export default class SourceViewerBase extends React.PureComponent {
     });
   }
 
+  reloadIssues() {
+    if (!this.state.sources) {
+      return;
+    }
+    const firstSourceLine = this.state.sources[0];
+    const lastSourceLine = this.state.sources[this.state.sources.length - 1];
+    this.props
+      .loadIssues(this.props.component, firstSourceLine.line, lastSourceLine.line)
+      .then(issues => {
+        if (this.mounted) {
+          this.setState({
+            issues,
+            issuesByLine: issuesByLine(issues),
+            issueLocationsByLine: locationsByLine(issues)
+          });
+        }
+      });
+  }
+
   loadSources() {
     return new Promise((resolve, reject) => {
       const onFailLoadSources = ({ response }) => {
@@ -312,12 +341,17 @@ export default class SourceViewerBase extends React.PureComponent {
     this.props.loadSources(this.props.component, from, firstSourceLine.line - 1).then(sources => {
       this.props.loadIssues(this.props.component, from, firstSourceLine.line - 1).then(issues => {
         if (this.mounted) {
-          this.setState(prevState => ({
-            issues: uniqBy([...issues, ...prevState.issues], issue => issue.key),
-            loadingSourcesBefore: false,
-            sources: [...this.computeCoverageStatus(sources), ...prevState.sources],
-            symbolsByLine: { ...prevState.symbolsByLine, ...symbolsByLine(sources) }
-          }));
+          this.setState(prevState => {
+            const nextIssues = uniqBy([...issues, ...prevState.issues], issue => issue.key);
+            return {
+              issues: nextIssues,
+              issuesByLine: issuesByLine(nextIssues),
+              issueLocationsByLine: locationsByLine(nextIssues),
+              loadingSourcesBefore: false,
+              sources: [...this.computeCoverageStatus(sources), ...prevState.sources],
+              symbolsByLine: { ...prevState.symbolsByLine, ...symbolsByLine(sources) }
+            };
+          });
         }
       });
     });
@@ -335,13 +369,24 @@ export default class SourceViewerBase extends React.PureComponent {
     this.props.loadSources(this.props.component, fromLine, toLine).then(sources => {
       this.props.loadIssues(this.props.component, fromLine, toLine).then(issues => {
         if (this.mounted) {
-          this.setState(prevState => ({
-            issues: uniqBy([...prevState.issues, ...issues], issue => issue.key),
-            hasSourcesAfter: sources.length > LINES,
-            loadingSourcesAfter: false,
-            sources: [...prevState.sources, ...this.computeCoverageStatus(sources.slice(0, LINES))],
-            symbolsByLine: { ...prevState.symbolsByLine, ...symbolsByLine(sources.slice(0, LINES)) }
-          }));
+          this.setState(prevState => {
+            const nextIssues = uniqBy([...prevState.issues, ...issues], issue => issue.key);
+            return {
+              issues: nextIssues,
+              issuesByLine: issuesByLine(nextIssues),
+              issueLocationsByLine: locationsByLine(nextIssues),
+              hasSourcesAfter: sources.length > LINES,
+              loadingSourcesAfter: false,
+              sources: [
+                ...prevState.sources,
+                ...this.computeCoverageStatus(sources.slice(0, LINES))
+              ],
+              symbolsByLine: {
+                ...prevState.symbolsByLine,
+                ...symbolsByLine(sources.slice(0, LINES))
+              }
+            };
+          });
         }
       });
     });