From ba3c075438f79b96ef1d475233f33fb5bca29694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Odini?= Date: Wed, 22 May 2024 17:32:17 +0200 Subject: [PATCH] refactor(Location): get country emoji from country_code instead of country (#580) --- src/components/PriceLocationChip.vue | 2 +- src/utils.js | 9 +++++- tests/fixtures/pitted_apricot_prices.json | 6 ++++ tests/fixtures/prices.json | 30 +++++++++++++++++++ .../product_3011360030498_prices.json | 3 ++ 5 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/components/PriceLocationChip.vue b/src/components/PriceLocationChip.vue index 70f6a06292e..0d7da2f0da8 100644 --- a/src/components/PriceLocationChip.vue +++ b/src/components/PriceLocationChip.vue @@ -23,7 +23,7 @@ export default { }, priceLocationEmoji() { if (this.price && this.price.location) { - return utils.getCountryEmojiFromName(this.price.location.osm_address_country) + return utils.getCountryEmojiFromCode(this.price.location.osm_address_country_code) } return null } diff --git a/src/utils.js b/src/utils.js index 853a74035aa..ff7a6c7f9da 100644 --- a/src/utils.js +++ b/src/utils.js @@ -107,6 +107,11 @@ function getCountryEmojiFromName(countryString) { return country ? country.emoji : null } +function getCountryEmojiFromCode(countryCode) { + const country = CountriesWithEmoji.find(c => c.code === countryCode) + return country ? country.emoji : null +} + function getLocationName(locationObject) { // Photon if (locationObject.properties) { @@ -158,7 +163,8 @@ function getLocationTitle(locationObject, withName=true, withRoad=false, withCit locationTitle += getLocationCity(locationObject) } if (withEmoji) { - locationTitle += ` ${getCountryEmojiFromName(locationObject.osm_address_country) || ''}` + // locationTitle += ` ${getCountryEmojiFromName(locationObject.osm_address_country) || ''}` + locationTitle += ` ${getCountryEmojiFromCode(locationObject.osm_address_country_code) || ''}` } return locationTitle } @@ -235,6 +241,7 @@ export default { getLocaleCategoryTagName, getLocaleOriginTags, getCountryEmojiFromName, + getCountryEmojiFromCode, getLocationTitle, getLocationID, getLocationType, diff --git a/tests/fixtures/pitted_apricot_prices.json b/tests/fixtures/pitted_apricot_prices.json index 954e376bc72..6adfcd23c96 100644 --- a/tests/fixtures/pitted_apricot_prices.json +++ b/tests/fixtures/pitted_apricot_prices.json @@ -39,9 +39,12 @@ "id": 32, "osm_name": "Monoprix", "osm_display_name": "Monoprix, Rue Lafayette, Hyper Centre, Secteur 2, Grenoble, Isère, Auvergne-Rhône-Alpes, France métropolitaine, 38000, France", + "osm_tag_key": "shop", + "osm_tag_value": "supermarket", "osm_address_postcode": "38000", "osm_address_city": "Grenoble", "osm_address_country": "France", + "osm_address_country_code": "FR", "osm_lat": 45.1904063, "osm_lon": 5.7286464, "created": "2024-02-09T17:43:00.113125+01:00", @@ -87,9 +90,12 @@ "id": 32, "osm_name": "Monoprix", "osm_display_name": "Monoprix, Rue Lafayette, Hyper Centre, Secteur 2, Grenoble, Isère, Auvergne-Rhône-Alpes, France métropolitaine, 38000, France", + "osm_tag_key": "shop", + "osm_tag_value": "supermarket", "osm_address_postcode": "38000", "osm_address_city": "Grenoble", "osm_address_country": "France", + "osm_address_country_code": "FR", "osm_lat": 45.1904063, "osm_lon": 5.7286464, "created": "2024-02-09T17:43:00.113125+01:00", diff --git a/tests/fixtures/prices.json b/tests/fixtures/prices.json index 189ffae72e3..fa34e55f457 100644 --- a/tests/fixtures/prices.json +++ b/tests/fixtures/prices.json @@ -39,9 +39,12 @@ "id": 32, "osm_name": "Monoprix", "osm_display_name": "Monoprix, Rue Lafayette, Hyper Centre, Secteur 2, Grenoble, Isère, Auvergne-Rhône-Alpes, France métropolitaine, 38000, France", + "osm_tag_key": "shop", + "osm_tag_value": "supermarket", "osm_address_postcode": "38000", "osm_address_city": "Grenoble", "osm_address_country": "France", + "osm_address_country_code": "FR", "osm_lat": 45.1904063, "osm_lon": 5.7286464, "created": "2024-02-09T17:43:00.113125+01:00", @@ -104,9 +107,12 @@ "id": 32, "osm_name": "Monoprix", "osm_display_name": "Monoprix, Rue Lafayette, Hyper Centre, Secteur 2, Grenoble, Isère, Auvergne-Rhône-Alpes, France métropolitaine, 38000, France", + "osm_tag_key": "shop", + "osm_tag_value": "supermarket", "osm_address_postcode": "38000", "osm_address_city": "Grenoble", "osm_address_country": "France", + "osm_address_country_code": "FR", "osm_lat": 45.1904063, "osm_lon": 5.7286464, "created": "2024-02-09T17:43:00.113125+01:00", @@ -152,9 +158,12 @@ "id": 32, "osm_name": "Monoprix", "osm_display_name": "Monoprix, Rue Lafayette, Hyper Centre, Secteur 2, Grenoble, Isère, Auvergne-Rhône-Alpes, France métropolitaine, 38000, France", + "osm_tag_key": "shop", + "osm_tag_value": "supermarket", "osm_address_postcode": "38000", "osm_address_city": "Grenoble", "osm_address_country": "France", + "osm_address_country_code": "FR", "osm_lat": 45.1904063, "osm_lon": 5.7286464, "created": "2024-02-09T17:43:00.113125+01:00", @@ -217,9 +226,12 @@ "id": 36, "osm_name": "E. Leclerc", "osm_display_name": "E. Leclerc, V 64, Pré Nouvel, Échirolles, Grenoble, Isère, Auvergne-Rhône-Alpes, France métropolitaine, 38130, France", + "osm_tag_key": "shop", + "osm_tag_value": "supermarket", "osm_address_postcode": "38130", "osm_address_city": "Échirolles", "osm_address_country": "France", + "osm_address_country_code": "FR", "osm_lat": 45.1498691, "osm_lon": 5.6920308, "created": "2024-02-18T19:39:23.805746+01:00", @@ -282,9 +294,12 @@ "id": 36, "osm_name": "E. Leclerc", "osm_display_name": "E. Leclerc, V 64, Pré Nouvel, Échirolles, Grenoble, Isère, Auvergne-Rhône-Alpes, France métropolitaine, 38130, France", + "osm_tag_key": "shop", + "osm_tag_value": "supermarket", "osm_address_postcode": "38130", "osm_address_city": "Échirolles", "osm_address_country": "France", + "osm_address_country_code": "FR", "osm_lat": 45.1498691, "osm_lon": 5.6920308, "created": "2024-02-18T19:39:23.805746+01:00", @@ -347,9 +362,12 @@ "id": 36, "osm_name": "E. Leclerc", "osm_display_name": "E. Leclerc, V 64, Pré Nouvel, Échirolles, Grenoble, Isère, Auvergne-Rhône-Alpes, France métropolitaine, 38130, France", + "osm_tag_key": "shop", + "osm_tag_value": "supermarket", "osm_address_postcode": "38130", "osm_address_city": "Échirolles", "osm_address_country": "France", + "osm_address_country_code": "FR", "osm_lat": 45.1498691, "osm_lon": 5.6920308, "created": "2024-02-18T19:39:23.805746+01:00", @@ -412,9 +430,12 @@ "id": 38, "osm_name": "E. Leclerc", "osm_display_name": "E. Leclerc, V 64, Pré Nouvel, Échirolles, Grenoble, Isère, Auvergne-Rhône-Alpes, France métropolitaine, 38130, France", + "osm_tag_key": "shop", + "osm_tag_value": "supermarket", "osm_address_postcode": "38130", "osm_address_city": "Échirolles", "osm_address_country": "France", + "osm_address_country_code": "FR", "osm_lat": 45.1498691, "osm_lon": 5.6920308, "created": "2024-02-18T19:39:23.807454+01:00", @@ -477,9 +498,12 @@ "id": 38, "osm_name": "E. Leclerc", "osm_display_name": "E. Leclerc, V 64, Pré Nouvel, Échirolles, Grenoble, Isère, Auvergne-Rhône-Alpes, France métropolitaine, 38130, France", + "osm_tag_key": "shop", + "osm_tag_value": "supermarket", "osm_address_postcode": "38130", "osm_address_city": "Échirolles", "osm_address_country": "France", + "osm_address_country_code": "FR", "osm_lat": 45.1498691, "osm_lon": 5.6920308, "created": "2024-02-18T19:39:23.807454+01:00", @@ -542,9 +566,12 @@ "id": 36, "osm_name": "E. Leclerc", "osm_display_name": "E. Leclerc, V 64, Pré Nouvel, Échirolles, Grenoble, Isère, Auvergne-Rhône-Alpes, France métropolitaine, 38130, France", + "osm_tag_key": "shop", + "osm_tag_value": "supermarket", "osm_address_postcode": "38130", "osm_address_city": "Échirolles", "osm_address_country": "France", + "osm_address_country_code": "FR", "osm_lat": 45.1498691, "osm_lon": 5.6920308, "created": "2024-02-18T19:39:23.805746+01:00", @@ -607,9 +634,12 @@ "id": 38, "osm_name": "E. Leclerc", "osm_display_name": "E. Leclerc, V 64, Pré Nouvel, Échirolles, Grenoble, Isère, Auvergne-Rhône-Alpes, France métropolitaine, 38130, France", + "osm_tag_key": "shop", + "osm_tag_value": "supermarket", "osm_address_postcode": "38130", "osm_address_city": "Échirolles", "osm_address_country": "France", + "osm_address_country_code": "FR", "osm_lat": 45.1498691, "osm_lon": 5.6920308, "created": "2024-02-18T19:39:23.807454+01:00", diff --git a/tests/fixtures/product_3011360030498_prices.json b/tests/fixtures/product_3011360030498_prices.json index 77d5a033653..312302b2fed 100644 --- a/tests/fixtures/product_3011360030498_prices.json +++ b/tests/fixtures/product_3011360030498_prices.json @@ -56,9 +56,12 @@ "id": 38, "osm_name": "E. Leclerc", "osm_display_name": "E. Leclerc, V 64, Pré Nouvel, Échirolles, Grenoble, Isère, Auvergne-Rhône-Alpes, France métropolitaine, 38130, France", + "osm_tag_key": "shop", + "osm_tag_value": "supermarket", "osm_address_postcode": "38130", "osm_address_city": "Échirolles", "osm_address_country": "France", + "osm_address_country_code": "FR", "osm_lat": 45.1498691, "osm_lon": 5.6920308, "created": "2024-02-18T19:39:23.807454+01:00",