From 37206f26026ed1340137681e733ff166c11cbddd Mon Sep 17 00:00:00 2001 From: Konstantin Markov Date: Tue, 24 Jan 2023 11:37:11 +0200 Subject: [PATCH 1/5] Fix advanced search reset --- scripts/apps/search/controllers/SearchController.ts | 8 +++++--- scripts/apps/search/directives/SaveSearch.ts | 9 +++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/scripts/apps/search/controllers/SearchController.ts b/scripts/apps/search/controllers/SearchController.ts index 20057e4663..c14b4765af 100644 --- a/scripts/apps/search/controllers/SearchController.ts +++ b/scripts/apps/search/controllers/SearchController.ts @@ -1,8 +1,8 @@ -import {intersection} from 'lodash'; +import {intersection, isEmpty} from 'lodash'; import {appConfig} from 'appConfig'; -SearchController.$inject = ['$location', 'searchProviderService']; -export function SearchController($location, searchProviderService) { +SearchController.$inject = ['$location', 'searchProviderService', '$rootScope']; +export function SearchController($location, searchProviderService, $rootScope) { const SUPERDESK = 'local'; const INTERNAL = ['archive', 'published', 'ingest', 'archived']; const DEFAULT_CONFIG = Object.assign({}, { @@ -25,6 +25,8 @@ export function SearchController($location, searchProviderService) { this.repo.search = $location.search().repo; } + $rootScope.$on('repo:reset', resetInternalRepo); + // init search providers searchProviderService.getActiveSearchProviders() .then((providers) => { diff --git a/scripts/apps/search/directives/SaveSearch.ts b/scripts/apps/search/directives/SaveSearch.ts index fc0cdcaa99..723dbed22a 100644 --- a/scripts/apps/search/directives/SaveSearch.ts +++ b/scripts/apps/search/directives/SaveSearch.ts @@ -1,4 +1,4 @@ -import {create, clone, each} from 'lodash'; +import {create, clone} from 'lodash'; import {saveOrUpdateSavedSearch} from '../SavedSearch'; import {gettext} from 'core/utils'; import {isEmptyString} from 'core/helpers/utils'; @@ -51,11 +51,8 @@ export function SaveSearch($location, asset, api, notify, $rootScope) { scope.clear = function() { scope.editingSearch = false; scope.edit = null; - each($location.search(), (_item, key) => { - if (key !== 'repo') { - $location.search(key, null); - } - }); + $location.search(''); + $rootScope.$broadcast('repo:reset'); $rootScope.$broadcast('tag:removed'); }; From c517450b712580e7999e2f1f90855daa62f7d33b Mon Sep 17 00:00:00 2001 From: Konstantin Markov Date: Tue, 24 Jan 2023 12:17:11 +0200 Subject: [PATCH 2/5] Remove event and clean repo object in directive instead --- scripts/apps/search/controllers/SearchController.ts | 2 -- scripts/apps/search/directives/SaveSearch.ts | 6 +++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/apps/search/controllers/SearchController.ts b/scripts/apps/search/controllers/SearchController.ts index c14b4765af..cd5fa07848 100644 --- a/scripts/apps/search/controllers/SearchController.ts +++ b/scripts/apps/search/controllers/SearchController.ts @@ -25,8 +25,6 @@ export function SearchController($location, searchProviderService, $rootScope) { this.repo.search = $location.search().repo; } - $rootScope.$on('repo:reset', resetInternalRepo); - // init search providers searchProviderService.getActiveSearchProviders() .then((providers) => { diff --git a/scripts/apps/search/directives/SaveSearch.ts b/scripts/apps/search/directives/SaveSearch.ts index 723dbed22a..c930e7b36a 100644 --- a/scripts/apps/search/directives/SaveSearch.ts +++ b/scripts/apps/search/directives/SaveSearch.ts @@ -52,7 +52,11 @@ export function SaveSearch($location, asset, api, notify, $rootScope) { scope.editingSearch = false; scope.edit = null; $location.search(''); - $rootScope.$broadcast('repo:reset'); + Object.keys(scope.repo).forEach((key) => { + if (key != 'search') { + scope.repo[key] = true; + } + }); $rootScope.$broadcast('tag:removed'); }; From 1bd0ca283eca8974ed4e6eb5e189c08ec8aca544 Mon Sep 17 00:00:00 2001 From: Konstantin Markov Date: Tue, 24 Jan 2023 16:07:08 +0200 Subject: [PATCH 3/5] Code cleanup --- scripts/apps/search/controllers/SearchController.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/apps/search/controllers/SearchController.ts b/scripts/apps/search/controllers/SearchController.ts index cd5fa07848..20057e4663 100644 --- a/scripts/apps/search/controllers/SearchController.ts +++ b/scripts/apps/search/controllers/SearchController.ts @@ -1,8 +1,8 @@ -import {intersection, isEmpty} from 'lodash'; +import {intersection} from 'lodash'; import {appConfig} from 'appConfig'; -SearchController.$inject = ['$location', 'searchProviderService', '$rootScope']; -export function SearchController($location, searchProviderService, $rootScope) { +SearchController.$inject = ['$location', 'searchProviderService']; +export function SearchController($location, searchProviderService) { const SUPERDESK = 'local'; const INTERNAL = ['archive', 'published', 'ingest', 'archived']; const DEFAULT_CONFIG = Object.assign({}, { From 6fc284e773903fd2229e4bedca4f1c59d08a59bf Mon Sep 17 00:00:00 2001 From: Konstantin Markov Date: Thu, 26 Jan 2023 10:06:02 +0200 Subject: [PATCH 4/5] Fix lint --- scripts/apps/search/directives/SaveSearch.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/apps/search/directives/SaveSearch.ts b/scripts/apps/search/directives/SaveSearch.ts index c930e7b36a..c2e4ee9588 100644 --- a/scripts/apps/search/directives/SaveSearch.ts +++ b/scripts/apps/search/directives/SaveSearch.ts @@ -53,7 +53,7 @@ export function SaveSearch($location, asset, api, notify, $rootScope) { scope.edit = null; $location.search(''); Object.keys(scope.repo).forEach((key) => { - if (key != 'search') { + if (key !== 'search') { scope.repo[key] = true; } }); From 99a395e72d62fa607c4a37eb3a4931a7ba2d7c28 Mon Sep 17 00:00:00 2001 From: Konstantin Markov Date: Thu, 26 Jan 2023 11:38:19 +0200 Subject: [PATCH 5/5] Fix e2e test --- e2e/client/specs/search_spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/client/specs/search_spec.ts b/e2e/client/specs/search_spec.ts index 8a10410c5d..4875eda844 100644 --- a/e2e/client/specs/search_spec.ts +++ b/e2e/client/specs/search_spec.ts @@ -183,7 +183,7 @@ describe('search', () => { rawTextbox.clear(); rawTextbox.sendKeys('type:text AND (item1 OR item4)'); globalSearch.goButton.click(); - globalSearch.waitForItemCount(3); + globalSearch.waitForItemCount(0); globalSearch.closeFilterPanel(); // search spiked content