From 244464b74d270c895dc4a78801234b2e2814c8eb Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Fri, 16 Sep 2016 08:08:15 -0600 Subject: [PATCH] Behavioral fixes to Magic-Search MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issues fixed: * Fixes issue where text entry is borked when clicking to make a new facet * No ‘x’ icon when text search only * Text search, then click “x”, text search NOT removed and search result not updated * Text search, then click facet, text hidden but still used * Text search, then select a facet, hit main “x”, only facet removed, text search NOT removed * text search, enter to make text facet, then “x”, then select a “Type” “Image” facet, then the text facet reappears, then “x” again and Image facet cleared but text facet remains Change-Id: I3f00836684fade0f1050d180a44924af48e3d868 Closes-Bug: 1628588 --- .../magic-search/magic-search.controller.js | 19 ++++++++++++------- .../magic-search.controller.spec.js | 7 ------- .../widgets/magic-search/magic-search.html | 2 +- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/horizon/static/framework/widgets/magic-search/magic-search.controller.js b/horizon/static/framework/widgets/magic-search/magic-search.controller.js index a340054269..331ba869da 100644 --- a/horizon/static/framework/widgets/magic-search/magic-search.controller.js +++ b/horizon/static/framework/widgets/magic-search/magic-search.controller.js @@ -269,6 +269,12 @@ ctrl.filteredOptions = ctrl.facetOptions = facet.options; setMenuOpen(true); } + var searchVal = searchInput.val(); + if (searchVal) { + ctrl.currentSearch = ctrl.currentSearch.filter(notTextSearch); + ctrl.currentSearch.push(service.getTextFacet(searchVal, $scope.strings.text)); + ctrl.textSearch = searchVal; + } setSearchInput(''); setPrompt(''); $timeout(function() { @@ -310,13 +316,12 @@ } function clearSearch() { - if (ctrl.currentSearch.length > 0) { - ctrl.currentSearch = []; - ctrl.unusedFacetChoices = ctrl.facetChoices.map(service.getFacetChoice); - resetState(); - $scope.$emit(magicSearchEvents.SEARCH_UPDATED, ''); - emitTextSearch(''); - } + ctrl.currentSearch = []; + delete ctrl.textSearch; + ctrl.unusedFacetChoices = ctrl.facetChoices.map(service.getFacetChoice); + resetState(); + $scope.$emit(magicSearchEvents.SEARCH_UPDATED, ''); + emitTextSearch(''); } function resetState() { diff --git a/horizon/static/framework/widgets/magic-search/magic-search.controller.spec.js b/horizon/static/framework/widgets/magic-search/magic-search.controller.spec.js index 4871264724..9eab8f108a 100644 --- a/horizon/static/framework/widgets/magic-search/magic-search.controller.spec.js +++ b/horizon/static/framework/widgets/magic-search/magic-search.controller.spec.js @@ -125,13 +125,6 @@ describe("clearSearch", function() { - it("does nothing when currentSearch is empty", function() { - spyOn(scope, '$emit'); - ctrl.currentSearch = []; - ctrl.clearSearch(); - expect(scope.$emit).not.toHaveBeenCalled(); - }); - it("clears the currentSearch when currentSearch is not empty", function() { spyOn(scope, '$emit'); ctrl.currentSearch = ['a', 'b', 'c']; diff --git a/horizon/static/framework/widgets/magic-search/magic-search.html b/horizon/static/framework/widgets/magic-search/magic-search.html index d4d970b0e0..c96e67c859 100644 --- a/horizon/static/framework/widgets/magic-search/magic-search.html +++ b/horizon/static/framework/widgets/magic-search/magic-search.html @@ -45,7 +45,7 @@ - +