From 60b6744463a378ade75bef38c3cdb2da97015f87 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Mon, 11 Jan 2016 09:13:30 +0100 Subject: [PATCH] Revert "SONAR-7149 display a list of sub-components when start searching" This reverts commit 88726dbd19b93375a6e6290f05168e051a334e5a. --- .../src/main/js/apps/code/actions/index.js | 29 ++++---- .../src/main/js/apps/code/components/Code.js | 33 +-------- .../main/js/apps/code/components/Search.js | 70 ++++--------------- .../src/main/js/apps/code/reducers/index.js | 4 +- .../main/nav/templates/nav-shortcuts-help.hbs | 21 ++---- .../sonar-web/tests/apps/code/store-test.js | 2 +- 6 files changed, 41 insertions(+), 118 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/code/actions/index.js b/server/sonar-web/src/main/js/apps/code/actions/index.js index 98526d00287..bc3515f64cb 100644 --- a/server/sonar-web/src/main/js/apps/code/actions/index.js +++ b/server/sonar-web/src/main/js/apps/code/actions/index.js @@ -146,20 +146,12 @@ function retrieveComponent (componentKey, bucket) { ]); } -let requestTree = (query, baseComponent, dispatch) => { +function requestTree (query, baseComponent, dispatch) { dispatch(startFetching()); - - const params = { s: 'qualifier,name', qualifiers: 'BRC,FIL,UTS' }; - - if (query) { - params.q = query; - } - - return getTree(baseComponent.key, params) + return getTree(baseComponent.key, { q: query, s: 'qualifier,name' }) .then(r => dispatch(searchAction(r.components))) .then(() => dispatch(stopFetching())); -}; -requestTree = _.debounce(requestTree, 250); +} async function getErrorMessage (response) { switch (response.status) { @@ -203,13 +195,18 @@ export function browse (componentKey) { }; } +let debouncedSearch = function (query, baseComponent, dispatch) { + if (query) { + requestTree(query, baseComponent, dispatch); + } else { + dispatch(searchAction(null)); + } +}; +debouncedSearch = _.debounce(debouncedSearch, 250); + export function search (query, baseComponent) { return dispatch => { dispatch(updateQueryAction(query)); - if (query != null) { - requestTree(query, baseComponent, dispatch); - } else { - dispatch(searchAction(null)); - } + debouncedSearch(query, baseComponent, dispatch); }; } diff --git a/server/sonar-web/src/main/js/apps/code/components/Code.js b/server/sonar-web/src/main/js/apps/code/components/Code.js index f7120d283df..f2c61b51ec7 100644 --- a/server/sonar-web/src/main/js/apps/code/components/Code.js +++ b/server/sonar-web/src/main/js/apps/code/components/Code.js @@ -25,7 +25,7 @@ import Components from './Components'; import Breadcrumbs from './Breadcrumbs'; import SourceViewer from './SourceViewer'; import Search from './Search'; -import { initComponent, browse, search } from '../actions'; +import { initComponent, browse } from '../actions'; import { translate } from '../../../helpers/l10n'; @@ -33,12 +33,8 @@ class Code extends Component { componentDidMount () { const { dispatch, component, routing } = this.props; const selectedKey = (routing.path && decodeURIComponent(routing.path.substr(1))) || component.key; - dispatch(initComponent(component.key, component.breadcrumbs)) .then(() => dispatch(browse(selectedKey))); - - this.handleKeyDown = this.handleKeyDown.bind(this); - this.attachShortcuts(); } componentWillReceiveProps (nextProps) { @@ -51,32 +47,11 @@ class Code extends Component { } } - componentWillUnmount () { - this.removeShortcuts(); - } - - attachShortcuts () { - window.addEventListener('keyup', this.handleKeyDown); - } - - removeShortcuts () { - window.removeEventListener('keyup', this.handleKeyDown); - } - handleBrowse (component) { const { dispatch } = this.props; dispatch(browse(component.key)); } - handleKeyDown (e) { - const { dispatch, component, searchQuery } = this.props; - - // "t" key - if (e.keyCode === 84 && searchQuery == null) { - dispatch(search('', component)); - } - } - render () { const { fetching, @@ -90,7 +65,7 @@ class Code extends Component { const shouldShowSearchResults = !!searchResults; const shouldShowSourceViewer = !!sourceViewer; const shouldShowComponents = !shouldShowSearchResults && !shouldShowSourceViewer && components; - const shouldShowBreadcrumbs = !shouldShowSearchResults && Array.isArray(breadcrumbs) && breadcrumbs.length > 1; + const shouldShowBreadcrumbs = !shouldShowSearchResults && Array.isArray(breadcrumbs) && breadcrumbs.length > 1; const componentsClassName = classNames('spacer-top', { 'new-loading': fetching }); @@ -105,9 +80,7 @@ class Code extends Component { -
- -
+ {errorMessage && ( diff --git a/server/sonar-web/src/main/js/apps/code/components/Search.js b/server/sonar-web/src/main/js/apps/code/components/Search.js index f71d5f4e424..2a6c602926f 100644 --- a/server/sonar-web/src/main/js/apps/code/components/Search.js +++ b/server/sonar-web/src/main/js/apps/code/components/Search.js @@ -21,80 +21,40 @@ import React, { Component } from 'react'; import { connect } from 'react-redux'; import { search } from '../actions'; -import { translate } from '../../../helpers/l10n'; class Search extends Component { componentDidMount () { - this.focusSearchInput(); - } - - componentDidUpdate () { - this.focusSearchInput(); - } - - focusSearchInput () { - if (this.refs.input) { - this.refs.input.focus(); - } + this.refs.input.focus(); } handleSearch (e) { e.preventDefault(); const { dispatch, component } = this.props; - const query = this.refs.input ? this.refs.input.value : ''; + const query = this.refs.input.value; dispatch(search(query, component)); } - handleStopSearch (e) { - e.preventDefault(); - const { dispatch } = this.props; - dispatch(search(null)); - } - - handleKeyDown (e) { - const { dispatch } = this.props; - - // "escape" key - if (e.keyCode === 27) { - dispatch(search(null)); - } - } - render () { const { query } = this.props; - const hasQuery = query != null; return (
- {hasQuery && ( - - )} - {!hasQuery && ( - - )} - {hasQuery && ( - - )} + +
); } diff --git a/server/sonar-web/src/main/js/apps/code/reducers/index.js b/server/sonar-web/src/main/js/apps/code/reducers/index.js index 596d92b91ea..2c8b31a1ebb 100644 --- a/server/sonar-web/src/main/js/apps/code/reducers/index.js +++ b/server/sonar-web/src/main/js/apps/code/reducers/index.js @@ -76,7 +76,7 @@ export const initialState = { breadcrumbs: null, sourceViewer: null, searchResults: null, - searchQuery: null, + searchQuery: '', coverageMetric: null, baseBreadcrumbs: [], errorMessage: null @@ -104,7 +104,7 @@ export function current (state = initialState, action) { breadcrumbs, sourceViewer, searchResults: null, - searchQuery: null, + searchQuery: '', errorMessage: null }; case SEARCH: diff --git a/server/sonar-web/src/main/js/main/nav/templates/nav-shortcuts-help.hbs b/server/sonar-web/src/main/js/main/nav/templates/nav-shortcuts-help.hbs index bfa98bc4495..2ef8a865b8b 100644 --- a/server/sonar-web/src/main/js/main/nav/templates/nav-shortcuts-help.hbs +++ b/server/sonar-web/src/main/js/main/nav/templates/nav-shortcuts-help.hbs @@ -23,21 +23,14 @@ -
-

{{t 'shortcuts.section.rules'}}

-
    -
  •    {{t 'shortcuts.section.rules.navigate_between_rules'}}
  • -
  •    {{t 'shortcuts.section.rules.open_details'}}
  • -
  •    {{t 'shortcuts.section.rules.return_to_list'}}
  • -
  • a    {{t 'shortcuts.section.rules.activate'}}
  • -
  • d    {{t 'shortcuts.section.rules.deactivate'}}
  • -
-
- -

{{t 'shortcuts.section.code'}}

+

{{t 'shortcuts.section.rules'}}

    -
  • t    {{t 'shortcuts.section.code.search'}}
  • +
  •    {{t 'shortcuts.section.rules.navigate_between_rules'}}
  • +
  •    {{t 'shortcuts.section.rules.open_details'}}
  • +
  •    {{t 'shortcuts.section.rules.return_to_list'}}
  • +
  • a    {{t 'shortcuts.section.rules.activate'}}
  • +
  • d    {{t 'shortcuts.section.rules.deactivate'}}
diff --git a/server/sonar-web/tests/apps/code/store-test.js b/server/sonar-web/tests/apps/code/store-test.js index fb54c02d32d..e8b36a58e4b 100644 --- a/server/sonar-web/tests/apps/code/store-test.js +++ b/server/sonar-web/tests/apps/code/store-test.js @@ -225,7 +225,7 @@ describe('Code :: Store', () => { it('should be reset', () => { const stateBefore = Object.assign({}, initialState, { searchQuery: 'query' }); expect(current(stateBefore, browseAction(exampleComponent)).searchQuery) - .to.be.null; + .to.equal(''); }); }); describe('errorMessage', () => { -- 2.39.5