Generalize deprecated_tags validation to outdated_tags validation

Add check for missing addTags go outdated_tags validation (close #6043, close #6042)
This commit is contained in:
Quincy Morgan
2019-03-12 17:08:20 -04:00
parent 33daa2a969
commit fb25a44017
7 changed files with 89 additions and 131 deletions

View File

@@ -1244,13 +1244,6 @@ en:
tip: "Crossing indoor features should use different levels."
indoor-indoor_connectable:
tip: "Crossing indoor features should be connected or use different levels."
deprecated_tag:
title: Deprecated Tags
single:
message: '{feature} has the outdated tag "{tag}"'
combination:
message: '{feature} has an outdated tag combination: {tags}'
tip: "Some tags become deprecated over time and should be replaced."
disconnected_way:
title: Disconnected Ways
highway:
@@ -1285,6 +1278,10 @@ en:
title: Misplaced Multipolygon Tags
message: "{multipolygon} has misplaced tags"
tip: "Multipolygons should be tagged on their relation, not their outer way."
outdated_tags:
title: Outdated Tags
message: '{feature} has outdated tags'
tip: "Some tags change over time and should be updated."
tag_suggests_area:
title: Lines Tagged as Areas
message: '{feature} should be a closed area based on the tag "{tag}"'
@@ -1308,10 +1305,6 @@ en:
move_tags:
title: Move the tags
annotation: Moved tags.
remove_deprecated_tag:
annotation: Removed an old tag.
remove_deprecated_tag_combo:
annotation: Removed an old tag combination.
remove_from_relation:
title: Remove from relation
remove_generic_name:
@@ -1333,12 +1326,9 @@ en:
tag_as_disconnected:
title: Tag as disconnected
annotation: Tagged very close features as disconnected.
upgrade_tag:
title: Upgrade the tag
annotation: Upgraded an old tag.
upgrade_tag_combo:
upgrade_tags:
title: Upgrade the tags
annotation: Upgraded an old tag combination.
annotation: Upgraded old tags.
use_bridge_or_tunnel:
title: Use a bridge or tunnel
use_different_layers:

29
dist/locales/en.json vendored
View File

@@ -1523,16 +1523,6 @@
"tip": "Crossing indoor features should be connected or use different levels."
}
},
"deprecated_tag": {
"title": "Deprecated Tags",
"single": {
"message": "{feature} has the outdated tag \"{tag}\""
},
"combination": {
"message": "{feature} has an outdated tag combination: {tags}"
},
"tip": "Some tags become deprecated over time and should be replaced."
},
"disconnected_way": {
"title": "Disconnected Ways",
"highway": {
@@ -1580,6 +1570,11 @@
"message": "{multipolygon} has misplaced tags",
"tip": "Multipolygons should be tagged on their relation, not their outer way."
},
"outdated_tags": {
"title": "Outdated Tags",
"message": "{feature} has outdated tags",
"tip": "Some tags change over time and should be updated."
},
"tag_suggests_area": {
"title": "Lines Tagged as Areas",
"message": "{feature} should be a closed area based on the tag \"{tag}\"",
@@ -1612,12 +1607,6 @@
"title": "Move the tags",
"annotation": "Moved tags."
},
"remove_deprecated_tag": {
"annotation": "Removed an old tag."
},
"remove_deprecated_tag_combo": {
"annotation": "Removed an old tag combination."
},
"remove_from_relation": {
"title": "Remove from relation"
},
@@ -1648,13 +1637,9 @@
"title": "Tag as disconnected",
"annotation": "Tagged very close features as disconnected."
},
"upgrade_tag": {
"title": "Upgrade the tag",
"annotation": "Upgraded an old tag."
},
"upgrade_tag_combo": {
"upgrade_tags": {
"title": "Upgrade the tags",
"annotation": "Upgraded an old tag combination."
"annotation": "Upgraded old tags."
},
"use_bridge_or_tunnel": {
"title": "Use a bridge or tunnel"

View File

@@ -1,88 +0,0 @@
import _clone from 'lodash-es/clone';
import { t } from '../util/locale';
import { actionUpgradeTags, actionChangeTags } from '../actions';
import { utilDisplayLabel, utilTagText } from '../util';
import { validationIssue, validationIssueFix } from '../core/validator';
export function validationDeprecatedTag() {
var type = 'deprecated_tag';
var validation = function(entity, context) {
var issues = [];
var deprecatedTagsArray = entity.deprecatedTags();
if (deprecatedTagsArray.length > 0) {
for (var deprecatedTagIndex in deprecatedTagsArray) {
var deprecatedTags = deprecatedTagsArray[deprecatedTagIndex];
var labelTags = _clone(deprecatedTags.old);
for (var key in labelTags) {
if (labelTags[key] === '*') {
// show the user the actual tag, like color=red instead of color=*
labelTags[key] = entity.tags[key];
}
}
var tagsLabel = utilTagText({ tags: labelTags });
var featureLabel = utilDisplayLabel(entity, context);
var isCombo = Object.keys(deprecatedTags.old).length > 1;
var messageObj = { feature: featureLabel };
if (isCombo) {
messageObj.tags = tagsLabel;
} else {
messageObj.tag = tagsLabel;
}
var tagMessageID = isCombo ? 'combination' : 'single';
issues.push(new validationIssue({
type: type,
severity: 'warning',
message: t('issues.deprecated_tag.' + tagMessageID + '.message', messageObj),
tooltip: t('issues.deprecated_tag.tip'),
entities: [entity],
hash: tagsLabel,
info: {
oldTags: deprecatedTags.old,
replaceTags: deprecatedTags.replace
},
fixes: [
new validationIssueFix({
icon: 'iD-icon-up',
title: t('issues.fix.' + (isCombo ? 'upgrade_tag_combo' : 'upgrade_tag') + '.title'),
onClick: function() {
var oldTags = this.issue.info.oldTags;
var replaceTags = this.issue.info.replaceTags;
var fixTextID = Object.keys(oldTags).length > 1 ? 'upgrade_tag_combo' : 'upgrade_tag';
context.perform(
actionUpgradeTags(this.issue.entities[0].id, oldTags, replaceTags),
t('issues.fix.' + fixTextID + '.annotation')
);
}
}),
new validationIssueFix({
icon: 'iD-operation-delete',
title: t('issues.fix.' + (isCombo ? 'remove_tags' : 'remove_tag') + '.title'),
onClick: function() {
var entity = this.issue.entities[0];
var tags = _clone(entity.tags);
var oldTags = this.issue.info.oldTags;
for (var key in oldTags) {
delete tags[key];
}
var fixTextID = Object.keys(oldTags).length > 1 ? 'remove_deprecated_tag_combo' : 'remove_deprecated_tag';
context.perform(
actionChangeTags(entity.id, tags),
t('issues.fix.' + fixTextID + '.annotation')
);
}
})
]
}));
}
}
return issues;
};
validation.type = type;
return validation;
}

View File

@@ -1,6 +1,5 @@
export { validationAlmostJunction } from './almost_junction';
export { validationCrossingWays } from './crossing_ways';
export { validationDeprecatedTag } from './deprecated_tag';
export { validationDisconnectedWay } from './disconnected_way';
export { validationGenericName } from './generic_name';
export { validationManyDeletions } from './many_deletions';
@@ -8,4 +7,5 @@ export { validationMaprules } from './maprules';
export { validationMissingRole } from './missing_role';
export { validationMissingTag } from './missing_tag';
export { validationOldMultipolygon } from './old_multipolygon';
export { validationOutdatedTags } from './outdated_tags';
export { validationTagSuggestsArea } from './tag_suggests_area';

View File

@@ -0,0 +1,71 @@
import _clone from 'lodash-es/clone';
import { t } from '../util/locale';
import { actionUpgradeTags, actionChangeTags } from '../actions';
import { utilDisplayLabel } from '../util';
import { validationIssue, validationIssueFix } from '../core/validator';
export function validationOutdatedTags() {
var type = 'outdated_tags';
var validation = function(entity, context) {
var deprecatedTagsArray = entity.deprecatedTags();
var preset = context.presets().match(entity, context.graph());
var missingRecommendedTags = {};
if (!preset.isFallback() && preset.tags !== preset.addTags) {
missingRecommendedTags = Object.keys(preset.addTags).reduce(function(obj, key) {
if (!entity.tags[key]) {
obj[key] = preset.addTags[key];
}
return obj;
}, {});
}
if (deprecatedTagsArray.length === 0 &&
Object.keys(missingRecommendedTags).length === 0) return [];
return [new validationIssue({
type: type,
severity: 'warning',
message: t('issues.outdated_tags.message', { feature: utilDisplayLabel(entity, context) }),
tooltip: t('issues.outdated_tags.tip'),
entities: [entity],
info: {
deprecatedTagsArray: deprecatedTagsArray,
missingRecommendedTags: missingRecommendedTags
},
fixes: [
new validationIssueFix({
icon: 'iD-icon-up',
title: t('issues.fix.upgrade_tags.title'),
onClick: function() {
var deprecatedTagsArray = this.issue.info.deprecatedTagsArray;
var missingRecommendedTags = this.issue.info.missingRecommendedTags;
var entityID = this.issue.entities[0].id;
context.perform(
function(graph) {
deprecatedTagsArray.forEach(function(deprecatedTags) {
graph = actionUpgradeTags(entityID, deprecatedTags.old, deprecatedTags.replace)(graph);
});
var tags = _clone(graph.entity(entityID).tags);
for (var key in missingRecommendedTags) {
tags[key] = missingRecommendedTags[key];
}
graph = actionChangeTags(entityID, tags)(graph);
return graph;
},
t('issues.fix.upgrade_tags.annotation')
);
}
})
]
})];
};
validation.type = type;
return validation;
}

View File

@@ -148,11 +148,11 @@
<script src='spec/validations/validator.js'></script>
<script src='spec/validations/almost_junction.js'></script>
<script src='spec/validations/crossing_ways.js'></script>
<script src='spec/validations/deprecated_tag.js'></script>
<script src='spec/validations/disconnected_way.js'></script>
<script src='spec/validations/missing_role.js'></script>
<script src='spec/validations/missing_tag.js'></script>
<script src='spec/validations/old_multipolygon.js'></script>
<script src='spec/validations/outdated_tags.js'></script>
<script src='spec/validations/tag_suggests_area.js'></script>
<script src='spec/operations/detach_node.js'></script>

View File

@@ -1,4 +1,4 @@
describe('iD.validations.deprecated_tag', function () {
describe('iD.validations.outdated_tags', function () {
var context;
beforeEach(function() {
@@ -18,7 +18,7 @@ describe('iD.validations.deprecated_tag', function () {
}
function validate() {
var validator = iD.validationDeprecatedTag();
var validator = iD.validationOutdatedTags();
var changes = context.history().changes();
var entities = changes.modified.concat(changes.created);
var issues = [];
@@ -44,7 +44,7 @@ describe('iD.validations.deprecated_tag', function () {
var issues = validate();
expect(issues).to.have.lengthOf(1);
var issue = issues[0];
expect(issue.type).to.eql('deprecated_tag');
expect(issue.type).to.eql('outdated_tags');
expect(issue.severity).to.eql('warning');
expect(issue.entities).to.have.lengthOf(1);
expect(issue.entities[0].id).to.eql('w-1');