]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10573 Allow to navigate on more than 100 rules with keyboard
authorPascal Mugnier <pascal.mugnier@sonarsource.com>
Tue, 17 Apr 2018 06:26:05 +0000 (08:26 +0200)
committerSonarTech <sonartech@sonarsource.com>
Wed, 18 Apr 2018 18:20:53 +0000 (20:20 +0200)
server/sonar-web/src/main/js/apps/coding-rules/components/App.tsx

index 3dfece1130104052d279520d25bc1fb680c42144..d8ba80576a083c42eb883e12f9a982eca4ce31f2 100644 (file)
@@ -56,6 +56,7 @@ import { scrollToElement } from '../../../helpers/scrolling';
 import '../styles.css';
 
 const PAGE_SIZE = 100;
+const LIMIT_BEFORE_LOAD_MORE = 5;
 
 interface Props {
   location: { pathname: string; query: RawQuery };
@@ -287,13 +288,23 @@ export default class App extends React.PureComponent<Props, State> {
   };
 
   selectNextRule = () => {
-    const { rules } = this.state;
+    const { rules, loading, paging } = this.state;
     const selectedIndex = this.getSelectedIndex();
-    if (rules && selectedIndex !== undefined && selectedIndex < rules.length - 1) {
-      if (this.state.openRule) {
-        this.openRule(rules[selectedIndex + 1].key);
-      } else {
-        this.setState({ selected: rules[selectedIndex + 1].key });
+    if (selectedIndex !== undefined) {
+      if (
+        selectedIndex > rules.length - LIMIT_BEFORE_LOAD_MORE &&
+        !loading &&
+        paging &&
+        rules.length < paging.total
+      ) {
+        this.fetchMoreRules();
+      }
+      if (rules && selectedIndex < rules.length - 1) {
+        if (this.state.openRule) {
+          this.openRule(rules[selectedIndex + 1].key);
+        } else {
+          this.setState({ selected: rules[selectedIndex + 1].key });
+        }
       }
     }
   };