Skip to content

Commit

Permalink
Merge pull request #900 from geonetwork/fix-map-reset
Browse files Browse the repository at this point in the history
[Fix]: Reset map dropdown links
  • Loading branch information
cmoinier authored Jun 17, 2024
2 parents e8fc61c + 05c1efb commit e1bb65c
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 31 deletions.
8 changes: 8 additions & 0 deletions libs/common/fixtures/src/lib/records.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ Malgré l'attention portée à la création de ces données, il est rappelé que
description: 'Téléchargement du fichier',
mimeType: 'x-gis/x-shapefile',
},
{
type: 'service',
url: new URL('https://my-org.net/ogc'),
accessServiceProtocol: 'ogcFeatures',
name: 'ogcFeaturesSecondRecord',
description: 'This OGC service is the second part of the download',
identifierInService: 'my:featuretype',
},
],
lineage: `Document d’urbanisme numérisé conformément aux prescriptions nationales du CNIG par le Service d'Information Géographique de l'Agglomération de la Région de Compiègne.
Ce lot de données produit en 2019, a été numérisé à partir du PCI Vecteur de 2019 et contrôlé par le Service d'Information Géographique de l'Agglomération de la Région de Compiègne.`,
Expand Down
40 changes: 40 additions & 0 deletions libs/feature/record/src/lib/state/mdview.facade.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,5 +328,45 @@ describe('MdViewFacade', () => {
tick()
expect(result).toEqual(values.a)
}))
describe('When the user switches datasets and allLinks emits again', () => {
beforeEach(() => {
store.setState({
[METADATA_VIEW_FEATURE_STATE_KEY]: {
...initialMetadataViewState,
metadata: DATASET_RECORDS[1],
},
})
})
it('should return only the last links from allLinks', fakeAsync(() => {
const values = {
a: [
{
type: 'service',
url: new URL('https://my-org.net/ogc'),
accessServiceProtocol: 'ogcFeatures',
name: 'ogcFeaturesSecondRecord',
description:
'This OGC service is the second part of the download',
identifierInService: 'my:featuretype',
},
],
}
jest.spyOn(facade.dataService, 'getItemsFromOgcApi').mockResolvedValue({
id: '123',
type: 'Feature',
time: null,
properties: {
type: '',
title: '',
},
links: [],
geometry: { type: 'MultiPolygon', coordinates: [] },
})
let result
facade.geoDataLinksWithGeometry$.subscribe((v) => (result = v))
tick()
expect(result).toEqual(values.a)
}))
})
})
})
69 changes: 38 additions & 31 deletions libs/feature/record/src/lib/state/mdview.facade.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { Injectable } from '@angular/core'
import { select, Store } from '@ngrx/store'
import { defaultIfEmpty, filter, map, mergeMap, scan } from 'rxjs/operators'
import {
defaultIfEmpty,
filter,
map,
mergeMap,
scan,
switchMap,
toArray,
} from 'rxjs/operators'
import * as MdViewActions from './mdview.actions'
import * as MdViewSelectors from './mdview.selectors'
import { LinkClassifierService, LinkUsage } from '@geonetwork-ui/util/shared'
Expand Down Expand Up @@ -95,36 +103,35 @@ export class MdViewFacade {
)

geoDataLinksWithGeometry$ = this.allLinks$.pipe(
mergeMap((links) => {
return from(links)
}),
mergeMap((link) => {
if (this.linkClassifier.hasUsage(link, LinkUsage.GEODATA)) {
if (
link.type === 'service' &&
link.accessServiceProtocol === 'ogcFeatures'
) {
return from(this.dataService.getItemsFromOgcApi(link.url.href)).pipe(
map((collectionRecords: OgcApiRecord) => {
return collectionRecords && collectionRecords.geometry
? link
: null
}),
defaultIfEmpty(null)
)
} else {
return of(link)
}
} else {
return of(null)
}
}),
scan((acc, val) => {
if (val !== null && !acc.includes(val)) {
acc.push(val)
}
return acc
}, [])
switchMap((links) =>
from(links).pipe(
mergeMap((link) => {
if (this.linkClassifier.hasUsage(link, LinkUsage.GEODATA)) {
if (
link.type === 'service' &&
link.accessServiceProtocol === 'ogcFeatures'
) {
return from(
this.dataService.getItemsFromOgcApi(link.url.href)
).pipe(
map((collectionRecords: OgcApiRecord) => {
return collectionRecords && collectionRecords.geometry
? link
: null
}),
defaultIfEmpty(null)
)
} else {
return of(link)
}
} else {
return of(null)
}
}),
toArray(),
map((links) => links.filter((link) => link !== null))
)
)
)

landingPageLinks$ = this.metadata$.pipe(
Expand Down

0 comments on commit e1bb65c

Please sign in to comment.