From d9695f1cef2744ba37d48f7ca7fa68fd345a907c Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Tue, 24 Jan 2023 14:20:05 +0100 Subject: [PATCH] update directionalCombo fields to tagging schema v6 schema keeping a fallback to v5's `cycleway` field type for now for #9477 --- modules/ui/field.js | 22 +++++++++++++++------- modules/ui/fields/directional_combo.js | 19 +++++++++++++------ 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/modules/ui/field.js b/modules/ui/field.js index 416b15cc1..b75680d7f 100644 --- a/modules/ui/field.js +++ b/modules/ui/field.js @@ -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; }); diff --git a/modules/ui/fields/directional_combo.js b/modules/ui/fields/directional_combo.js index 91a280789..9491cc5fb 100644 --- a/modules/ui/fields/directional_combo.js +++ b/modules/ui/fields/directional_combo.js @@ -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])