From 7eea169d4aa159ad8615baa3dc4f1f70faf18366 Mon Sep 17 00:00:00 2001 From: Camille Moinier Date: Thu, 13 Jun 2024 14:13:04 +0200 Subject: [PATCH 1/3] feat: reset dropdown choices for map --- .../record/src/lib/state/mdview.facade.ts | 69 ++++++++++--------- 1 file changed, 38 insertions(+), 31 deletions(-) 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( From 22bcf5f89d58f286a5392e102b81ef81564256e5 Mon Sep 17 00:00:00 2001 From: Camille Moinier Date: Fri, 14 Jun 2024 11:13:56 +0200 Subject: [PATCH 2/3] feat: add UT and map loading while dropdown options load --- .../fixtures/src/lib/records.fixtures.ts | 8 ++++ .../src/lib/map-view/map-view.component.ts | 4 +- .../src/lib/state/mdview.facade.spec.ts | 40 +++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/libs/common/fixtures/src/lib/records.fixtures.ts b/libs/common/fixtures/src/lib/records.fixtures.ts index c193335ee6..317aedb08b 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/map-view/map-view.component.ts b/libs/feature/record/src/lib/map-view/map-view.component.ts index 87e40b8fd8..95f4f39c3a 100644 --- a/libs/feature/record/src/lib/map-view/map-view.component.ts +++ b/libs/feature/record/src/lib/map-view/map-view.component.ts @@ -64,6 +64,7 @@ export class MapViewComponent implements OnInit, OnDestroy { ) dropdownChoices$ = this.compatibleMapLinks$.pipe( + tap(() => (this.loading = true)), map((links) => links.length ? links.map((link, index) => ({ @@ -71,7 +72,8 @@ export class MapViewComponent implements OnInit, OnDestroy { value: index, })) : [{ label: 'No preview layer', value: 0 }] - ) + ), + finalize(() => (this.loading = false)) ) selectedLinkIndex$ = new BehaviorSubject(0) 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) + })) + }) }) }) From 2e6d828ca802f92bd2d1b14eb68cbd0fdd76d38d Mon Sep 17 00:00:00 2001 From: Camille Moinier Date: Mon, 17 Jun 2024 16:00:03 +0200 Subject: [PATCH 3/3] feat: remove this.loading as it has no effect --- libs/feature/record/src/lib/map-view/map-view.component.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libs/feature/record/src/lib/map-view/map-view.component.ts b/libs/feature/record/src/lib/map-view/map-view.component.ts index 95f4f39c3a..87e40b8fd8 100644 --- a/libs/feature/record/src/lib/map-view/map-view.component.ts +++ b/libs/feature/record/src/lib/map-view/map-view.component.ts @@ -64,7 +64,6 @@ export class MapViewComponent implements OnInit, OnDestroy { ) dropdownChoices$ = this.compatibleMapLinks$.pipe( - tap(() => (this.loading = true)), map((links) => links.length ? links.map((link, index) => ({ @@ -72,8 +71,7 @@ export class MapViewComponent implements OnInit, OnDestroy { value: index, })) : [{ label: 'No preview layer', value: 0 }] - ), - finalize(() => (this.loading = false)) + ) ) selectedLinkIndex$ = new BehaviorSubject(0)