Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow duplicate values in semiCombo for some fields #10639

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 27 additions & 11 deletions modules/ui/fields/combo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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());
});
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
k-yle marked this conversation as resolved.
Show resolved Hide resolved

arr = utilArrayUniq(arr);
if (!field.allowDuplicates) {
arr = utilArrayUniq(arr);
}
t[field.key] = arr.length ? arr.join(';') : undefined;

_lengthIndicator.update(t[field.key]);
Expand Down Expand Up @@ -620,21 +631,26 @@ 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;
} else {
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,
Expand Down Expand Up @@ -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();
Expand Down
Loading