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.
This commit is contained in:
Robin Ward 2019-05-03 09:42:43 -04:00
parent 5f78bbebe9
commit 15c9b00307
9 changed files with 123 additions and 55 deletions

View File

@ -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);
});
}
}
});

View File

@ -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")

View File

@ -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() {

View File

@ -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}}

View File

@ -122,7 +122,8 @@
{{/links-redirect}}
</div>
{{/d-modal-body}}
<div class="modal-footer">
{{#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}}
@ -141,4 +142,5 @@
class="btn-default"
label=editButtonLabel}}
{{/if}}
</div>
</div>
{{/if}}

View File

@ -3,12 +3,11 @@ 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",
historyHeat(updatedAt) {
export function historyHeat(siteSettings, updatedAt) {
if (!updatedAt) {
return;
}
@ -17,25 +16,26 @@ export default createWidget("post-edits-indicator", {
const rightNow = new Date().getTime();
const updatedAtTime = updatedAt.getTime();
const siteSettings = this.siteSettings;
if (updatedAtTime > rightNow - FIFTY_HOURS * siteSettings.history_hours_low)
if (updatedAtTime > rightNow - mult(siteSettings.history_hours_low)) {
return "heatmap-high";
if (
updatedAtTime >
rightNow - FIFTY_HOURS * siteSettings.history_hours_medium
)
}
if (updatedAtTime > rightNow - mult(siteSettings.history_hours_medium)) {
return "heatmap-med";
if (
updatedAtTime >
rightNow - FIFTY_HOURS * siteSettings.history_hours_high
)
}
if (updatedAtTime > rightNow - mult(siteSettings.history_hours_high)) {
return "heatmap-low";
},
}
}
export default createWidget("post-edits-indicator", {
tagName: "div.post-info.edits",
html(attrs) {
let icon = "pencil-alt";
const updatedAt = new Date(attrs.updated_at);
let className = this.historyHeat(updatedAt);
let className = historyHeat(this.siteSettings, updatedAt);
const date = longDate(updatedAt);
let title;

View File

@ -1,4 +1,10 @@
.reviewable {
.flagged-post-header {
width: 100%;
display: flex;
justify-content: space-between;
}
.status {
color: $primary-medium;
span.approved {

View File

@ -1,6 +1,10 @@
class ReviewableFlaggedPostSerializer < ReviewableSerializer
target_attributes :cooked, :raw, :reply_count
attributes :blank_post
target_attributes :cooked, :raw, :reply_count, :version
attributes :blank_post, :post_updated_at
def post_updated_at
object.target&.updated_at
end
def blank_post
true

View File

@ -4,7 +4,8 @@ QUnit.test("displayEdit", function(assert) {
const HistoryController = this.subject();
HistoryController.setProperties({
model: { last_revision: 3, current_revision: 3, can_edit: false }
model: { last_revision: 3, current_revision: 3, can_edit: false },
topicController: {}
});
assert.equal(
@ -21,6 +22,14 @@ QUnit.test("displayEdit", function(assert) {
"it should display edit button when user can edit the post"
);
HistoryController.set("topicController", null);
assert.equal(
HistoryController.get("displayEdit"),
false,
"it should not display edit button when there is not topic controller"
);
HistoryController.set("topicController", {});
HistoryController.set("model.current_revision", 2);
assert.equal(
HistoryController.get("displayEdit"),