Skip to content

Commit b71105a

Browse files
committed
preserve order of options when fiel has also autosuggestions, fixes #12117
and render additional values from taginfo as raw-options only (e.g. when the field references another field for strings, but omits some options on purpose to disincentivize them)
1 parent b704587 commit b71105a

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ _Breaking developer changes, which may affect downstream projects or sites that
6363
#### :rocket: Presets
6464
* Standardize tooltips in combo boxes: always show (full) raw tag, don't duplicate the already rendered titles, and show descriptions from wiki/taginfo where available ([#12010], thanks [@tordans])
6565
* Use full width for the dropdown box for the values of the `access` field ([#12065])
66+
* Preserve the order of options when a combo field accepts both static options as well as autosuggestions from taginfo and display additional tag values from taginfo as raw-options only ([#12117])
6667
#### :hammer: Development
6768
* Replace `sinon` with `vitest`'s built in spy/mock library ([#12058])
6869
* Add type annotations to `context.js` module ([#11589], thanks [@k-yle])
@@ -82,6 +83,7 @@ _Breaking developer changes, which may affect downstream projects or sites that
8283
[#12070]: https://github.com/openstreetmap/iD/issues/12070
8384
[#12078]: https://github.com/openstreetmap/iD/issues/12078
8485
[#12110]: https://github.com/openstreetmap/iD/issues/12110
86+
[#12117]: https://github.com/openstreetmap/iD/issues/12117
8587
[#12120]: https://github.com/openstreetmap/iD/issues/12120
8688
[#12139]: https://github.com/openstreetmap/iD/pull/12139
8789
[#12178]: https://github.com/openstreetmap/iD/pull/12178

modules/ui/fields/combo.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -442,19 +442,28 @@ export function uiFieldCombo(field, context) {
442442
d.value.toLowerCase().indexOf(_countryCode + ':') === 0);
443443
}
444444

445-
const additionalOptions = (field.options || stringsField.options || [])
446-
.filter(v => !data.some(dv => dv.value === (_isMulti ? field.key + v : v)))
447-
.map(v => ({ value: v }));
445+
const staticOptions = getOptions();
448446

449447
// hide the caret if there are no suggestions
450-
_container.classed('empty-combobox', data.length === 0);
448+
_container.classed('empty-combobox', data.length + staticOptions.length === 0);
451449

452-
_comboData = data.concat(additionalOptions).map(function(d) {
450+
data = data.map(function(d) {
453451
var v = d.value;
454452
if (_isMulti) v = v.replace(field.key, '');
455453
const labelId = getLabelId(stringsField, v);
456-
var isLocalizable = stringsField.hasTextForStringId(labelId);
457-
var label = stringsField.t(labelId, { default: v });
454+
let isLocalizable;
455+
let label;
456+
let display;
457+
if (hasStaticValues() && !staticOptions.find(option => option.key === v)) {
458+
// field has static options, but value is not one of them: include only as a raw option
459+
isLocalizable = false;
460+
label = v;
461+
display = selection => selection.append('span').text(v);
462+
} else {
463+
isLocalizable = stringsField.hasTextForStringId(labelId);
464+
label = stringsField.t(labelId, { default: v });
465+
display = stringsField.t.append(labelId, { default: v });
466+
}
458467

459468
// Only here is data for `taginfoDesc` present. We render it as `title`, when no `presetDesc` is given.
460469
const presetDesc = presetDescription(v);
@@ -466,11 +475,22 @@ export function uiFieldCombo(field, context) {
466475
value: label,
467476
title: !presetDesc && taginfoDesc ? `${taginfoDesc}\n${formatTag(field.key, v, _isMulti)}` : formatTag(field.key, v, _isMulti),
468477
description: presetDesc,
469-
display: addComboboxIcons(stringsField.t.append(labelId, { default: label }), v),
478+
display: addComboboxIcons(display, v),
470479
klass: isLocalizable ? '' : 'raw-option'
471480
};
472481
});
473482

483+
if (hasStaticValues()) {
484+
_comboData = staticOptions.map(option =>
485+
// prefer taginfo entry, as those might have additional details like the taginfoDesc
486+
data.find(d => d.key === option.key) || option
487+
).concat(data.filter(d =>
488+
// append taginfo results that are not present in the static options at the end
489+
!staticOptions.some(option => d.key === option.key)));
490+
} else {
491+
_comboData = data;
492+
}
493+
474494
_comboData = _comboData.filter(queryFilter);
475495

476496
if (!field.allowDuplicates) {

0 commit comments

Comments
 (0)