update directionalCombo fields to tagging schema v6 schema

keeping a fallback to v5's `cycleway` field type for now

for #9477
This commit is contained in:
Martin Raifer
2023-01-24 14:20:05 +01:00
parent 98e9a11a51
commit d9695f1cef
2 changed files with 28 additions and 13 deletions

View File

@@ -41,9 +41,6 @@ export function uiField(context, presetField, entityIDs, options) {
.title(() => t.append('inspector.lock.suggestion', { label: field.title }))
.placement('bottom');
field.keys = field.keys || [field.key];
// only create the fields that are actually being shown
if (_show && !field.impl) {
createField();
@@ -67,12 +64,23 @@ export function uiField(context, presetField, entityIDs, options) {
}
function allKeys() {
let keys = field.keys || [field.key];
if (field.type === 'directionalCombo' && field.key) {
// directionalCombo fields can have an additional key describing the for
// cases where both directions share a "common" value.
keys = keys.concat(field.key);
}
return keys;
}
function isModified() {
if (!entityIDs || !entityIDs.length) return false;
return entityIDs.some(function(entityID) {
var original = context.graph().base().entities[entityID];
var latest = context.graph().entity(entityID);
return field.keys.some(function(key) {
return allKeys().some(function(key) {
return original ? latest.tags[key] !== original.tags[key] : latest.tags[key];
});
});
@@ -80,7 +88,7 @@ export function uiField(context, presetField, entityIDs, options) {
function tagsContainFieldKey() {
return field.keys.some(function(key) {
return allKeys().some(function(key) {
if (field.type === 'multiCombo') {
for (var tagKey in _tags) {
if (tagKey.indexOf(key) === 0) {
@@ -99,7 +107,7 @@ export function uiField(context, presetField, entityIDs, options) {
d3_event.preventDefault();
if (!entityIDs || _locked) return;
dispatch.call('revert', d, d.keys);
dispatch.call('revert', d, allKeys());
}
@@ -109,7 +117,7 @@ export function uiField(context, presetField, entityIDs, options) {
if (_locked) return;
var t = {};
d.keys.forEach(function(key) {
allKeys().forEach(function(key) {
t[key] = undefined;
});

View File

@@ -13,6 +13,15 @@ export function uiFieldDirectionalCombo(field, context) {
var _combos = {};
// fallback for schema-builder v5's cycleway field type: can be removed eventually
if (field.type === 'cycleway') {
field = {
...field,
key: field.keys[0],
keys: field.keys.slice(1)
};
}
function directionalCombo(selection) {
function stripcolon(s) {
@@ -37,10 +46,8 @@ export function uiFieldDirectionalCombo(field, context) {
.attr('class', 'rows')
.merge(div);
var keys = field.keys.slice(1);
items = div.selectAll('li')
.data(keys);
.data(field.keys);
var enter = items.enter()
.append('li')
@@ -77,8 +84,8 @@ export function uiFieldDirectionalCombo(field, context) {
function change(key, newValue) {
const commonKey = field.keys[0];
const otherKey = key === field.keys[1] ? field.keys[2] : field.keys[1];
const commonKey = field.key;
const otherKey = key === field.keys[0] ? field.keys[1] : field.keys[0];
dispatch.call('change', this, tags => {
const otherValue = tags[otherKey] || tags[commonKey];
@@ -101,7 +108,7 @@ export function uiFieldDirectionalCombo(field, context) {
directionalCombo.tags = function(tags) {
_tags = tags;
const commonKey = field.keys[0];
const commonKey = field.key;
for (let key in _combos) {
const uniqueValues = [... new Set([]
.concat(_tags[commonKey])