]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4004 require 3 characters to search
authorStas Vilchik <vilchiks@gmail.com>
Fri, 4 Mar 2016 09:59:07 +0000 (10:59 +0100)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Fri, 4 Mar 2016 15:30:43 +0000 (16:30 +0100)
server/sonar-web/src/main/js/apps/code/actions/index.js
server/sonar-web/src/main/js/apps/code/components/Search.js
server/sonar-web/src/main/js/apps/code/styles/code.css

index a89e78786f551209474a0ec030050d0a6ba1e8c8..6bca96a7b02176f767f6e69d5735263c4bab7d32 100644 (file)
@@ -222,7 +222,10 @@ debouncedSearch = _.debounce(debouncedSearch, 250);
 export function search (query, baseComponent) {
   return dispatch => {
     dispatch(updateQueryAction(query));
-    debouncedSearch(query, baseComponent, dispatch);
+
+    if (query.length > 2 || !query.length) {
+      debouncedSearch(query, baseComponent, dispatch);
+    }
   };
 }
 
index 60522b0f759555f81455640b85bfb4e10e899641..97cba288b037e97ace6b8f5c2e25a034f2058d75 100644 (file)
  */
 import React, { Component } from 'react';
 import { connect } from 'react-redux';
+import classNames from 'classnames';
 
 import { search, selectCurrent, selectNext, selectPrev } from '../actions';
+import { translateWithParameters } from '../../../helpers/l10n';
 
 
 class Search extends Component {
@@ -44,7 +46,7 @@ class Search extends Component {
         dispatch(selectNext());
         break;
       default:
-      // do nothing
+        // do nothing
     }
   }
 
@@ -57,6 +59,9 @@ class Search extends Component {
 
   render () {
     const { query } = this.props;
+    const inputClassName = classNames('search-box-input', {
+      'touched': query.length > 0 && query.length < 3
+    });
 
     return (
         <form
@@ -70,12 +75,15 @@ class Search extends Component {
               onKeyDown={this.handleKeyDown.bind(this)}
               onChange={this.handleSearch.bind(this)}
               value={query}
-              className="search-box-input"
+              className={inputClassName}
               type="search"
               name="q"
               placeholder="Search"
               maxLength="100"
               autoComplete="off"/>
+          <div className="note">
+            {translateWithParameters('select2.tooShort', 3)}
+          </div>
         </form>
     );
   }
index 3577f7f341e280c92bdfea406ef106c2fc41b2cc..f5ffda5a8e02dff8637493ddd7d67d03cdd09e29 100644 (file)
   float: left;
   padding-right: 10px;
 }
+
+.code-search-box .note {
+  margin-top: 4px;
+  margin-left: 25px;
+  opacity: 0;
+  transition: opacity 0.3s ease;
+}
+
+.code-search-box input.touched ~ .note {
+  opacity: 1;
+}