From de23bd5c33e49e0d3488cc452e217cc9b5ae99d3 Mon Sep 17 00:00:00 2001 From: alanb43 Date: Sun, 27 Nov 2022 01:55:30 -0500 Subject: [PATCH] added warning when changeset comment length > 255 chars --- data/core.yaml | 1 + modules/ui/changeset_editor.js | 41 ++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/data/core.yaml b/data/core.yaml index f98a773c5..041921828 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -615,6 +615,7 @@ en: comment_needed_message: Please add a changeset comment first. about_changeset_comments: About changeset comments about_changeset_comments_link: //wiki.openstreetmap.org/wiki/Good_changeset_comments + changeset_comment_length_warning: "Changeset comments can have a maximum of 255 characters" google_warning: "You mentioned Google in this comment: remember that copying from Google Maps is strictly forbidden." google_warning_link: https://www.openstreetmap.org/copyright contributors: diff --git a/modules/ui/changeset_editor.js b/modules/ui/changeset_editor.js index 8daa62bbd..1ff6580b2 100644 --- a/modules/ui/changeset_editor.js +++ b/modules/ui/changeset_editor.js @@ -85,10 +85,10 @@ export function uiChangesetEditor(context) { } } - // Add warning if comment mentions Google var hasGoogle = _tags.comment.match(/google/i); + var commentTooLong = _tags.comment.length > 255; var commentWarning = selection.select('.form-field-comment').selectAll('.comment-warning') - .data(hasGoogle ? [0] : []); + .data(hasGoogle || commentTooLong ? [0] : []); commentWarning.exit() .transition() @@ -96,23 +96,30 @@ export function uiChangesetEditor(context) { .style('opacity', 0) .remove(); - var commentEnter = commentWarning.enter() - .insert('div', '.tag-reference-body') - .attr('class', 'field-warning comment-warning') - .style('opacity', 0); + function displayWarningMessage(msg, link) { + var commentEnter = commentWarning.enter() + .insert('div', '.tag-reference-body') + .attr('class', 'field-warning comment-warning') + .style('opacity', 0); - commentEnter - .append('a') - .attr('target', '_blank') - .call(svgIcon('#iD-icon-alert', 'inline')) - .attr('href', t('commit.google_warning_link')) - .append('span') - .call(t.append('commit.google_warning')); + commentEnter + .append('a') + .attr('target', '_blank') + .call(svgIcon('#iD-icon-alert', 'inline')) + .attr('href', t(link)) + .append('span') + .call(t.append(msg)); - commentEnter - .transition() - .duration(200) - .style('opacity', 1); + commentEnter + .transition() + .duration(200) + .style('opacity', 1); + } + + // Add warning if comment mentions Google or comment length + // exceeds 255 chars + if (hasGoogle) displayWarningMessage('commit.google_warning', 'commit.google_warning_link'); + if (commentTooLong) displayWarningMessage('commit.changeset_comment_length_warning', 'commit.about_changeset_comments_link'); }