From 49c838fee551aa8b7d564d59a2a367613624f20b Mon Sep 17 00:00:00 2001 From: Kyle Hensel Date: Mon, 30 Dec 2024 22:55:50 +1300 Subject: [PATCH] allow duplicate values in semiCombo for some fields --- config/id.js | 2 +- modules/ui/fields/combo.js | 38 +++++++++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/config/id.js b/config/id.js index 2a30cd3957..efa41477a9 100644 --- a/config/id.js +++ b/config/id.js @@ -2,7 +2,7 @@ // cdns for external data packages const presetsCdnUrl = ENV__ID_PRESETS_CDN_URL - || 'https://cdn.jsdelivr.net/npm/@openstreetmap/id-tagging-schema@{presets_version}/'; + || 'https://raw.githubusercontent.com/k-yle/id-tagging-schema/kyle-deploy/'; // FIXME: TEMPORARY const ociCdnUrl = ENV__ID_OCI_CDN_URL || 'https://cdn.jsdelivr.net/npm/osm-community-index@{version}/'; const wmfSitematrixCdnUrl = ENV__ID_WMF_SITEMATRIX_CDN_URL diff --git a/modules/ui/fields/combo.js b/modules/ui/fields/combo.js index caacf33a7a..5c750ddf89 100644 --- a/modules/ui/fields/combo.js +++ b/modules/ui/fields/combo.js @@ -206,7 +206,9 @@ export function uiFieldCombo(field, context) { _comboData = _comboData.filter(filter); } - _comboData = objectDifference(_comboData, _multiData); + if (!field.allowDuplicates) { + _comboData = objectDifference(_comboData, _multiData); + } _combobox.data(_comboData); if (callback) callback(_comboData); } @@ -289,7 +291,9 @@ export function uiFieldCombo(field, context) { _comboData = _comboData.filter(queryFilter); - _comboData = objectDifference(_comboData, _multiData); + if (!field.allowDuplicates) { + _comboData = objectDifference(_comboData, _multiData); + } if (callback) callback(_comboData, hasStaticValues()); }); } @@ -384,7 +388,10 @@ export function uiFieldCombo(field, context) { } else if (_isSemi) { var arr = _multiData.map(function(d) { return d.key; }); arr = arr.concat(vals); - t[field.key] = context.cleanTagValue(utilArrayUniq(arr).filter(Boolean).join(';')); + if (!field.allowDuplicates) { + arr = utilArrayUniq(arr); + } + t[field.key] = context.cleanTagValue(arr.filter(Boolean).join(';')); } window.setTimeout(function() { _input.node().focus(); }, 10); @@ -410,11 +417,15 @@ export function uiFieldCombo(field, context) { if (_isMulti) { t[d.key] = undefined; } else if (_isSemi) { - var arr = _multiData.map(function(md) { - return md.key === d.key ? null : md.key; - }).filter(Boolean); + let arr = _multiData.map(item => item.key); + + // delete the value using the index, since a value + // may exist multiple times in the array. + arr.splice(d.index, 1); - arr = utilArrayUniq(arr); + if (!field.allowDuplicates) { + arr = utilArrayUniq(arr); + } t[field.key] = arr.length ? arr.join(';') : undefined; _lengthIndicator.update(t[field.key]); @@ -620,7 +631,7 @@ export function uiFieldCombo(field, context) { if (Array.isArray(tags[field.key])) { tags[field.key].forEach(function(tagVal) { - var thisVals = utilArrayUniq((tagVal || '').split(';')).filter(Boolean); + var thisVals = (tagVal || '').split(';').filter(Boolean); allValues = allValues.concat(thisVals); if (!commonValues) { commonValues = thisVals; @@ -628,13 +639,18 @@ export function uiFieldCombo(field, context) { commonValues = commonValues.filter(value => thisVals.includes(value)); } }); - allValues = utilArrayUniq(allValues).filter(Boolean); + allValues = allValues.filter(Boolean); } else { - allValues = utilArrayUniq((tags[field.key] || '').split(';')).filter(Boolean); + allValues = (tags[field.key] || '').split(';').filter(Boolean); commonValues = allValues; } + if (!field.allowDuplicates) { + commonValues = utilArrayUniq(commonValues); + allValues = utilArrayUniq(allValues); + } + _multiData = allValues.map(function(v) { return { key: v, @@ -667,7 +683,7 @@ export function uiFieldCombo(field, context) { // Render chips var chips = _container.selectAll('.chip') - .data(_multiData); + .data(_multiData.map((item, index) => ({ ...item, index }))); chips.exit() .remove();