UX: Link directly to the post, not to the topic

This commit is contained in:
Robin Ward 2019-04-01 14:28:57 -04:00
parent fdf4145d4b
commit 6470c85fda
7 changed files with 42 additions and 16 deletions

View File

@ -2,7 +2,7 @@
<div class='post-contents'>
{{reviewable-created-by-name user=reviewable.target_created_by tagName=''}}
{{reviewable-topic-link topic=reviewable.topic}}
{{reviewable-topic-link reviewable=reviewable}}
<div class='post-body'>
{{{reviewable.cooked}}}

View File

@ -3,7 +3,7 @@
<div class='post-contents'>
{{reviewable-created-by-name user=reviewable.created_by tagName=''}}
{{#reviewable-topic-link topic=reviewable.topic}}
{{#reviewable-topic-link reviewable=reviewable}}
{{i18n "review.new_topic"}}
{{reviewable.payload.title}}
{{/reviewable-topic-link}}

View File

@ -1,14 +1,12 @@
{{#if topic}}
<div class='post-topic'>
{{#if topic}}
{{i18n "review.topic"}}
{{topic-status topic=topic}}
{{topic-link topic}}
{{i18n "review.topic_replies" count=topic.reply_count}}
{{else}}
{{yield}}
{{/if}}
</div>
{{else}}
{{i18n "topic.deleted"}}
{{/if}}
<div class='post-topic'>
{{#if reviewable.topic}}
{{i18n "review.topic"}}
{{topic-status topic=reviewable.topic}}
<a href={{reviewable.topic_url}} class='title'>{{reviewable.topic.title}}</a>
{{i18n "review.topic_replies" count=reviewable.topic.reply_count}}
{{else if (has-block)}}
{{yield}}
{{else}}
{{i18n "topic.deleted"}}
{{/if}}
</div>

View File

@ -10,6 +10,7 @@ class ReviewableSerializer < ApplicationSerializer
:status,
:type,
:topic_id,
:topic_url,
:category_id,
:created_at,
:can_edit,
@ -86,6 +87,15 @@ class ReviewableSerializer < ApplicationSerializer
data
end
def topic_url
return object.target.url if object.target.is_a?(Post)
return object.topic.url
end
def include_topic_url?
object.topic_id.present?
end
def include_topic_id?
object.topic_id.present?
end

View File

@ -0,0 +1,16 @@
require 'rails_helper'
describe ReviewableFlaggedPostSerializer do
let(:admin) { Fabricate(:admin) }
it "includes the user fields for review" do
p0 = Fabricate(:post)
reviewable = PostActionCreator.spam(Fabricate(:user), p0).reviewable
json = ReviewableFlaggedPostSerializer.new(reviewable, scope: Guardian.new(admin), root: nil).as_json
expect(json[:cooked]).to be_present
expect(json[:raw]).to be_present
expect(json[:topic_url]).to eq(p0.url)
end
end

View File

@ -48,6 +48,7 @@ describe ReviewableQueuedPostSerializer do
expect(payload['raw']).to eq('hello world post contents.')
expect(payload['title']).to be_blank
expect(json[:topic_id]).to eq(reviewable.topic_id)
expect(json[:topic_url]).to eq(reviewable.topic.url)
expect(json[:can_edit]).to eq(true)
fields = json[:editable_fields]

View File

@ -11,6 +11,7 @@ describe ReviewableUserSerializer do
expect(json[:username]).to eq(reviewable.target.username)
expect(json[:email]).to eq(reviewable.target.email)
expect(json[:name]).to eq(reviewable.target.name)
expect(json[:topic_url]).to be_blank
end
end