]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1544132 - Allow editing empty Descriptions
authorKohei Yoshino <kohei.yoshino@gmail.com>
Tue, 23 Apr 2019 22:30:47 +0000 (18:30 -0400)
committerGitHub <noreply@github.com>
Tue, 23 Apr 2019 22:30:47 +0000 (18:30 -0400)
extensions/BugModal/lib/ActivityStream.pm
extensions/BugModal/template/en/default/bug_modal/activity_stream.html.tmpl
extensions/EditComments/template/en/default/hook/bug_modal/activity_stream-comment_action.html.tmpl
extensions/EditComments/template/en/default/pages/comment-revisions.html.tmpl
extensions/EditComments/web/js/inline-editor.js
extensions/EditComments/web/styles/revisions.css
skins/standard/global.css

index a0e1b18fdd5bc70d6961c2759d9b4088164980ed..18e3370ccd7f31d18f96ad3f1681c646133912e7 100644 (file)
@@ -179,14 +179,6 @@ sub _add_comments_to_stream {
       $comment->{collapsed_reason} = $comment->author->name;
     }
 
-    if ( $comment->type != CMT_ATTACHMENT_CREATED
-      && $comment->count == 0
-      && length($comment->body) == 0)
-    {
-      $comment->{collapsed}        = 1;
-      $comment->{collapsed_reason} = 'empty';
-    }
-
 # If comment type is resolved as duplicate, do not add '...marked as duplicate...' string to comment body
     if ($comment->type == CMT_DUPE_OF) {
       $comment->set_type(0);
index 55c792dfa7679073307bd8c2fca1d5b5602d5121..95881ded95344f600452dcbb1ba12deb9205b829 100644 (file)
               </button>
             [% END %]
             <button type="button" class="reply-btn minor iconic" title="Reply to this comment" aria-label="Reply"
-                    data-reply-id="[% comment.count FILTER none %]"
+                    [% 'disabled' IF !comment.body %] data-reply-id="[% comment.count FILTER none %]"
                     data-reply-name="[% comment.author.name || comment.author.nick FILTER html %]">
               <span class="icon" aria-hidden="true"></span>
             </button>
     [% comment_tag = 'pre' %]
   [% END %]
 
-  [% IF comment.body %]
+  [%# Description (Comment 0) can be empty %]
+  [% IF comment.body || comment.count == 0 %]
     <[% comment_tag FILTER none %]
-        class="comment-text [%= "markdown-body" IF comment.is_markdown %] [%= "bz_private" IF comment.is_private %]"
+        class="comment-text [%= "markdown-body" IF comment.is_markdown %] [%= "bz_private" IF comment.is_private %]
+               [% "empty" IF !comment.body %]"
         id="ct-[% comment.count FILTER none %]" data-comment-id="[% comment.id FILTER none %]"
         [% IF comment.is_markdown +%] data-ismarkdown="true" [% END ~%]
         [% IF comment.collapsed +%] style="display:none"[% END ~%]>
-      [%~ comment.body_full({ exclude_attachment => 1 }) FILTER renderMarkdown(bug, comment) ~%]
+      [%~ IF comment.body ~%]
+        [%~ comment.body_full({ exclude_attachment => 1 }) FILTER renderMarkdown(bug, comment) ~%]
+      [%~ ELSE ~%]
+        <em>No description provided.</em>
+      [%~ END ~%]
     </[% comment_tag FILTER none %]>
   [% END %]
 [% END %]
index 76208017e48134d1733b28c156662ac029046d16..8ef264ac91f2502ebbe473426b0e7ef7f5c07e96 100644 (file)
@@ -7,7 +7,7 @@
   #%]
 
 [%
-  RETURN IF comment.body == '';
+  RETURN UNLESS comment.body || comment.count == 0;
   RETURN UNLESS user.is_insider
     || Param('edit_comments_group') && user.in_group(Param('edit_comments_group')) && comment.author.id == user.id;
   RETURN UNLESS
index d4cc4e0b8a85cb0e577352f635c8f4719ce3e18e..b2859d3893ea8e4347d3821146bbc2ad30eb70d7 100644 (file)
@@ -40,6 +40,8 @@
     <div class="body">
       [% IF !user.is_insider && a.is_hidden %]
         <div class="hidden-comment">(Hidden by Administrator)</div>
+      [% ELSIF comment.count == 0 && !a.new %]
+        <div class="empty-comment">No description provided.</div>
       [% ELSE %]
         <pre class="bz_comment_text">[% a.new FILTER quoteUrls(bug) %]</pre>
       [% END %]
index 8c92bcf1fdc3314142f18798c8161cd1b8b916d5..6ddf668a629b149ce29f512c3bd47e7dfbef3358 100644 (file)
@@ -48,7 +48,8 @@ Bugzilla.InlineCommentEditor = class InlineCommentEditor {
 
     this.$edit_button.addEventListener('click', event => this.edit_button_onclick(event));
 
-    // Check if the comment is written in Markdown
+    // Check if the comment is empty or written in Markdown
+    this.is_empty = this.$body.matches('.empty');
     this.is_markdown = this.$body.matches('[data-ismarkdown="true"]');
   }
 
@@ -140,6 +141,12 @@ Bugzilla.InlineCommentEditor = class InlineCommentEditor {
     // Adjust the height of `<textarea>`
     this.$textarea.style.height = `${this.$textarea.scrollHeight}px`;
 
+    // Let the user edit Description (Comment 0) immediately if it's empty
+    if (this.is_empty) {
+      this.fetch_onload({ comments: { [this.comment_id]: '' } });
+      return;
+    }
+
     // Retrieve the raw comment text
     bugzilla_ajax({
       url: `${BUGZILLA.config.basepath}rest/editcomments/comment/${this.comment_id}`,
@@ -284,11 +291,13 @@ Bugzilla.InlineCommentEditor = class InlineCommentEditor {
 
   /**
    * Enable or disable buttons on the comment actions toolbar (not the editor's own toolbar) while editing the comment
-   * to avoid any unexpected behaviour.
+   * to avoid any unexpected behaviour. The Reply button should always be disabled if the comment is empty.
    * @param {Boolean} disabled Whether the buttons should be disabled.
    */
   toggle_toolbar_buttons(disabled) {
-    this.$change_set.querySelectorAll('.comment-actions button').forEach($button => $button.disabled = disabled);
+    this.$change_set.querySelectorAll('.comment-actions button').forEach($button => {
+      $button.disabled = $button.matches('.reply-btn') && this.is_empty ? true : disabled;
+    });
   }
 
   /**
@@ -322,6 +331,13 @@ Bugzilla.InlineCommentEditor = class InlineCommentEditor {
    */
   save_onsuccess(data) {
     this.$body.innerHTML = data.html;
+
+    // Remove the empty state (new comment cannot be empty)
+    if (this.is_empty) {
+      this.is_empty = false;
+      this.$body.classList.remove('empty');
+    }
+
     this.finish();
 
     // Highlight code if possible
index ccaeb54421609d8506152e6fbcedc345824817a5..0614cf816b443c722cdb8cdb7e92b624e487c346 100644 (file)
@@ -23,6 +23,7 @@
   flex: none;
 }
 
+.revision .empty-comment,
 .revision .hidden-comment {
   padding: 10px;
   font-style: italic;
index 22c14207438c751f6987b1880970dcdf423f3833..aaacddbeaada462a0212b42e0521447ac55f1a44 100644 (file)
@@ -2171,6 +2171,10 @@ pre.comment-text {
     border: 1px dashed darkred;
 }
 
+.comment-text.empty {
+  color: #666;
+}
+
 /* Markdown styling adapted from https://github.com/sindresorhus/github-markdown-css */
 
 .markdown-body {