FEATURE: Show edit indicator on review queue

FEATURE: Show edit indicator on review queue

If a flagged post has edits, show the pencil icon and pop up the history window when clicked.

diff --git a/app/assets/javascripts/discourse/components/reviewable-flagged-post.js.es6 b/app/assets/javascripts/discourse/components/reviewable-flagged-post.js.es6
new file mode 100644
index 0000000..05e8411
--- /dev/null
+++ b/app/assets/javascripts/discourse/components/reviewable-flagged-post.js.es6
@@ -0,0 +1,33 @@
+import computed from "ember-addons/ember-computed-decorators";
+import { longDate } from "discourse/lib/formatter";
+import { historyHeat } from "discourse/widgets/post-edits-indicator";
+import showModal from "discourse/lib/show-modal";
+
+export default Ember.Component.extend({
+  hasEdits: Ember.computed.gt("reviewable.version", 1),
+
+  @computed("reviewable.post_updated_at")
+  historyClass(updatedAt) {
+    return historyHeat(this.siteSettings, new Date(updatedAt));
+  },
+
+  @computed("reviewable.post_updated_at")
+  editedDate(updatedAt) {
+    return longDate(updatedAt);
+  },
+
+  actions: {
+    showEditHistory() {
+      let postId = this.get("reviewable.post_id");
+      this.store.find("post", postId).then(post => {
+        let historyController = showModal("history", {
+          model: post,
+          modalClass: "history-modal"
+        });
+        historyController.refresh(postId, "latest");
+        historyController.set("post", post);
+        historyController.set("topicController", null);
+      });
+    }
+  }
+});
diff --git a/app/assets/javascripts/discourse/controllers/history.js.es6 b/app/assets/javascripts/discourse/controllers/history.js.es6
index 369b37b..cea58e4 100644
--- a/app/assets/javascripts/discourse/controllers/history.js.es6
+++ b/app/assets/javascripts/discourse/controllers/history.js.es6
@@ -152,9 +152,14 @@ export default Ember.Controller.extend(ModalFunctionality, {
     return !prevHidden && this.currentUser && this.currentUser.get("staff");
   },
 
-  @computed("model.last_revision", "model.current_revision", "model.can_edit")
-  displayEdit(lastRevision, currentRevision, canEdit) {
-    return canEdit && lastRevision === currentRevision;
+  @computed(
+    "model.last_revision",
+    "model.current_revision",
+    "model.can_edit",
+    "topicController"
+  )
+  displayEdit(lastRevision, currentRevision, canEdit, topicController) {
+    return !!(canEdit && topicController && lastRevision === currentRevision);
   },
 
   @computed("model.wiki")
diff --git a/app/assets/javascripts/discourse/routes/topic.js.es6 b/app/assets/javascripts/discourse/routes/topic.js.es6
index d0c5b28..cbedc6f 100644
--- a/app/assets/javascripts/discourse/routes/topic.js.es6
+++ b/app/assets/javascripts/discourse/routes/topic.js.es6
@@ -118,14 +118,13 @@ const TopicRoute = Discourse.Route.extend({
     },
 
     showHistory(model, revision) {
-      showModal("history", { model });
-      const historyController = this.controllerFor("history");
-
+      let historyController = showModal("history", {
+        model,
+        modalClass: "history-modal"
+      });
       historyController.refresh(model.get("id"), revision || "latest");
       historyController.set("post", model);
       historyController.set("topicController", this.controllerFor("topic"));
-
-      this.controllerFor("modal").set("modalClass", "history-modal");
     },
 
     showGrantBadgeModal() {
diff --git a/app/assets/javascripts/discourse/templates/components/reviewable-flagged-post.hbs b/app/assets/javascripts/discourse/templates/components/reviewable-flagged-post.hbs
index d79d8a2..be4407f 100644
--- a/app/assets/javascripts/discourse/templates/components/reviewable-flagged-post.hbs
+++ b/app/assets/javascripts/discourse/templates/components/reviewable-flagged-post.hbs
@@ -1,10 +1,20 @@
-{{reviewable-topic-link reviewable=reviewable tagName=''}}
+<div class='flagged-post-header'>
+  {{reviewable-topic-link reviewable=reviewable tagName=''}}
+  {{#if hasEdits}}
+    <a {{action "showEditHistory"}}
+      class="has-edits {{historyClass}}"
+      title="{{i18n "post.last_edited_on"}} {{editedDate}}">
+        {{d-icon "pencil-alt"}}
+    </a>
+  {{/if}}
+</div>
 
 <div class='post-contents-wrapper'>
   {{reviewable-created-by user=reviewable.target_created_by tagName=''}}
   <div class='post-contents'>
     {{reviewable-created-by-name user=reviewable.target_created_by tagName=''}}
     <div class='post-body'>
+
       {{#if reviewable.blank_post}}
         <p>{{i18n "review.deleted_post"}}</p>
       {{else}}
diff --git a/app/assets/javascripts/discourse/templates/modal/history.hbs b/app/assets/javascripts/discourse/templates/modal/history.hbs
index 97444c9..fc6f987 100644
--- a/app/assets/javascripts/discourse/templates/modal/history.hbs
+++ b/app/assets/javascripts/discourse/templates/modal/history.hbs
@@ -122,23 +122,25 @@
     {{/links-redirect}}
   </div>
 {{/d-modal-body}}
-<div class="modal-footer">
-    {{#if displayRevert}}
-      {{d-button action=(action "revertToVersion") icon="undo" label="post.revisions.controls.revert" class="btn-danger" disabled=loading}}
-    {{/if}}
+{{#if topicController}}
+  <div class="modal-footer">
+      {{#if displayRevert}}
+        {{d-button action=(action "revertToVersion") icon="undo" label="post.revisions.controls.revert" class="btn-danger" disabled=loading}}
+      {{/if}}
 
-    {{#if displayHide}}
-      {{d-button action=(action "hideVersion") icon="far-eye-slash" label="post.revisions.controls.hide" class="btn-danger" disabled=loading}}
-    {{/if}}
+      {{#if displayHide}}
+        {{d-button action=(action "hideVersion") icon="far-eye-slash" label="post.revisions.controls.hide" class="btn-danger" disabled=loading}}
+      {{/if}}
 
-    {{#if displayShow}}
-      {{d-button action=(action "showVersion") icon="far-eye" label="post.revisions.controls.show" class="btn-default" disabled=loading}}
-    {{/if}}
+      {{#if displayShow}}
+        {{d-button action=(action "showVersion") icon="far-eye" label="post.revisions.controls.show" class="btn-default" disabled=loading}}
+      {{/if}}
 
-    {{#if displayEdit}}
-      {{d-button action=(action "editPost")
-          icon="pencil-alt"
-          class="btn-default"
-          label=editButtonLabel}}
-    {{/if}}
-</div>
+      {{#if displayEdit}}
+        {{d-button action=(action "editPost")
+            icon="pencil-alt"
+            class="btn-default"
+            label=editButtonLabel}}
+      {{/if}}
+  </div>
+{{/if}}
diff --git a/app/assets/javascripts/discourse/widgets/post-edits-indicator.js.es6 b/app/assets/javascripts/discourse/widgets/post-edits-indicator.js.es6
index 8d5b173..81f339d 100644
--- a/app/assets/javascripts/discourse/widgets/post-edits-indicator.js.es6
+++ b/app/assets/javascripts/discourse/widgets/post-edits-indicator.js.es6
@@ -3,39 +3,39 @@ import { iconNode } from "discourse-common/lib/icon-library";
 import { longDate } from "discourse/lib/formatter";
 import { h } from "virtual-dom";
 
-const FIFTY_HOURS = 60 * 50 * 1000;
+function mult(val) {
+  return 60 * 50 * 1000 * val;
+}
 
-export default createWidget("post-edits-indicator", {
-  tagName: "div.post-info.edits",
+export function historyHeat(siteSettings, updatedAt) {
+  if (!updatedAt) {
+    return;
+  }
 
-  historyHeat(updatedAt) {
-    if (!updatedAt) {
-      return;
-    }
+  // Show heat on age
+  const rightNow = new Date().getTime();
+  const updatedAtTime = updatedAt.getTime();
 
-    // Show heat on age
-    const rightNow = new Date().getTime();
-    const updatedAtTime = updatedAt.getTime();
+  if (updatedAtTime > rightNow - mult(siteSettings.history_hours_low)) {
+    return "heatmap-high";
+  }
 
-    const siteSettings = this.siteSettings;
-    if (updatedAtTime > rightNow - FIFTY_HOURS * siteSettings.history_hours_low)
-      return "heatmap-high";
-    if (
-      updatedAtTime >
-      rightNow - FIFTY_HOURS * siteSettings.history_hours_medium
-    )
-      return "heatmap-med";
-    if (
-      updatedAtTime >
-      rightNow - FIFTY_HOURS * siteSettings.history_hours_high
-    )
-      return "heatmap-low";
-  },

[... diff too long, it was truncated ...]

GitHub sha: 15c9b003

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there: