Show link to the original topic when it was deleted (#7319)

Show link to the original topic when it was deleted (#7319)

  • Moved i18n keys to core. We show a links that points to the original topic when it was deleted

  • Use link-to since it’s more idiomatic

diff --git a/app/assets/javascripts/discourse/templates/components/reviewable-topic-link.hbs b/app/assets/javascripts/discourse/templates/components/reviewable-topic-link.hbs
index af344e0..30d2dc8 100644
--- a/app/assets/javascripts/discourse/templates/components/reviewable-topic-link.hbs
+++ b/app/assets/javascripts/discourse/templates/components/reviewable-topic-link.hbs
@@ -7,6 +7,9 @@
   {{else if (has-block)}}
     {{yield}}
   {{else}}
-    <span class="title-text">{{i18n "topic.deleted"}}</span>
+    <span class="title-text">
+      {{i18n "review.topics.deleted"}}
+      {{link-to (i18n "review.topics.original") "topic" "-" reviewable.removed_topic_id}}
+    </span>
   {{/if}}
 </div>
diff --git a/app/serializers/reviewable_serializer.rb b/app/serializers/reviewable_serializer.rb
index 5719934..51775af 100644
--- a/app/serializers/reviewable_serializer.rb
+++ b/app/serializers/reviewable_serializer.rb
@@ -72,19 +72,19 @@ class ReviewableSerializer < ApplicationSerializer
   end
 
   def attributes
-    data = super
+    super.tap do |data|
+      data[:removed_topic_id] = object.topic_id unless object.topic
 
-    if object.target.present?
-      # Automatically add the target id as a "good name" for example a target_type of `User`
-      # becomes `user_id`
-      data[:"#{object.target_type.downcase}_id"] = object.target_id
-    end
+      if object.target.present?
+        # Automatically add the target id as a "good name" for example a target_type of `User`
+        # becomes `user_id`
+        data[:"#{object.target_type.downcase}_id"] = object.target_id
+      end
 
-    if self.class._payload_for_serialization.present?
-      data[:payload] = (object.payload || {}).slice(*self.class._payload_for_serialization)
+      if self.class._payload_for_serialization.present?
+        data[:payload] = (object.payload || {}).slice(*self.class._payload_for_serialization)
+      end
     end
-
-    data
   end
 
   def topic_tags
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 9b4c052..38405a1 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -404,6 +404,8 @@ en:
         topic: "Topic"
         reviewable_count: "Count"
         reported_by: "Reported by"
+        deleted: "[Topic Deleted]"
+        original: '(original topic)'
         details: "details"
         unique_users:
           one: "1 user"
diff --git a/spec/serializers/reviewable_serializer_spec.rb b/spec/serializers/reviewable_serializer_spec.rb
index 9c5558a..e2ca4c7 100644
--- a/spec/serializers/reviewable_serializer_spec.rb
+++ b/spec/serializers/reviewable_serializer_spec.rb
@@ -6,7 +6,7 @@ describe ReviewableSerializer do
   let(:admin) { Fabricate(:admin) }
 
   it "serializes all the fields" do
-    json = ReviewableSerializer.new(reviewable, scope: Guardian.new(admin), root: nil).as_json
+    json = described_class.new(reviewable, scope: Guardian.new(admin), root: nil).as_json
 
     expect(json[:id]).to eq(reviewable.id)
     expect(json[:status]).to eq(reviewable.status)
@@ -15,6 +15,15 @@ describe ReviewableSerializer do
     expect(json[:category_id]).to eq(reviewable.category_id)
     expect(json[:can_edit]).to eq(true)
     expect(json[:version]).to eq(0)
+    expect(json[:removed_topic_id]).to be_nil
+  end
+
+  it 'Includes the removed topic id when the topis was deleted' do
+    reviewable.topic.trash!(admin)
+
+    json = described_class.new(reviewable.reload, scope: Guardian.new(admin), root: nil).as_json
+
+    expect(json[:removed_topic_id]).to eq reviewable.topic_id
   end
 
   it "will not throw an error when the payload is `nil`" do
@@ -22,5 +31,4 @@ describe ReviewableSerializer do
     json = ReviewableQueuedPostSerializer.new(reviewable, scope: Guardian.new(admin), root: nil).as_json
     expect(json['payload']).to be_blank
   end
-
 end

GitHub sha: 82e05107