From c2ade4a4f87b75ef12bc63dbffca69bb57c31f39 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Oct 2020 05:35:06 +0000 Subject: [PATCH 1/2] Bump @ideditor/country-coder from 3.2.0 to 4.0.0 Bumps [@ideditor/country-coder](https://github.com/ideditor/country-coder) from 3.2.0 to 4.0.0. - [Release notes](https://github.com/ideditor/country-coder/releases) - [Commits](https://github.com/ideditor/country-coder/compare/v3.2.0...v4.0.0) Signed-off-by: dependabot[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 33493be10..10a3d25e6 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "translations": "node scripts/update_locales.js" }, "dependencies": { - "@ideditor/country-coder": "^3.2.0", + "@ideditor/country-coder": "^4.0.0", "@ideditor/location-conflation": "~0.5.0", "@mapbox/sexagesimal": "1.2.0", "@mapbox/togeojson": "0.16.0", From 2769ac87f1f7d431e5ee9a73ac38417a1ebe4284 Mon Sep 17 00:00:00 2001 From: Quincy Morgan <2046746+quincylvania@users.noreply.github.com> Date: Mon, 19 Oct 2020 13:12:05 -0400 Subject: [PATCH 2/2] Support territories in preset and field country limiters (re: #8102) --- modules/presets/collection.js | 14 +++++++++----- modules/ui/field.js | 13 ++++++------- modules/ui/preset_list.js | 4 ++-- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/modules/presets/collection.js b/modules/presets/collection.js index dd1b56021..c2f419cb1 100644 --- a/modules/presets/collection.js +++ b/modules/presets/collection.js @@ -1,4 +1,5 @@ -import { utilArrayUniq, utilEditDistance } from '../util'; +import { utilArrayIntersection, utilArrayUniq } from '../util/array'; +import { utilEditDistance } from '../util'; // @@ -45,7 +46,7 @@ export function presetCollection(collection) { return _this.item(id); }; - _this.search = (value, geometry, countryCode) => { + _this.search = (value, geometry, countryCodes) => { if (!value) return _this; value = value.toLowerCase().trim(); @@ -83,10 +84,13 @@ export function presetCollection(collection) { } let pool = _this.collection; - if (countryCode) { + if (countryCodes) { + if (typeof countryCodes === 'string') countryCodes = [countryCodes]; + countryCodes = countryCodes.map(code => code.toLowerCase()); + pool = pool.filter(a => { - if (a.countryCodes && a.countryCodes.indexOf(countryCode) === -1) return false; - if (a.notCountryCodes && a.notCountryCodes.indexOf(countryCode) !== -1) return false; + if (a.countryCodes && !utilArrayIntersection(a.countryCodes, countryCodes).length) return false; + if (a.notCountryCodes && utilArrayIntersection(a.notCountryCodes, countryCodes).length) return false; return true; }); } diff --git a/modules/ui/field.js b/modules/ui/field.js index d26343bf1..bd92c1afd 100644 --- a/modules/ui/field.js +++ b/modules/ui/field.js @@ -9,6 +9,7 @@ import { geoExtent } from '../geo/extent'; import { uiFieldHelp } from './field_help'; import { uiFields } from './fields'; import { uiTagReference } from './tag_reference'; +import { utilArrayIntersection } from '../util/array'; import { utilRebind, utilUniqueDomId } from '../util'; @@ -306,16 +307,14 @@ export function uiField(context, presetField, entityIDs, options) { if (!extent) return true; var center = extent.center(); - var countryCode = countryCoder.iso1A2Code(center); + var codes = countryCoder.iso1A2Codes(center).map(function(code) { + return code.toLowerCase(); + }); - if (!countryCode) return false; - - countryCode = countryCode.toLowerCase(); - - if (field.countryCodes && field.countryCodes.indexOf(countryCode) === -1) { + if (field.countryCodes && !utilArrayIntersection(codes, field.countryCodes).length) { return false; } - if (field.notCountryCodes && field.notCountryCodes.indexOf(countryCode) !== -1) { + if (field.notCountryCodes && utilArrayIntersection(codes, field.notCountryCodes).length) { return false; } } diff --git a/modules/ui/preset_list.js b/modules/ui/preset_list.js index 3402918ff..aa92d508e 100644 --- a/modules/ui/preset_list.js +++ b/modules/ui/preset_list.js @@ -98,9 +98,9 @@ export function uiPresetList(context) { var results, messageText; if (value.length && extent) { var center = extent.center(); - var countryCode = countryCoder.iso1A2Code(center); + var countryCodes = countryCoder.iso1A2Codes(center); - results = presets.search(value, entityGeometries()[0], countryCode && countryCode.toLowerCase()); + results = presets.search(value, entityGeometries()[0], countryCodes); messageText = t('inspector.results', { n: results.collection.length, search: value