diff --git a/libs/common/fixtures/src/lib/records.fixtures.ts b/libs/common/fixtures/src/lib/records.fixtures.ts index 3e7177423a..cc08efd8e3 100644 --- a/libs/common/fixtures/src/lib/records.fixtures.ts +++ b/libs/common/fixtures/src/lib/records.fixtures.ts @@ -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.`, diff --git a/libs/feature/record/src/lib/state/mdview.facade.spec.ts b/libs/feature/record/src/lib/state/mdview.facade.spec.ts index 24957eea0c..dbfe53f427 100644 --- a/libs/feature/record/src/lib/state/mdview.facade.spec.ts +++ b/libs/feature/record/src/lib/state/mdview.facade.spec.ts @@ -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) + })) + }) }) }) diff --git a/libs/feature/record/src/lib/state/mdview.facade.ts b/libs/feature/record/src/lib/state/mdview.facade.ts index 814b6a7dcd..c979cce049 100644 --- a/libs/feature/record/src/lib/state/mdview.facade.ts +++ b/libs/feature/record/src/lib/state/mdview.facade.ts @@ -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' @@ -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(