From 10030bb4ae8d7e2d87a842607ae8745ed0d6e9d6 Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Tue, 15 Apr 2025 11:34:33 +0200 Subject: [PATCH] display explicit "context" tags of deprecation rules, closes #10104 --- CHANGELOG.md | 2 ++ modules/validations/outdated_tags.js | 30 ++++++++++++++++++++------ test/spec/validations/outdated_tags.js | 15 +++++++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4567eca89..d3ec52bad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ _Breaking developer changes, which may affect downstream projects or sites that #### :scissors: Operations #### :camera: Street-Level #### :white_check_mark: Validation +* Show unchanged tags of a [deprecation rule](https://github.com/ideditor/schema-builder?tab=readme-ov-file#deprecations) explicitly in the validation warning ([#10104]) #### :bug: Bugfixes * Fix removed tooltips from re-appearing when using keyboard navigation ([#9873]) #### :earth_asia: Localization @@ -49,6 +50,7 @@ _Breaking developer changes, which may affect downstream projects or sites that #### :hammer: Development [#9873]: https://github.com/openstreetmap/iD/issues/9873 +[#10104]: https://github.com/openstreetmap/iD/issues/10104 # v2.33.0 diff --git a/modules/validations/outdated_tags.js b/modules/validations/outdated_tags.js index 5adc893cf..918fcc26f 100644 --- a/modules/validations/outdated_tags.js +++ b/modules/validations/outdated_tags.js @@ -55,9 +55,10 @@ export function validationOutdatedTags() { } const nsiDiff = nsiResult ? utilTagDiff(oldTags, nsiResult.newTags) : []; - // Upgrade deprecated tags.. + // Upgrade deprecated tags + let deprecatedTags; if (_dataDeprecated) { - const deprecatedTags = getDeprecatedTags(entity.tags, _dataDeprecated); + deprecatedTags = getDeprecatedTags(entity.tags, _dataDeprecated); if (entity.type === 'way' && entity.isClosed() && entity.tags.traffic_calming === 'island' && !entity.tags.highway) { // https://github.com/openstreetmap/id-tagging-schema/issues/1162#issuecomment-2000356902 @@ -90,13 +91,23 @@ export function validationOutdatedTags() { } }); } - const deprecationDiff = utilTagDiff(oldTags, newTags); + const deprecationDiff = utilTagDiff(oldTags, newTags).concat( + Object.keys(oldTags) + .filter(key => deprecatedTags?.some(deprecated => deprecated.replace?.[key] !== undefined)) + .filter(key => newTags[key] === oldTags[key]) + .map(key => ({ + type: '~', + key, + oldVal: oldTags[key], + newVal: newTags[key], + display: '  ' + key + '=' + oldTags[key] + }))); let issues = []; issues.provisional = (_waitingForDeprecated || waitingForNsi); if (deprecationDiff.length) { - const isOnlyAddingTags = deprecationDiff.every(d => d.type === '+'); + const isOnlyAddingTags = !deprecationDiff.some(d => d.type === '-'); const prefix = isOnlyAddingTags ? 'incomplete.' : ''; issues.push(new validationIssue({ @@ -244,8 +255,15 @@ export function validationOutdatedTags() { .attr('class', 'tagDiff-row') .append('td') .attr('class', d => { - let klass = d.type === '+' ? 'add' : 'remove'; - return `tagDiff-cell tagDiff-cell-${klass}`; + const klass = 'tagDiff-cell'; + switch (d.type) { + case '+': + return `${klass} tagDiff-cell-add`; + case '-': + return `${klass} tagDiff-cell-remove`; + default: + return `${klass} tagDiff-cell-unchanged`; + } }) .html(d => d.display); } diff --git a/test/spec/validations/outdated_tags.js b/test/spec/validations/outdated_tags.js index ff0687ad3..8385e4192 100644 --- a/test/spec/validations/outdated_tags.js +++ b/test/spec/validations/outdated_tags.js @@ -1,3 +1,4 @@ +import { select as d3_select } from 'd3-selection'; import { setTimeout } from 'node:timers/promises'; describe('iD.validations.outdated_tags', function () { @@ -194,6 +195,20 @@ describe('iD.validations.outdated_tags', function () { }); }); + it('includes unchanged context tags of deprecation rule in tag reference', async () => { + createWay({ building: 'roof' }); + const validator = iD.validationOutdatedTags(context); + await setTimeout(20); + const issues = validate(validator); + expect(issues).toHaveLength(1); + const selection = d3_select(document.createElement('div')); + issues[0].reference(selection); + const tagReference = selection.selectAll('table .tagDiff-row').data(); + expect(tagReference).toHaveLength(2); + expect(tagReference.some(ref => ref.type === '+' && ref.key === 'layer')).toBeTruthy(); + expect(tagReference.some(ref => ref.type === '~' && ref.key === 'building')).toBeTruthy(); + }); + it('generates 2 separate issues for incomplete tags and NSI suggestions', async () => { createWay({ building: 'roof', amenity: 'fast_food', brand: 'Fish Bowl' }); const validator = iD.validationOutdatedTags(context);