From dcd7fb493889e86fc531ff4c50b55310dc2c13f5 Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Fri, 2 Dec 2022 13:49:49 +0100 Subject: [PATCH] don't include misspelled taginfo suggestions in combo fields --- CHANGELOG.md | 2 ++ modules/ui/combobox.js | 2 -- modules/ui/fields/combo.js | 30 ++++++++++++++++++++---------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ebebe5634..e268fb85e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,12 +45,14 @@ _Breaking developer changes, which may affect downstream projects or sites that #### :rocket: Presets * Clamp degree values in `direction` fields between 0 and 359 degrees ([#9386]) * Disable increment/decrement buttons on number fields if the input value is not numeric or when there is a multi-selection with conflicting values +* Filter out misspelled taginfo suggestions in combo field ([#9397]) #### :hammer: Development * Upgrade to Transifex API v3 ([#9375]) [#9372]: https://github.com/openstreetmap/iD/issues/9372 [#9375]: https://github.com/openstreetmap/iD/pull/9375 [#9386]: https://github.com/openstreetmap/iD/issues/9386 +[#9397]: https://github.com/openstreetmap/iD/issues/9397 # 2.23.2 diff --git a/modules/ui/combobox.js b/modules/ui/combobox.js index 7a1dc6916..057787aa5 100644 --- a/modules/ui/combobox.js +++ b/modules/ui/combobox.js @@ -349,8 +349,6 @@ export function uiCombobox(context, klass) { suggestionValues.push(s.key); } }); - //_suggestions.map(s => s.value) - // .concat(_suggestions.filter(s => s.key !== s.value).map(s => s.key)); var bestIndex = -1; for (var i = 0; i < suggestionValues.length; i++) { diff --git a/modules/ui/fields/combo.js b/modules/ui/fields/combo.js index d27198bdd..589324c31 100644 --- a/modules/ui/fields/combo.js +++ b/modules/ui/fields/combo.js @@ -97,6 +97,10 @@ export function uiFieldCombo(field, context) { return 'yes'; } + return restrictTagValueSpelling(dval) || undefined; + } + + function restrictTagValueSpelling(dval) { if (_snake_case) { dval = snake(dval); } @@ -105,7 +109,7 @@ export function uiFieldCombo(field, context) { dval = dval.toLowerCase(); } - return dval || undefined; + return dval; } @@ -227,23 +231,29 @@ export function uiFieldCombo(field, context) { services.taginfo[fn](params, function(err, data) { if (err) return; - data = data.filter(function(d) { - // don't show the fallback value - return field.type !== 'typeCombo' || d.value !== 'yes'; + // don't show the fallback value + data = data.filter(d => + field.type !== 'typeCombo' || d.value !== 'yes'); + + // don't show misspelled values + data = data.filter(d => { + var value = d.value; + if (_isMulti) { + value = value.slice(field.key.length); + } + return value === restrictTagValueSpelling(value); }); var deprecatedValues = osmEntity.deprecatedTagValuesByKey(_dataDeprecated)[field.key]; if (deprecatedValues) { // don't suggest deprecated tag values - data = data.filter(function(d) { - return deprecatedValues.indexOf(d.value) === -1; - }); + data = data.filter(d => + !deprecatedValues.includes(d.value)); } if (hasCountryPrefix) { - data = data.filter(function(d) { - return d.value.toLowerCase().indexOf(_countryCode + ':') === 0; - }); + data = data.filter(d => + d.value.toLowerCase().indexOf(_countryCode + ':') === 0); } const additionalOptions = (field.options || stringsField.options || [])