From a57b089527f3ed740125da5e78967fd3d6fbdfd3 Mon Sep 17 00:00:00 2001 From: Edie Lemoine Date: Thu, 4 Jul 2024 13:13:42 +0200 Subject: [PATCH] feat(pickup): support dragging map to load more locations Note: only supported for PostNL --- .../src/__snapshots__/index.spec.ts.snap | 3 +- .../__tests__/utils/waitForPickupLocations.ts | 2 +- .../components/map/LeafletMap/LeafletMap.vue | 6 +- .../map/LeafletMapInner/LeafletMapInner.vue | 108 +++-------- .../LeafletMapLoadMoreButton.vue | 39 ++++ .../map/LeafletMarker/LeafletMarker.vue | 46 +++-- .../delivery-options/src/composables/index.ts | 1 + .../src/composables/usePickupLocation.spec.ts | 6 +- .../src/composables/usePickupLocation.ts | 20 +- .../src/composables/usePickupLocationsMap.ts | 177 ++++++++++++++++++ .../useResolvedPickupLocations.spec.ts | 48 +++++ .../composables/useResolvedPickupLocations.ts | 139 +++++++++++--- .../composables/useSelectedPickupLocation.ts | 13 +- .../getDefaultConfigForPlatform.spec.ts.snap | 2 + .../src/config/setConfiguration.ts | 2 +- .../src/stores/useAddressStore.ts | 5 + apps/delivery-options/src/types/map.types.ts | 12 +- .../createGetDeliveryOptionsParameters.ts | 7 +- .../src/utils/createLatLngParameters.ts | 18 ++ apps/delivery-options/src/utils/index.ts | 1 + .../PickupLocationList/PickupLocationList.vue | 4 +- .../PickupLocationListWrapper.vue | 6 +- .../PickupLocationMap/PickupLocationMap.vue | 29 ++- .../PickupLocationMapWrapper.vue | 18 +- .../PickupLocationMapMarker.vue | 7 +- .../Pickup/PickupLocations.vue | 2 +- libs/shared/src/composables/sdk/index.ts | 1 + .../sdk/usePickupLocationsByLatLngRequest.ts | 29 +++ libs/shared/src/config/getMyParcelConfig.ts | 11 +- .../src/config/getSendMyParcelConfig.ts | 9 +- libs/shared/src/data/enums.ts | 1 + .../data/getDefaultDeliveryOptionsConfig.ts | 1 + .../getPlatformConfig.spec.ts.snap | 2 + libs/shared/src/utils/getAllConfigOptions.ts | 5 + 34 files changed, 580 insertions(+), 200 deletions(-) create mode 100644 apps/delivery-options/src/components/map/LeafletMapInner/LeafletMapLoadMoreButton.vue create mode 100644 apps/delivery-options/src/composables/usePickupLocationsMap.ts create mode 100644 apps/delivery-options/src/composables/useResolvedPickupLocations.spec.ts create mode 100644 apps/delivery-options/src/utils/createLatLngParameters.ts create mode 100644 libs/shared/src/composables/sdk/usePickupLocationsByLatLngRequest.ts diff --git a/apps/delivery-options/src/__snapshots__/index.spec.ts.snap b/apps/delivery-options/src/__snapshots__/index.spec.ts.snap index fdd0995f..157fb170 100644 --- a/apps/delivery-options/src/__snapshots__/index.spec.ts.snap +++ b/apps/delivery-options/src/__snapshots__/index.spec.ts.snap @@ -69,6 +69,7 @@ exports[`exports > exports from index.ts 1`] = ` "createCarrierMarkerIcon", "createDeliveryTypeTranslatable", "createGetDeliveryOptionsParameters", + "createLatLngParameters", "createNextDate", "createPackageTypeTranslatable", "createRelativeDateFormatter", @@ -77,7 +78,6 @@ exports[`exports > exports from index.ts 1`] = ` "getConfigPriceKey", "getDefaultAddress", "getDeliveryTypePrice", - "getFullPickupLocation", "getResolvedCarrier", "getResolvedDeliveryType", "getResolvedValue", @@ -103,6 +103,7 @@ exports[`exports > exports from index.ts 1`] = ` "useMostEcoFriendly", "useOptionsGroupedByCarrier", "usePickupLocation", + "usePickupLocationsMap", "useProvideElementWidth", "useResolvedCarrier", "useResolvedDeliveryDates", diff --git a/apps/delivery-options/src/__tests__/utils/waitForPickupLocations.ts b/apps/delivery-options/src/__tests__/utils/waitForPickupLocations.ts index 71d9ebaf..4c995059 100644 --- a/apps/delivery-options/src/__tests__/utils/waitForPickupLocations.ts +++ b/apps/delivery-options/src/__tests__/utils/waitForPickupLocations.ts @@ -2,7 +2,7 @@ import {waitFor} from '@testing-library/vue'; import {useResolvedPickupLocations} from '../../composables'; export const waitForPickupLocations = async (): Promise => { - const locations = useResolvedPickupLocations(); + const {locations} = useResolvedPickupLocations(); await waitFor(() => locations.value.length > 0, {timeout: 1000}); }; diff --git a/apps/delivery-options/src/components/map/LeafletMap/LeafletMap.vue b/apps/delivery-options/src/components/map/LeafletMap/LeafletMap.vue index 00e5b179..33bfa49f 100644 --- a/apps/delivery-options/src/components/map/LeafletMap/LeafletMap.vue +++ b/apps/delivery-options/src/components/map/LeafletMap/LeafletMap.vue @@ -8,7 +8,7 @@ @@ -19,8 +19,4 @@ diff --git a/apps/delivery-options/src/components/map/LeafletMapInner/LeafletMapInner.vue b/apps/delivery-options/src/components/map/LeafletMapInner/LeafletMapInner.vue index 0e7281d1..a7a5c1fe 100644 --- a/apps/delivery-options/src/components/map/LeafletMapInner/LeafletMapInner.vue +++ b/apps/delivery-options/src/components/map/LeafletMapInner/LeafletMapInner.vue @@ -1,112 +1,48 @@ diff --git a/apps/delivery-options/src/components/map/LeafletMapInner/LeafletMapLoadMoreButton.vue b/apps/delivery-options/src/components/map/LeafletMapInner/LeafletMapLoadMoreButton.vue new file mode 100644 index 00000000..4a4a6ca3 --- /dev/null +++ b/apps/delivery-options/src/components/map/LeafletMapInner/LeafletMapLoadMoreButton.vue @@ -0,0 +1,39 @@ + + + diff --git a/apps/delivery-options/src/components/map/LeafletMarker/LeafletMarker.vue b/apps/delivery-options/src/components/map/LeafletMarker/LeafletMarker.vue index 4bdf212b..2e7d079a 100644 --- a/apps/delivery-options/src/components/map/LeafletMarker/LeafletMarker.vue +++ b/apps/delivery-options/src/components/map/LeafletMarker/LeafletMarker.vue @@ -5,24 +5,22 @@ diff --git a/apps/delivery-options/src/views/MyParcelDeliveryOptions/Pickup/PickupLocationMap/PickupLocationMap.vue b/apps/delivery-options/src/views/MyParcelDeliveryOptions/Pickup/PickupLocationMap/PickupLocationMap.vue index 0cb45e5a..f054f610 100644 --- a/apps/delivery-options/src/views/MyParcelDeliveryOptions/Pickup/PickupLocationMap/PickupLocationMap.vue +++ b/apps/delivery-options/src/views/MyParcelDeliveryOptions/Pickup/PickupLocationMap/PickupLocationMap.vue @@ -15,7 +15,7 @@ diff --git a/apps/delivery-options/src/views/MyParcelDeliveryOptions/Pickup/PickupLocationMap/PickupLocationMapWrapper.vue b/apps/delivery-options/src/views/MyParcelDeliveryOptions/Pickup/PickupLocationMap/PickupLocationMapWrapper.vue index 1f1f3458..ab231902 100644 --- a/apps/delivery-options/src/views/MyParcelDeliveryOptions/Pickup/PickupLocationMap/PickupLocationMapWrapper.vue +++ b/apps/delivery-options/src/views/MyParcelDeliveryOptions/Pickup/PickupLocationMap/PickupLocationMapWrapper.vue @@ -3,18 +3,28 @@ diff --git a/apps/delivery-options/src/views/MyParcelDeliveryOptions/Pickup/PickupLocationMapMarker/PickupLocationMapMarker.vue b/apps/delivery-options/src/views/MyParcelDeliveryOptions/Pickup/PickupLocationMapMarker/PickupLocationMapMarker.vue index 37645477..91cef035 100644 --- a/apps/delivery-options/src/views/MyParcelDeliveryOptions/Pickup/PickupLocationMapMarker/PickupLocationMapMarker.vue +++ b/apps/delivery-options/src/views/MyParcelDeliveryOptions/Pickup/PickupLocationMapMarker/PickupLocationMapMarker.vue @@ -10,7 +10,6 @@ import {computed, toRefs} from 'vue'; import {type MarkerOptions} from 'leaflet'; import {isDef} from '@vueuse/core'; import {createCarrierMarkerIcon} from '../../../../utils'; -import {useDeliveryOptionsForm} from '../../../../form'; import {MAP_MARKER_CLASS_PREFIX} from '../../../../data'; import {usePickupLocation, useResolvedCarrier, useSelectedValues} from '../../../../composables'; import {LeafletMarker} from '../../../../components'; @@ -18,11 +17,11 @@ import {LeafletMarker} from '../../../../components'; const props = defineProps<{locationCode: string; active: boolean}>(); const propRefs = toRefs(props); -const form = useDeliveryOptionsForm(); - const {pickupLocation} = usePickupLocation(propRefs.locationCode); -const carrier = useResolvedCarrier(pickupLocation.value?.carrier); +const carrierName = computed(() => pickupLocation.value?.carrier); + +const carrier = useResolvedCarrier(carrierName); const center = computed(() => { if (!isDef(pickupLocation.value)) { diff --git a/apps/delivery-options/src/views/MyParcelDeliveryOptions/Pickup/PickupLocations.vue b/apps/delivery-options/src/views/MyParcelDeliveryOptions/Pickup/PickupLocations.vue index a1a008d7..f606185c 100644 --- a/apps/delivery-options/src/views/MyParcelDeliveryOptions/Pickup/PickupLocations.vue +++ b/apps/delivery-options/src/views/MyParcelDeliveryOptions/Pickup/PickupLocations.vue @@ -30,7 +30,7 @@ import PickupLocationInput from './PickupLocationInput/PickupLocationInput.vue'; const config = useConfigStore(); -const locations = useResolvedPickupLocations(); +const {locations} = useResolvedPickupLocations(); const mode = ref(config.pickupLocationsDefaultView); const {translate} = useLanguage(); diff --git a/libs/shared/src/composables/sdk/index.ts b/libs/shared/src/composables/sdk/index.ts index 48917cfd..d6ffe78f 100644 --- a/libs/shared/src/composables/sdk/index.ts +++ b/libs/shared/src/composables/sdk/index.ts @@ -5,3 +5,4 @@ export * from './useDeliveryOptionsRequest'; export * from './usePickupLocationsRequest'; export * from './useRequest'; export * from './useRequestStorage'; +export {usePickupLocationsByLatLngRequest} from './usePickupLocationsByLatLngRequest'; diff --git a/libs/shared/src/composables/sdk/usePickupLocationsByLatLngRequest.ts b/libs/shared/src/composables/sdk/usePickupLocationsByLatLngRequest.ts new file mode 100644 index 00000000..9af29e3f --- /dev/null +++ b/libs/shared/src/composables/sdk/usePickupLocationsByLatLngRequest.ts @@ -0,0 +1,29 @@ +import {type EndpointParameters, type GetPickupLocations, type PickupLocation} from '@myparcel/sdk'; +import {useSdk} from '../useSdk'; +import {type RequestHandler} from '../../types'; +import {REQUEST_KEY_PICKUP_LOCATIONS} from '../../data'; +import {useRequest} from './useRequest'; + +export const usePickupLocationsByLatLngRequest = ( + parameters: EndpointParameters, +): RequestHandler => { + return useRequest( + [REQUEST_KEY_PICKUP_LOCATIONS, parameters], + () => { + const sdk = useSdk(); + + return sdk.getPickupLocations({parameters}); + }, + { + fallback: [], + + /** + * TODO: Remove this when the api returns a proper response rather than 500 internal server error when no pickup + * locations are found (API-1301) + */ + onError() { + // silently fail + }, + }, + ); +}; diff --git a/libs/shared/src/config/getMyParcelConfig.ts b/libs/shared/src/config/getMyParcelConfig.ts index d13df832..d1389afe 100644 --- a/libs/shared/src/config/getMyParcelConfig.ts +++ b/libs/shared/src/config/getMyParcelConfig.ts @@ -1,3 +1,4 @@ +/* eslint-disable max-lines-per-function */ import { AUSTRIA, BELGIUM, @@ -29,9 +30,8 @@ import { } from '@myparcel/constants/countries'; import {CarrierName, DeliveryTypeName, PackageTypeName, ShipmentOptionName} from '@myparcel/constants'; import {type PlatformConfiguration} from '../types'; -import {AddressField, CarrierSetting, SubscriptionType, CustomDeliveryType} from '../data'; +import {AddressField, CarrierSetting, SubscriptionType, CustomDeliveryType, ConfigSetting} from '../data'; -// eslint-disable-next-line max-lines-per-function export const getMyParcelConfig = (): PlatformConfiguration => ({ carriers: [ { @@ -54,7 +54,12 @@ export const getMyParcelConfig = (): PlatformConfiguration => ({ pickupCountries: [NETHERLANDS, BELGIUM, DENMARK, SWEDEN, GERMANY], fakeDelivery: true, shipmentOptions: [ShipmentOptionName.OnlyRecipient, ShipmentOptionName.Signature], - features: [CarrierSetting.DeliveryDaysWindow, CarrierSetting.DropOffDays, CarrierSetting.DropOffDelay], + features: [ + CarrierSetting.DeliveryDaysWindow, + CarrierSetting.DropOffDays, + CarrierSetting.DropOffDelay, + ConfigSetting.PickupMapAllowLoadMore, + ], addressFields: [AddressField.PostalCode, AddressField.Street, AddressField.City], }, { diff --git a/libs/shared/src/config/getSendMyParcelConfig.ts b/libs/shared/src/config/getSendMyParcelConfig.ts index 43caa52d..1ba92aa2 100644 --- a/libs/shared/src/config/getSendMyParcelConfig.ts +++ b/libs/shared/src/config/getSendMyParcelConfig.ts @@ -28,7 +28,7 @@ import { } from '@myparcel/constants/countries'; import {CarrierName, DeliveryTypeName, PackageTypeName, ShipmentOptionName} from '@myparcel/constants'; import {type PlatformConfiguration} from '../types'; -import {AddressField, CarrierSetting, SubscriptionType, CustomDeliveryType} from '../data'; +import {AddressField, CarrierSetting, SubscriptionType, CustomDeliveryType, ConfigSetting} from '../data'; // eslint-disable-next-line max-lines-per-function export const getSendMyParcelConfig = (): PlatformConfiguration => ({ @@ -53,7 +53,12 @@ export const getSendMyParcelConfig = (): PlatformConfiguration => ({ deliveryCountries: [BELGIUM, NETHERLANDS], pickupCountries: [BELGIUM, NETHERLANDS], shipmentOptions: [ShipmentOptionName.OnlyRecipient, ShipmentOptionName.Signature], - features: [CarrierSetting.DeliveryDaysWindow, CarrierSetting.DropOffDays, CarrierSetting.DropOffDelay], + features: [ + CarrierSetting.DeliveryDaysWindow, + CarrierSetting.DropOffDays, + CarrierSetting.DropOffDelay, + ConfigSetting.PickupMapAllowLoadMore, + ], fakeDelivery: true, }, { diff --git a/libs/shared/src/data/enums.ts b/libs/shared/src/data/enums.ts index 963d288d..741ddc9a 100644 --- a/libs/shared/src/data/enums.ts +++ b/libs/shared/src/data/enums.ts @@ -45,6 +45,7 @@ export enum ConfigSetting { Locale = 'locale', PickupLocationsDefaultView = 'pickupLocationsDefaultView', PickupLocationsMapTileLayerData = 'pickupLocationsMapTileLayerData', + PickupMapAllowLoadMore = 'pickupMapAllowLoadMore', PickupShowDistance = 'pickupShowDistance', Platform = 'platform', ShowDeliveryDate = 'showDeliveryDate', diff --git a/libs/shared/src/data/getDefaultDeliveryOptionsConfig.ts b/libs/shared/src/data/getDefaultDeliveryOptionsConfig.ts index 815f2df8..4affb5ef 100644 --- a/libs/shared/src/data/getDefaultDeliveryOptionsConfig.ts +++ b/libs/shared/src/data/getDefaultDeliveryOptionsConfig.ts @@ -49,6 +49,7 @@ export const getDefaultDeliveryOptionsConfig = (): ResolvedDeliveryOptionsConfig [CarrierSetting.AllowPickupLocations]: true, [ConfigSetting.PickupLocationsDefaultView]: PickupLocationsView.Map, + [ConfigSetting.PickupMapAllowLoadMore]: true, [ConfigSetting.PickupShowDistance]: true, /** diff --git a/libs/shared/src/utils/__snapshots__/getPlatformConfig.spec.ts.snap b/libs/shared/src/utils/__snapshots__/getPlatformConfig.spec.ts.snap index 6914f095..e64e246a 100644 --- a/libs/shared/src/utils/__snapshots__/getPlatformConfig.spec.ts.snap +++ b/libs/shared/src/utils/__snapshots__/getPlatformConfig.spec.ts.snap @@ -53,6 +53,7 @@ exports[`getPlatformConfig > gets config for platform belgie 1`] = ` "deliveryDaysWindow", "dropOffDays", "dropOffDelay", + "pickupMapAllowLoadMore", ], "name": "postnl", "packageTypes": [ @@ -165,6 +166,7 @@ exports[`getPlatformConfig > gets config for platform myparcel 1`] = ` "deliveryDaysWindow", "dropOffDays", "dropOffDelay", + "pickupMapAllowLoadMore", ], "name": "postnl", "packageTypes": [ diff --git a/libs/shared/src/utils/getAllConfigOptions.ts b/libs/shared/src/utils/getAllConfigOptions.ts index aec11ff4..e81556c4 100644 --- a/libs/shared/src/utils/getAllConfigOptions.ts +++ b/libs/shared/src/utils/getAllConfigOptions.ts @@ -59,4 +59,9 @@ export const getAllConfigOptions = useMemoize((): ConfigOption[] => [ key: ConfigSetting.PickupLocationsMapTileLayerData, type: OptionType.String, }), + + declareOption({ + key: ConfigSetting.PickupMapAllowLoadMore, + type: OptionType.Boolean, + }), ]);