From 9a36960708931efcde163a0f27d5599430ac1c01 Mon Sep 17 00:00:00 2001 From: Camille Moinier Date: Thu, 14 Sep 2023 13:06:32 +0200 Subject: [PATCH 1/4] fix(datahub): custom filter btn fix for sorting param --- .../src/app/home/home-header/home-header.component.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/apps/datahub/src/app/home/home-header/home-header.component.ts b/apps/datahub/src/app/home/home-header/home-header.component.ts index db8c8e7954..73592cc3aa 100644 --- a/apps/datahub/src/app/home/home-header/home-header.component.ts +++ b/apps/datahub/src/app/home/home-header/home-header.component.ts @@ -20,9 +20,9 @@ import { import { SortByEnum, SortByField } from '@geonetwork-ui/common/domain/search' import { map } from 'rxjs/operators' import { ROUTER_ROUTE_NEWS } from '../../router/constants' -import { lastValueFrom } from 'rxjs' +import { firstValueFrom, lastValueFrom } from 'rxjs' import { CatalogRecord } from '@geonetwork-ui/common/domain/record' -import { sortByFromString } from '@geonetwork-ui/util/shared' +import { sortByToString } from '@geonetwork-ui/util/shared' marker('datahub.header.myfavorites') marker('datahub.header.lastRecords') @@ -84,9 +84,7 @@ export class HomeHeaderComponent { customSearchParameters.filters ) ) - this.searchService.setSortAndFilters( - searchFilters, - sortByFromString(customSearchParameters.sort) - ) + const sortBy = await firstValueFrom(this.searchFacade.sortBy$) + this.searchService.setSortAndFilters(searchFilters, sortBy) } } From db74690007b480dbf8adda77e494263c3e5be9bd Mon Sep 17 00:00:00 2001 From: Camille Moinier Date: Thu, 14 Sep 2023 15:01:13 +0200 Subject: [PATCH 2/4] fix(datahub): add mock to home header test --- .../src/app/home/home-header/home-header.component.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/datahub/src/app/home/home-header/home-header.component.spec.ts b/apps/datahub/src/app/home/home-header/home-header.component.spec.ts index 0982f0315f..6d32a51734 100644 --- a/apps/datahub/src/app/home/home-header/home-header.component.spec.ts +++ b/apps/datahub/src/app/home/home-header/home-header.component.spec.ts @@ -61,6 +61,7 @@ class routerFacadeMock { class searchFacadeMock { setFavoritesOnly = jest.fn() setSortBy = jest.fn() + sortBy$ = new BehaviorSubject(['desc', 'createDate']) } class searchServiceMock { From b3c719c259da04dbe09386843d2d0bc497321cfb Mon Sep 17 00:00:00 2001 From: Camille Moinier Date: Wed, 20 Sep 2023 17:10:48 +0200 Subject: [PATCH 3/4] feat: make sort param optionnal --- .../src/app/home/home-header/home-header.component.ts | 10 +++++++--- conf/default.toml | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/apps/datahub/src/app/home/home-header/home-header.component.ts b/apps/datahub/src/app/home/home-header/home-header.component.ts index 73592cc3aa..5ef3aeb0f5 100644 --- a/apps/datahub/src/app/home/home-header/home-header.component.ts +++ b/apps/datahub/src/app/home/home-header/home-header.component.ts @@ -22,7 +22,7 @@ import { map } from 'rxjs/operators' import { ROUTER_ROUTE_NEWS } from '../../router/constants' import { firstValueFrom, lastValueFrom } from 'rxjs' import { CatalogRecord } from '@geonetwork-ui/common/domain/record' -import { sortByToString } from '@geonetwork-ui/util/shared' +import { sortByFromString } from '@geonetwork-ui/util/shared' marker('datahub.header.myfavorites') marker('datahub.header.lastRecords') @@ -84,7 +84,11 @@ export class HomeHeaderComponent { customSearchParameters.filters ) ) - const sortBy = await firstValueFrom(this.searchFacade.sortBy$) - this.searchService.setSortAndFilters(searchFilters, sortBy) + if (customSearchParameters.sort) { + const sortBy = sortByFromString(customSearchParameters.sort[0]) + this.searchService.setSortAndFilters(searchFilters, sortBy) + } else { + this.searchService.setFilters(searchFilters) + } } } diff --git a/conf/default.toml b/conf/default.toml index 44903cbe7f..8788371b6f 100644 --- a/conf/default.toml +++ b/conf/default.toml @@ -75,7 +75,7 @@ background_color = "#fdfbff" # One or several search presets can be defined here; every search preset is composed of: # - a name (which can be a translation key) -# - a sort criteria: either `createDate`, `userSavedCount` or `_score` (prepend with `-` for descending sort) +# - a sort criteria: either `createDate`, `userSavedCount` or `_score` (prepend with `-` for descending sort) (optionnal) # - filters which can be expressed like so: # [[search_preset]] # name = 'filterByName' @@ -88,6 +88,7 @@ background_color = "#fdfbff" # filters.publicationYear = ['2023', '2022'] # filters.isSpatial = ['yes'] # filters.license = ['unknown'] +# sort = ['createDate'] # [[search_preset]] # name = 'otherFilterName' # filters.q = 'Other Full text search' From 4d1c3c588da7f732baa62318a3ce7fe1433afc30 Mon Sep 17 00:00:00 2001 From: Camille Moinier Date: Wed, 20 Sep 2023 17:27:33 +0200 Subject: [PATCH 4/4] fix: impacted tests --- .../home-header/home-header.component.spec.ts | 37 +++++++++++++------ .../home/home-header/home-header.component.ts | 2 +- conf/default.toml | 2 +- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/apps/datahub/src/app/home/home-header/home-header.component.spec.ts b/apps/datahub/src/app/home/home-header/home-header.component.spec.ts index 6d32a51734..5c8ba2afb4 100644 --- a/apps/datahub/src/app/home/home-header/home-header.component.spec.ts +++ b/apps/datahub/src/app/home/home-header/home-header.component.spec.ts @@ -34,7 +34,6 @@ jest.mock('@geonetwork-ui/util/app-config', () => { filters: { publisher: ['DREAL'] }, }, { - sort: 'title', name: 'filterCarto', filters: { q: 'Cartographie' }, }, @@ -69,6 +68,7 @@ class searchServiceMock { setSearch = jest.fn() setSortBy = jest.fn() setSortAndFilters = jest.fn() + setFilters = jest.fn() } class AuthServiceMock { @@ -234,17 +234,32 @@ describe('HeaderComponent', () => { const allBadges = fixture.debugElement.queryAll(By.css('.badge-btn')) expect(allBadges.length).toBe(4) }) - beforeEach(() => { - const firstCustomBadge = fixture.debugElement.queryAll( - By.css('.badge-btn') - )[2] - firstCustomBadge.nativeElement.click() + describe('when sort is defined', () => { + beforeEach(() => { + const firstCustomBadge = fixture.debugElement.queryAll( + By.css('.badge-btn') + )[2] + firstCustomBadge.nativeElement.click() + }) + it('should redirect correctly', () => { + expect(searchService.setSortAndFilters).toHaveBeenCalledWith( + { thisIs: 'a fake filter' }, + SortByEnum.CREATE_DATE + ) + }) }) - it('should redirect correctly', () => { - expect(searchService.setSortAndFilters).toHaveBeenCalledWith( - { thisIs: 'a fake filter' }, - SortByEnum.CREATE_DATE - ) + describe('when sort is not defined', () => { + beforeEach(() => { + const secondCustomBadge = fixture.debugElement.queryAll( + By.css('.badge-btn') + )[3] + secondCustomBadge.nativeElement.click() + }) + it('should redirect correctly', () => { + expect(searchService.setFilters).toHaveBeenCalledWith({ + thisIs: 'a fake filter', + }) + }) }) }) diff --git a/apps/datahub/src/app/home/home-header/home-header.component.ts b/apps/datahub/src/app/home/home-header/home-header.component.ts index 5ef3aeb0f5..ce3093a834 100644 --- a/apps/datahub/src/app/home/home-header/home-header.component.ts +++ b/apps/datahub/src/app/home/home-header/home-header.component.ts @@ -85,7 +85,7 @@ export class HomeHeaderComponent { ) ) if (customSearchParameters.sort) { - const sortBy = sortByFromString(customSearchParameters.sort[0]) + const sortBy = sortByFromString(customSearchParameters.sort) this.searchService.setSortAndFilters(searchFilters, sortBy) } else { this.searchService.setFilters(searchFilters) diff --git a/conf/default.toml b/conf/default.toml index 8788371b6f..830ec315c1 100644 --- a/conf/default.toml +++ b/conf/default.toml @@ -88,7 +88,7 @@ background_color = "#fdfbff" # filters.publicationYear = ['2023', '2022'] # filters.isSpatial = ['yes'] # filters.license = ['unknown'] -# sort = ['createDate'] +# sort = 'createDate' # [[search_preset]] # name = 'otherFilterName' # filters.q = 'Other Full text search'