From f0938cf17c2ecd9a42d977b7c6aba849ace558f7 Mon Sep 17 00:00:00 2001 From: JamesHawking Date: Tue, 26 Sep 2017 15:01:04 +0200 Subject: [PATCH 1/3] XW-4026 | Fix for failing test --- app/components/wikia-search.js | 21 ++++++--------------- app/controllers/search.js | 21 ++------------------- 2 files changed, 8 insertions(+), 34 deletions(-) diff --git a/app/components/wikia-search.js b/app/components/wikia-search.js index 815363fd827..b0502b769a1 100644 --- a/app/components/wikia-search.js +++ b/app/components/wikia-search.js @@ -41,7 +41,6 @@ export default Component.extend( inputFocused: false, // Whether or not to display the loading search suggestion results message (en: 'Loading...') isLoadingResultsSuggestions: false, - phrase: '', phraseMinimalLength: 3, query: '', /** @@ -64,10 +63,7 @@ export default Component.extend( emptyPhraseInput: computed.not('phrase'), hasSuggestions: computed.notEmpty('suggestions'), noScroll: computed.oneWay('hasSuggestions'), - queryObserver: observer('query', function () { - // ensures that phrase is changed according to external change - this.set('phrase', this.get('query')); - }), + phrase: Ember.computed.oneWay('query'), searchPlaceholderLabel: computed(function () { return this.get('i18n').t('search:main.search-input-label'); }), @@ -75,15 +71,10 @@ export default Component.extend( didInsertElement() { this._super(...arguments); - run.scheduleOnce('afterRender', this, () => { - // initialize with query - this.set('phrase', this.get('query')); - this.set('inputField', $('.side-search__input')); + if (this.get('focusInput')) { + this.$('.side-search__input').focus(); + } - if (this.get('focusInput')) { - this.get('inputField').focus(); - } - }); }, actions: { @@ -94,7 +85,7 @@ export default Component.extend( label: 'search-open-special-search' }); - this.get('inputField').blur(); + this.$('.side-search__input').blur(); this.set('searchRequestInProgress', true); this.setSearchSuggestionItems(); this.get('onEnterHandler')(value); @@ -103,7 +94,7 @@ export default Component.extend( clearSearch() { this.set('phrase', ''); - this.get('inputField').focus(); + this.$('.side-search__input').focus(); }, searchSuggestionClick() { diff --git a/app/controllers/search.js b/app/controllers/search.js index b80234cc29a..9d89d02d456 100644 --- a/app/controllers/search.js +++ b/app/controllers/search.js @@ -5,7 +5,6 @@ const { computed, inject, $, - run } = Ember; export default Controller.extend({ @@ -14,23 +13,7 @@ export default Controller.extend({ // TODO: to be removed as we'll be supporting more errors on search page, // see: https://wikia-inc.atlassian.net/browse/DAT-4324 notFoundError: computed.equal('model.error', 'search-error-not-found'), - - init() { - /* - yes, we have the same function in two places (here and in wikia-search component). - This was the best solution, as wikia-search component had to have implemented this function - as well (because is used also in other contexts). We cannot pass actions from controllers - to components (DDAU). Observing for certain property passed from controller to component - wouldn't be clean solution as well. - */ - run.scheduleOnce('afterRender', this, () => { - this.set('inputPhrase', this.get('query')); - - if (!this.get('fastboot.isFastBoot')) { - this.set('inputField', $('.side-search__input')); - } - }); - }, + inputPhrase: computed.alias('query'), actions: { onSearchEnter(query) { @@ -40,7 +23,7 @@ export default Controller.extend({ onErrorPageClick() { this.set('inputPhrase', ''); - this.get('inputField').focus(); + $('.side-search__input').focus(); }, onLoadMore() { From 3736a8e81fddfa858cb55313c8b0ca4e37ddacac Mon Sep 17 00:00:00 2001 From: JamesHawking Date: Tue, 26 Sep 2017 15:18:13 +0200 Subject: [PATCH 2/3] XW-4026 | Fix for input search --- app/components/wikia-search.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/components/wikia-search.js b/app/components/wikia-search.js index b0502b769a1..834fc24ea48 100644 --- a/app/components/wikia-search.js +++ b/app/components/wikia-search.js @@ -64,6 +64,7 @@ export default Component.extend( hasSuggestions: computed.notEmpty('suggestions'), noScroll: computed.oneWay('hasSuggestions'), phrase: Ember.computed.oneWay('query'), + $searchInputElement: this.$('.side-search__input'), searchPlaceholderLabel: computed(function () { return this.get('i18n').t('search:main.search-input-label'); }), @@ -72,7 +73,7 @@ export default Component.extend( this._super(...arguments); if (this.get('focusInput')) { - this.$('.side-search__input').focus(); + this.get('$searchInputElement').focus(); } }, @@ -85,7 +86,7 @@ export default Component.extend( label: 'search-open-special-search' }); - this.$('.side-search__input').blur(); + this.get('$searchInputElement').blur(); this.set('searchRequestInProgress', true); this.setSearchSuggestionItems(); this.get('onEnterHandler')(value); @@ -94,7 +95,7 @@ export default Component.extend( clearSearch() { this.set('phrase', ''); - this.$('.side-search__input').focus(); + this.get('$searchInputElement').focus(); }, searchSuggestionClick() { From ca88d1d2df4b974e65242e295b6e8bdb44a02388 Mon Sep 17 00:00:00 2001 From: JamesHawking Date: Tue, 26 Sep 2017 15:23:31 +0200 Subject: [PATCH 3/3] XW-4026 | Selector assigned to property --- app/components/wikia-search.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/components/wikia-search.js b/app/components/wikia-search.js index 834fc24ea48..185e50295c2 100644 --- a/app/components/wikia-search.js +++ b/app/components/wikia-search.js @@ -59,12 +59,12 @@ export default Component.extend( i18n: inject.service(), logger: inject.service(), wikiVariables: inject.service(), - + inputSearchSelector: '.side-search__input', emptyPhraseInput: computed.not('phrase'), hasSuggestions: computed.notEmpty('suggestions'), noScroll: computed.oneWay('hasSuggestions'), phrase: Ember.computed.oneWay('query'), - $searchInputElement: this.$('.side-search__input'), + searchPlaceholderLabel: computed(function () { return this.get('i18n').t('search:main.search-input-label'); }), @@ -73,7 +73,7 @@ export default Component.extend( this._super(...arguments); if (this.get('focusInput')) { - this.get('$searchInputElement').focus(); + this.$(this.get('inputSearchSelector')).focus(); } }, @@ -86,7 +86,7 @@ export default Component.extend( label: 'search-open-special-search' }); - this.get('$searchInputElement').blur(); + this.$(this.get('inputSearchSelector')).blur(); this.set('searchRequestInProgress', true); this.setSearchSuggestionItems(); this.get('onEnterHandler')(value); @@ -95,7 +95,7 @@ export default Component.extend( clearSearch() { this.set('phrase', ''); - this.get('$searchInputElement').focus(); + this.$(this.get('inputSearchSelector')).focus(); }, searchSuggestionClick() {