From 4228b65602191946946374acbd09f121a58c9737 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Mon, 18 Jan 2021 17:18:37 -0500 Subject: [PATCH] Support more `*:wikidata` tags for field locking and pin styling --- modules/presets/preset.js | 8 ++++++- modules/svg/tag_classes.js | 10 +++++++- modules/ui/fields/input.js | 38 ++++++++++++++++++++++++++---- modules/ui/fields/localized.js | 43 ++++++++++++++++++++-------------- 4 files changed, 76 insertions(+), 23 deletions(-) diff --git a/modules/presets/preset.js b/modules/presets/preset.js index c4d3bb989..1ef100d99 100644 --- a/modules/presets/preset.js +++ b/modules/presets/preset.js @@ -155,7 +155,13 @@ export function presetPreset(presetID, preset, addable, allFields, allPresets) { _this.reference = () => { // Lookup documentation on Wikidata... - const qid = _this.tags.wikidata || _this.tags['brand:wikidata'] || _this.tags['operator:wikidata']; + const qid = ( + _this.tags.wikidata || + _this.tags['flag:wikidata'] || + _this.tags['brand:wikidata'] || + _this.tags['network:wikidata'] || + _this.tags['operator:wikidata'] + ); if (qid) { return { qid: qid }; } diff --git a/modules/svg/tag_classes.js b/modules/svg/tag_classes.js index a7482bdd8..9debfd202 100644 --- a/modules/svg/tag_classes.js +++ b/modules/svg/tag_classes.js @@ -160,7 +160,15 @@ export function svgTagClasses() { } // If this is a wikidata-tagged item, add a class for that.. - if (t.wikidata || t['brand:wikidata']) { + var qid = ( + t.wikidata || + t['flag:wikidata'] || + t['brand:wikidata'] || + t['network:wikidata'] || + t['operator:wikidata'] + ); + + if (qid) { classes.push('tag-wikidata'); } diff --git a/modules/ui/fields/input.js b/modules/ui/fields/input.js index 809f6d552..7904679ad 100644 --- a/modules/ui/fields/input.js +++ b/modules/ui/fields/input.js @@ -34,11 +34,41 @@ export function uiFieldText(field, context) { .catch(function() { /* ignore */ }); } - function i(selection) { - var entity = _entityIDs.length && context.hasEntity(_entityIDs[0]); - var preset = entity && presetManager.match(entity, context.graph()); - var isLocked = preset && preset.suggestion && field.id === 'brand'; + + function calcLocked() { + // Protect certain fields that have a companion `*:wikidata` value + var isLocked = (field.id === 'brand' || field.id === 'network' || field.id === 'operator' || field.id === 'flag') && + _entityIDs.length && + _entityIDs.some(function(entityID) { + var entity = context.graph().hasEntity(entityID); + if (!entity) return false; + + var which = field.id; // 'brand', 'network', 'operator', 'flag' + + // If the value was already edited manually then unlock and allow further editing + var base = context.graph().base().entities[_entityIDs[0]]; + if (base) { + var hasOriginalValue = entity.tags[which] && entity.tags[which] === base.tags[which]; + if (!hasOriginalValue) return false; + } + + // Features linked to Wikidata are likely important and should be protected + if (entity.tags.wikidata) return true; + + var preset = presetManager.match(entity, context.graph()); + var isSuggestion = preset && preset.suggestion; + + // Lock the field if there is a value and a companion `*:wikidata` value + return isSuggestion && !!entity.tags[which] && !!entity.tags[which + ':wikidata']; + }); + field.locked(isLocked); + } + + + function i(selection) { + calcLocked(); + var isLocked = field.locked(); var wrap = selection.selectAll('.form-field-input-wrap') .data([0]); diff --git a/modules/ui/fields/localized.js b/modules/ui/fields/localized.js index 25193a9f5..413a8ffe3 100644 --- a/modules/ui/fields/localized.js +++ b/modules/ui/fields/localized.js @@ -83,34 +83,43 @@ export function uiFieldLocalized(field, context) { function calcLocked() { - - // only lock the Name field - var isLocked = field.id === 'name' && + // Protect name field for suggestion presets that don't display a brand/operator field + var isLocked = (field.id === 'name') && _entityIDs.length && - // lock the field if any feature needs it _entityIDs.some(function(entityID) { - var entity = context.graph().hasEntity(entityID); if (!entity) return false; - var original = context.graph().base().entities[_entityIDs[0]]; - var hasOriginalName = original && entity.tags.name && entity.tags.name === original.tags.name; - // if the name was already edited manually then allow further editing - if (!hasOriginalName) return false; + // If the value was already edited manually then unlock and allow further editing + var base = context.graph().base().entities[_entityIDs[0]]; + if (base) { + var hasOriginalValue = entity.tags.name && entity.tags.name === base.tags.name; + if (!hasOriginalValue) return false; + } - // features linked to Wikidata are likely important and should be protected + // Features linked to Wikidata are likely important and should be protected if (entity.tags.wikidata) return true; - // assume the name has already been confirmed if its source has been researched + // Assume the name has already been confirmed if its source has been researched if (entity.tags['name:etymology:wikidata']) return true; + // Lock the name if this is a suggestion preset that assigns the name var preset = presetManager.match(entity, context.graph()); - var isSuggestion = preset && preset.suggestion; - var showsBrand = preset && preset.originalFields.filter(function(d) { - return d.id === 'brand'; - }).length; - // protect standardized brand names - return isSuggestion && !showsBrand; + if (preset) { + var isSuggestion = preset.suggestion; + var showsBrandField = preset.originalFields.some(function(d) { return d.id === 'brand'; }); + var showsOperatorField = preset.originalFields.some(function(d) { return d.id === 'operator'; }); + var setsName = preset.addTags.name; + var setsBrandWikidata = preset.addTags['brand:wikidata']; + var setsOperatorWikidata = preset.addTags['operator:wikidata']; + + return isSuggestion && setsName && ( + (setsBrandWikidata && !showsBrandField) || + (setsOperatorWikidata && !showsOperatorField) + ); + } + + return false; }); field.locked(isLocked);