From 981ed9ef8c3d865f709f152d75ef58a15761e134 Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Thu, 24 Jan 2019 09:28:59 -0500 Subject: [PATCH] Integrate the generic_name validation into the new validations framework --- data/core.yaml | 6 ++++ dist/locales/en.json | 8 +++++ modules/util/index.js | 1 + modules/util/util.js | 7 +++- modules/validations/generic_name.js | 48 ++++++++++++++++++++----- modules/validations/validation_issue.js | 1 + 6 files changed, 61 insertions(+), 10 deletions(-) diff --git a/data/core.yaml b/data/core.yaml index e6ae02fa7..c14db4350 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -1163,6 +1163,9 @@ en: message: "The tag {tag} suggests line should be area, but it is not an area." deprecated_tags: message: "Deprecated tags: {tags}" + generic_name: + message: '{feature} has the generic name "{name}".' + tooltip: 'Names should be the official, on-the-ground titles of features.' building-building_crossing: message: "{building} intersect {building1} on the same layer." tooltip: "Buildings should not intersect except on separate layers." @@ -1215,6 +1218,9 @@ en: connect_almost_junction: title: Connect the features undo_redo: Connected two features that were really close. + remove_name: + title: Remove the name + undo_redo: Removed a generic name. intro: done: done ok: OK diff --git a/dist/locales/en.json b/dist/locales/en.json index ca49b76e6..4f4d1712b 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -1413,6 +1413,10 @@ "deprecated_tags": { "message": "Deprecated tags: {tags}" }, + "generic_name": { + "message": "{feature} has the generic name \"{name}\".", + "tooltip": "Names should be the official, on-the-ground titles of features." + }, "building-building_crossing": { "message": "{building} intersect {building1} on the same layer.", "tooltip": "Buildings should not intersect except on separate layers." @@ -1482,6 +1486,10 @@ "connect_almost_junction": { "title": "Connect the features", "undo_redo": "Connected two features that were really close." + }, + "remove_name": { + "title": "Remove the name", + "undo_redo": "Removed a generic name." } } }, diff --git a/modules/util/index.js b/modules/util/index.js index 1a3a65459..3babfc60f 100644 --- a/modules/util/index.js +++ b/modules/util/index.js @@ -22,6 +22,7 @@ export { utilKeybinding } from './keybinding'; export { utilNoAuto } from './util'; export { utilPrefixCSSProperty } from './util'; export { utilPrefixDOMProperty } from './util'; +export { utilPreset } from './util'; export { utilQsString } from './util'; export { utilRebind } from './rebind'; export { utilSetTransform } from './util'; diff --git a/modules/util/util.js b/modules/util/util.js index 659b0072c..49cfd685f 100644 --- a/modules/util/util.js +++ b/modules/util/util.js @@ -129,7 +129,7 @@ export function utilDisplayLabel(entity, context) { // use the display name if there is one return displayName; } - var preset = context.presets().match(entity, context.graph()); + var preset = utilPreset(entity, context); if (preset && preset.name()) { // use the preset name if there is a match return preset.name(); @@ -139,6 +139,11 @@ export function utilDisplayLabel(entity, context) { } +export function utilPreset(entity, context) { + return context.presets().match(entity, context.graph()); +} + + export function utilEntityRoot(entityType) { return { node: 'n', diff --git a/modules/validations/generic_name.js b/modules/validations/generic_name.js index 7cc27834a..fbc2683e5 100644 --- a/modules/validations/generic_name.js +++ b/modules/validations/generic_name.js @@ -1,7 +1,21 @@ +import _clone from 'lodash-es/clone'; import { t } from '../util/locale'; +import { + utilPreset +} from '../util'; +import { + ValidationIssueType, + ValidationIssueSeverity, + validationIssue, + validationIssueFix +} from './validation_issue'; +import { + actionChangeTags +} from '../actions'; import { discardNames } from '../../node_modules/name-suggestion-index/config/filters.json'; -export function validationGenericName() { + +export function validationGenericName(context) { function isGenericName(entity) { var name = entity.tags.name; @@ -31,21 +45,37 @@ export function validationGenericName() { return function validation(changes) { - var warnings = []; + var issues = []; for (var i = 0; i < changes.created.length; i++) { var change = changes.created[i]; var generic = isGenericName(change); if (generic) { - warnings.push({ - id: 'generic_name', - message: t('validations.generic_name'), - tooltip: t('validations.generic_name_tooltip', { name: generic }), - entity: change - }); + var preset = utilPreset(change, context); + issues.push(new validationIssue({ + type: ValidationIssueType.generic_name, + severity: ValidationIssueSeverity.warning, + message: t('issues.generic_name.message', {feature: preset.name(), name: generic}), + tooltip: t('issues.generic_name.tooltip'), + entities: [change], + fixes: [ + new validationIssueFix({ + title: t('issues.fix.remove_name.title'), + action: function() { + var entity = this.issue.entities[0]; + var tags = _clone(entity.tags); + tags.name = undefined; + context.perform( + actionChangeTags(entity.id, tags), + t('issues.fix.remove_name.undo_redo') + ); + } + }) + ] + })); } } - return warnings; + return issues; }; } diff --git a/modules/validations/validation_issue.js b/modules/validations/validation_issue.js index ab5ab076f..2e6a2105d 100644 --- a/modules/validations/validation_issue.js +++ b/modules/validations/validation_issue.js @@ -12,6 +12,7 @@ var ValidationIssueType = Object.freeze({ map_rule_issue: 'map_rule_issue', crossing_ways: 'crossing_ways', highway_almost_junction: 'highway_almost_junction', + generic_name: 'generic_name' });