Skip to content

Commit

Permalink
Merge pull request #798 from geonetwork/no-geom-no-error
Browse files Browse the repository at this point in the history
Datahub: Remove warning from console if filter geometry undefined
  • Loading branch information
tkohr committed Feb 21, 2024
2 parents ca02804 + 696ca82 commit ae0a63a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
15 changes: 15 additions & 0 deletions libs/feature/search/src/lib/state/effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,21 @@ describe('Effects', () => {
)
})
})
describe('when geometry is undefined', () => {
beforeEach(() => {
effects['filterGeometry$'] = of(undefined) as any
effects = TestBed.inject(SearchEffects)
actions$ = of(new RequestMoreResults('main'))
})
it('skips the geometry in the search', async () => {
await firstValueFrom(effects.loadResults$)
expect(repository.search).toHaveBeenCalledWith(
expect.objectContaining({
filterGeometry: undefined,
})
)
})
})
})
describe('when useSpatialFilter is disabled', () => {
beforeEach(() => {
Expand Down
7 changes: 4 additions & 3 deletions libs/feature/search/src/lib/state/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ export class SearchEffects {
),
switchMap(([state, favorites]) => {
if (!state.params.useSpatialFilter || !this.filterGeometry$) {
return of([state, favorites, null])
return of([state, favorites, undefined])
}
return this.filterGeometry$.pipe(
tap((geom) => {
if (!geom) return
try {
const trace = validGeoJson(geom, true) as string[]
if (trace?.length > 0) {
Expand All @@ -145,15 +146,15 @@ export class SearchEffects {
}),
map((geom) => [state, favorites, geom]),
catchError((e) => {
return of([state, favorites, null])
return of([state, favorites, undefined])
})
)
}),
switchMap(
([state, favorites, geometry]: [
SearchStateSearch,
string[],
Geometry | null
Geometry | undefined
]) => {
const { currentPage, pageSize, sort } = state.params
const filters = {
Expand Down

0 comments on commit ae0a63a

Please sign in to comment.