From eb5fd35e0a8f59b01990bd4d05747293816f0230 Mon Sep 17 00:00:00 2001 From: Arthur Belkhayat Date: Mon, 5 Feb 2024 09:02:40 +0100 Subject: [PATCH] fix: auto research navigation orientation to cartographie (#448) * fix: auto research navigation orientation to cartographie * fix: delete import not use * feat: use id of research instead of type for more accuracy * fix: test with adresse ids --- .../user-location/user-location.component.ts | 16 +++++++++++++--- .../data/http/address/address.http.spec.ts | 2 ++ .../adresse/data/http/address/address.http.ts | 2 ++ .../adresse/data/transfers/address.transfer.ts | 1 + src/features/adresse/models/address.ts | 1 + .../presenters/address/address.presenter.spec.ts | 4 ++++ .../presenters/address/address.presenter.ts | 1 + .../address/result-found.presentation.ts | 1 + .../cartographie/cartographie.layout.html | 8 +++++--- .../layouts/cartographie/cartographie.layout.ts | 10 ++++++++-- .../data/http/conseillers/conseillers.http.ts | 1 + .../core/presenters/filter/filter.presenter.ts | 3 +++ .../lieux-mediation-numerique.presenter.spec.ts | 4 ++++ .../lieux-mediation-numerique.presenter.ts | 1 + .../pages/localisation/localisation.page.ts | 1 + 15 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/features/adresse/components/user-location/user-location.component.ts b/src/features/adresse/components/user-location/user-location.component.ts index 10357789..ca4c8f3c 100644 --- a/src/features/adresse/components/user-location/user-location.component.ts +++ b/src/features/adresse/components/user-location/user-location.component.ts @@ -26,6 +26,11 @@ const SEARCH_DEBOUNCE_TIME: number = 300; const setZoomUserPosition = (defaultUserPosition: number, distance?: number): number => distance ? (distance >= 50000 && distance <= 100000 ? 8 : 10) : defaultUserPosition; +const findAddressById = ( + addresses: ResultFoundPresentation<{ type: AddressType }>[], + id?: string +): ResultFoundPresentation<{ type: AddressType }> | undefined => addresses.find((address) => address.id === id); + @Component({ changeDetection: ChangeDetectionStrategy.OnPush, selector: 'app-user-location', @@ -34,6 +39,8 @@ const setZoomUserPosition = (defaultUserPosition: number, distance?: number): nu export class UserLocationComponent implements OnInit { @Input() adresse?: string; + @Input() adresseId?: string; + @Input() fullWidth: boolean = false; @Input() placeholder: string = 'Entrez une adresse'; @@ -82,9 +89,12 @@ export class UserLocationComponent implements OnInit { map((resultsToCombine: ResultFoundPresentation<{ type: AddressType }>[][]) => resultsToCombine.flat()), tap( (addressesFound: ResultFoundPresentation<{ type: AddressType }>[]) => - addressesFound[0] && this.onSelected(addressesFound[0]) + addressesFound && this.onSelected(findAddressById(addressesFound, this.adresseId) || addressesFound[0]) ), - map((addressesFound: ResultFoundPresentation<{ type: AddressType }>[]) => addressesFound[0]?.label) + map( + (addressesFound: ResultFoundPresentation<{ type: AddressType }>[]) => + findAddressById(addressesFound, this.adresseId)?.label || addressesFound[0].label + ) ); @Output() public resultFound: EventEmitter> = new EventEmitter< @@ -129,7 +139,7 @@ export class UserLocationComponent implements OnInit { localisation, setZoomUserPosition(this._zoomLevel.userPosition, parseInt(this.route.snapshot.queryParams['distance'])) ); - this.resultFound.emit({ context: '', label: '', localisation, payload: { type: 'user' } }); + this.resultFound.emit({ id: '', context: '', label: '', localisation, payload: { type: 'user' } }); this._loadingState$.next(false); this._displayGeolocation$.next(false); diff --git a/src/features/adresse/data/http/address/address.http.spec.ts b/src/features/adresse/data/http/address/address.http.spec.ts index bc784574..84f1dfb7 100644 --- a/src/features/adresse/data/http/address/address.http.spec.ts +++ b/src/features/adresse/data/http/address/address.http.spec.ts @@ -18,6 +18,7 @@ describe('address http', (): void => { coordinates: [4.8375548, 45.7665478] }, properties: { + id: 'addressTransferId', context: '80, Somme, Hauts-de-France', label: '8 Boulevard du Port 80000 Amiens', type: 'housenumber' @@ -32,6 +33,7 @@ describe('address http', (): void => { expect(addresses).toStrictEqual([ { + id: 'addressTransferId', context: '80, Somme, Hauts-de-France', label: '8 Boulevard du Port 80000 Amiens', localisation: Localisation({ diff --git a/src/features/adresse/data/http/address/address.http.ts b/src/features/adresse/data/http/address/address.http.ts index 5d168e6d..e5da785b 100644 --- a/src/features/adresse/data/http/address/address.http.ts +++ b/src/features/adresse/data/http/address/address.http.ts @@ -24,6 +24,7 @@ export class AddressHttp extends AddressRepository { map((addressTransfer: AddressTransfer): Address[] => addressTransfer.features.map( (addressTransferFeature: Feature): Address => ({ + id: addressTransferFeature.properties.id, context: addressTransferFeature.properties.context, label: addressTransferFeature.properties.label, localisation: Localisation({ @@ -46,6 +47,7 @@ export class AddressHttp extends AddressRepository { map((addressTransfer: AddressTransfer): Address[] => addressTransfer.features.map( (addressTransferFeature: Feature): Address => ({ + id: addressTransferFeature.properties.id, context: addressTransferFeature.properties.context, label: addressTransferFeature.properties.label, localisation: Localisation({ diff --git a/src/features/adresse/data/transfers/address.transfer.ts b/src/features/adresse/data/transfers/address.transfer.ts index f02da987..b4717b93 100644 --- a/src/features/adresse/data/transfers/address.transfer.ts +++ b/src/features/adresse/data/transfers/address.transfer.ts @@ -2,6 +2,7 @@ import { FeatureCollection, Point } from 'geojson'; import { AddressType } from '../../models'; export type AddressTransferProperties = { + id: string; label: string; context: string; type: AddressType; diff --git a/src/features/adresse/models/address.ts b/src/features/adresse/models/address.ts index eb1f5b62..c6df0e29 100644 --- a/src/features/adresse/models/address.ts +++ b/src/features/adresse/models/address.ts @@ -3,6 +3,7 @@ import { Localisation } from '@gouvfr-anct/lieux-de-mediation-numerique'; export type AddressType = 'housenumber' | 'street' | 'locality' | 'municipality'; export interface Address { + id: string; context: string; label: string; localisation: Localisation; diff --git a/src/features/adresse/presenters/address/address.presenter.spec.ts b/src/features/adresse/presenters/address/address.presenter.spec.ts index c945133c..ba5b97ce 100644 --- a/src/features/adresse/presenters/address/address.presenter.spec.ts +++ b/src/features/adresse/presenters/address/address.presenter.spec.ts @@ -11,6 +11,7 @@ describe('address presenter', (): void => { search$: (): Observable => { return of([ { + id: 'testId-01', context: '80, Somme, Hauts-de-France', label: '8 Boulevard du Port 80000 Amiens', localisation: Localisation({ @@ -24,6 +25,7 @@ describe('address presenter', (): void => { reverse$: (): Observable => { return of([ { + id: 'testId-01', context: '80, Somme, Hauts-de-France', label: '8 Boulevard du Port 80000 Amiens', localisation: Localisation({ @@ -50,6 +52,7 @@ describe('address presenter', (): void => { expect(addressesFound).toStrictEqual([ { + id: 'testId-01', context: '80, Somme, Hauts-de-France', label: '8 Boulevard du Port 80000 Amiens', localisation: Localisation({ @@ -62,6 +65,7 @@ describe('address presenter', (): void => { expect(addressesFoundReverse).toStrictEqual([ { + id: 'testId-01', context: '80, Somme, Hauts-de-France', label: '8 Boulevard du Port 80000 Amiens', localisation: Localisation({ diff --git a/src/features/adresse/presenters/address/address.presenter.ts b/src/features/adresse/presenters/address/address.presenter.ts index b961f6e9..dff8cacd 100644 --- a/src/features/adresse/presenters/address/address.presenter.ts +++ b/src/features/adresse/presenters/address/address.presenter.ts @@ -7,6 +7,7 @@ import { map } from 'rxjs/operators'; const toResultFound = (addresses: Address[]): ResultFoundPresentation<{ type: AddressType }>[] => addresses.map( (address: Address): ResultFoundPresentation<{ type: AddressType }> => ({ + id: address.id, context: address.context, label: address.label, localisation: address.localisation, diff --git a/src/features/adresse/presenters/address/result-found.presentation.ts b/src/features/adresse/presenters/address/result-found.presentation.ts index c918acb5..f4b5b1e2 100644 --- a/src/features/adresse/presenters/address/result-found.presentation.ts +++ b/src/features/adresse/presenters/address/result-found.presentation.ts @@ -2,6 +2,7 @@ import { Localisation } from '@gouvfr-anct/lieux-de-mediation-numerique'; import { WithType } from '../../configuration'; export interface ResultFoundPresentation { + id: string; context: string; label: string; localisation: Localisation; diff --git a/src/features/cartographie/layouts/cartographie/cartographie.layout.html b/src/features/cartographie/layouts/cartographie/cartographie.layout.html index 2a276a47..512f04e3 100644 --- a/src/features/cartographie/layouts/cartographie/cartographie.layout.html +++ b/src/features/cartographie/layouts/cartographie/cartographie.layout.html @@ -5,7 +5,7 @@
- +

Patientez quelques instants

Nous recherchons les lieux @@ -35,7 +35,8 @@

placeholder="Recherchez un lieu ou une adresse" class="me-3 d-sm-inline-block d-none" [adresse]="(defaultAddress$ | async) ?? ''" - [fromOrientation]="this.fromOrientation" + [adresseId]="(defaultAddressId$ | async) ?? ''" + [fromOrientation]="(this.fromOrientation$ | async) ?? false" (resultFound)="onResultFound($event)"> placeholder="Recherchez un lieu ou une adresse" class="m-3 d-sm-none d-block" [adresse]="(defaultAddress$ | async) ?? ''" + [adresseId]="(defaultAddressId$ | async) ?? ''" [fullWidth]="true" - [fromOrientation]="this.fromOrientation" + [fromOrientation]="(this.fromOrientation$ | async) ?? false" (resultFound)="onResultFound($event)"> paramMap.get('address')) ); - public fromOrientation: boolean = Object.keys(this.route.snapshot.queryParams).length > 0; + public defaultAddressId$: Observable = this.route.queryParamMap.pipe( + map((paramMap: ParamMap) => paramMap.get('addressId')) + ); + + private _fromOrientation$: BehaviorSubject = new BehaviorSubject( + Object.keys(this.route.snapshot.queryParams).length > 0 + ); + public readonly fromOrientation$: Observable = this._fromOrientation$.asObservable(); private readonly _userLocalisation$: BehaviorSubject = new BehaviorSubject(NO_LOCALISATION); public readonly userLocalisation$: Observable = this._userLocalisation$.asObservable(); diff --git a/src/features/coordinateurs/data/http/conseillers/conseillers.http.ts b/src/features/coordinateurs/data/http/conseillers/conseillers.http.ts index aad3164f..8c5558e1 100644 --- a/src/features/coordinateurs/data/http/conseillers/conseillers.http.ts +++ b/src/features/coordinateurs/data/http/conseillers/conseillers.http.ts @@ -13,6 +13,7 @@ const onlyMatchingConseillerNom = conseiller.nom.toLowerCase().includes(searchTerm.toLowerCase()); const toResultFound = (conseiller: Conseiller): ResultFoundPresentation<{ type: 'conseiller' }> => ({ + id: conseiller.id, context: conseiller.structurePorteuse.adresse, label: conseiller.nom, localisation: Localisation({ diff --git a/src/features/core/presenters/filter/filter.presenter.ts b/src/features/core/presenters/filter/filter.presenter.ts index 1ba9b621..b0b96136 100644 --- a/src/features/core/presenters/filter/filter.presenter.ts +++ b/src/features/core/presenters/filter/filter.presenter.ts @@ -44,6 +44,7 @@ export type FilterPresentation = { export type FilterQueryParamsPresentation = { service?: Service; address?: string; + address_id?: string; latitude?: `${number}`; longitude?: `${number}`; distance?: `${number}`; @@ -61,6 +62,7 @@ export type FilterFormPresentation = FilterPresentation & { address?: string; latitude?: number; longitude?: number; + addressId?: string; }; const wrapInArray = (params: string | string[]): T[] => (Array.isArray(params) ? params : [params]) as unknown as T[]; @@ -92,6 +94,7 @@ export const hasActiveFilter = (filterFormPresentation: FilterFormPresentation): export const toFilterFormPresentationFromQuery = (queryParams?: FilterQueryParamsPresentation): FilterFormPresentation => ({ service: queryParams?.service, address: queryParams?.address, + addressId: queryParams?.address_id, latitude: queryParams?.latitude ? parseFloat(queryParams.latitude) : undefined, longitude: queryParams?.longitude ? parseFloat(queryParams.longitude) : undefined, distance: queryParams?.distance ? parseInt(queryParams.distance) : undefined, diff --git a/src/features/core/presenters/lieux-mediation-numerique/lieux-mediation-numerique.presenter.spec.ts b/src/features/core/presenters/lieux-mediation-numerique/lieux-mediation-numerique.presenter.spec.ts index a4212f14..adf4506e 100644 --- a/src/features/core/presenters/lieux-mediation-numerique/lieux-mediation-numerique.presenter.spec.ts +++ b/src/features/core/presenters/lieux-mediation-numerique/lieux-mediation-numerique.presenter.spec.ts @@ -2387,6 +2387,7 @@ describe('lieux-mediation-numerique-list presenter', (): void => { expect[]>(searchResults).toStrictEqual([ { + id: '288b41b0-20ef-426c-9cac-0af99203365d', context: '12 BIS RUE DE LECLERCQ 51100, Reims', label: 'Anonymal', localisation: Localisation({ latitude: 46.2814605, longitude: 4.468874 }), @@ -2419,6 +2420,7 @@ describe('lieux-mediation-numerique-list presenter', (): void => { expect[]>(searchResults).toStrictEqual([ { + id: '288b41b0-20ef-426c-9cac-0af99203365d', context: '12 BIS RUE DE LECLERCQ 51100, Reims', label: 'Anonymal', localisation: Localisation({ latitude: 46.2814605, longitude: 4.468874 }), @@ -2466,6 +2468,7 @@ describe('lieux-mediation-numerique-list presenter', (): void => { expect[]>(searchResults).toStrictEqual([ { + id: '288b41b0-20ef-426c-9cac-0af99203365d', context: '12 BIS RUE DE LECLERCQ 51100, Reims', label: 'Anonymal Reims', localisation: Localisation({ latitude: 46.2814605, longitude: 4.468874 }), @@ -2475,6 +2478,7 @@ describe('lieux-mediation-numerique-list presenter', (): void => { } }, { + id: 'd27dc31b-cb32-488f-9cfd-01baa4dcbae4', context: '17 rue Paul Bellamy 44000, Nantes', label: 'Anonymal Nantes', localisation: Localisation({ latitude: 46.2814605, longitude: 4.468874 }), diff --git a/src/features/core/presenters/lieux-mediation-numerique/lieux-mediation-numerique.presenter.ts b/src/features/core/presenters/lieux-mediation-numerique/lieux-mediation-numerique.presenter.ts index b1736d53..0dc1dad3 100644 --- a/src/features/core/presenters/lieux-mediation-numerique/lieux-mediation-numerique.presenter.ts +++ b/src/features/core/presenters/lieux-mediation-numerique/lieux-mediation-numerique.presenter.ts @@ -264,6 +264,7 @@ const toResultFound = ({ }: LieuMediationNumerique & { localisation: Localisation; }): ResultFoundPresentation<{ id: string; type: 'place' }> => ({ + id: id, context: `${adresse.voie} ${adresse.code_postal}, ${adresse.commune}`, label: nom, payload: { id, type: 'place' }, diff --git a/src/features/orientation/pages/localisation/localisation.page.ts b/src/features/orientation/pages/localisation/localisation.page.ts index 6a782260..4eb9453b 100644 --- a/src/features/orientation/pages/localisation/localisation.page.ts +++ b/src/features/orientation/pages/localisation/localisation.page.ts @@ -66,6 +66,7 @@ export class LocalisationPage { } public onSelectAddress(address: ResultFoundPresentation): void { + this.orientationLayout.filterForm.get('addressId')?.setValue(address.id); this.orientationLayout.filterForm.get('address')?.setValue(address.label); this.orientationLayout.filterForm.get('latitude')?.setValue(address.localisation.latitude); this.orientationLayout.filterForm.get('longitude')?.setValue(address.localisation.longitude);