From 5e4ba397c37b0f52b7bc4b29c3c2eb8f9f138fb4 Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Fri, 13 Dec 2024 12:11:00 +0100 Subject: [PATCH 1/2] fix(search-filters-summary): ignore search field value in reset button --- .../search-filters-summary.component.spec.ts | 7 ++++++- .../search-filters-summary.component.ts | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libs/feature/search/src/lib/search-filters-summary/search-filters-summary.component.spec.ts b/libs/feature/search/src/lib/search-filters-summary/search-filters-summary.component.spec.ts index 8056ac459..f5854b17c 100644 --- a/libs/feature/search/src/lib/search-filters-summary/search-filters-summary.component.spec.ts +++ b/libs/feature/search/src/lib/search-filters-summary/search-filters-summary.component.spec.ts @@ -13,6 +13,7 @@ import { FieldFilters } from '@geonetwork-ui/common/domain/model/search' class SearchFacadeMock { searchFilters$ = new BehaviorSubject({ + any: 'search should be ignored', format: {}, isSpatial: {}, license: {}, @@ -94,7 +95,9 @@ describe('SearchFiltersSummaryComponent', () => { it('should clear filters', () => { component.clearFilters() - expect(searchService.setFilters).toHaveBeenCalledWith({}) + expect(searchService.setFilters).toHaveBeenCalledWith({ + any: 'search should be ignored', + }) }) }) @@ -139,6 +142,7 @@ describe('SearchFiltersSummaryComponent', () => { it('should clear filters except with keys from FILTER_SUMMARY_IGNORE_LIST', () => { const filters = { owner: { 1: true }, + any: 'search should be ignored', format: {}, isSpatial: {}, license: {}, @@ -150,6 +154,7 @@ describe('SearchFiltersSummaryComponent', () => { component.clearFilters() expect(searchService.setFilters).toHaveBeenCalledWith({ owner: { 1: true }, + any: 'search should be ignored', }) }) }) diff --git a/libs/feature/search/src/lib/search-filters-summary/search-filters-summary.component.ts b/libs/feature/search/src/lib/search-filters-summary/search-filters-summary.component.ts index c4318f8f7..3a7ed26c4 100644 --- a/libs/feature/search/src/lib/search-filters-summary/search-filters-summary.component.ts +++ b/libs/feature/search/src/lib/search-filters-summary/search-filters-summary.component.ts @@ -47,6 +47,7 @@ export class SearchFiltersSummaryComponent implements OnInit { filteredFilters[key] = value } } + delete filteredFilters['any'] //ignore search field return Object.values(filteredFilters).some( (value) => value !== undefined && @@ -62,7 +63,7 @@ export class SearchFiltersSummaryComponent implements OnInit { map((filters) => { const newFilters = { ...filters } Object.keys(newFilters).forEach((key) => { - if (!this.filterSummaryIgnoreList.includes(key)) { + if (!this.filterSummaryIgnoreList.includes(key) && key !== 'any') { delete newFilters[key] } }) From dca5437ef26479ec4c78d7db51bcf104e2ea3b83 Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Mon, 16 Dec 2024 17:06:49 +0100 Subject: [PATCH 2/2] refactor(search-filters-summary): ignore 'any' via ignoreList --- .../search-filters-summary.component.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libs/feature/search/src/lib/search-filters-summary/search-filters-summary.component.ts b/libs/feature/search/src/lib/search-filters-summary/search-filters-summary.component.ts index 3a7ed26c4..590256704 100644 --- a/libs/feature/search/src/lib/search-filters-summary/search-filters-summary.component.ts +++ b/libs/feature/search/src/lib/search-filters-summary/search-filters-summary.component.ts @@ -31,7 +31,11 @@ export class SearchFiltersSummaryComponent implements OnInit { @Inject(FILTER_SUMMARY_IGNORE_LIST) filterSummaryIgnoreList: string[] ) { - this.filterSummaryIgnoreList = filterSummaryIgnoreList || [] + const defaultIgnoreList = ['any'] + this.filterSummaryIgnoreList = [ + ...defaultIgnoreList, + ...(filterSummaryIgnoreList ?? []), + ] } ngOnInit(): void { @@ -47,7 +51,6 @@ export class SearchFiltersSummaryComponent implements OnInit { filteredFilters[key] = value } } - delete filteredFilters['any'] //ignore search field return Object.values(filteredFilters).some( (value) => value !== undefined && @@ -63,7 +66,7 @@ export class SearchFiltersSummaryComponent implements OnInit { map((filters) => { const newFilters = { ...filters } Object.keys(newFilters).forEach((key) => { - if (!this.filterSummaryIgnoreList.includes(key) && key !== 'any') { + if (!this.filterSummaryIgnoreList.includes(key)) { delete newFilters[key] } })