Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Update the ReviewablePostVotingComment UI (#35675)

Krzysztof Kotlarek04190f192dcc
diff --git a/plugins/discourse-post-voting/app/models/reviewable_post_voting_comment.rb b/plugins/discourse-post-voting/app/models/reviewable_post_voting_comment.rb
index a855ca9777e..977af6b17e5 100644
--- a/plugins/discourse-post-voting/app/models/reviewable_post_voting_comment.rb
+++ b/plugins/discourse-post-voting/app/models/reviewable_post_voting_comment.rb
@@ -1,6 +1,8 @@
# frozen_string_literal: true
class ReviewablePostVotingComment < Reviewable
+ include ReviewableActionBuilder
+
def serializer
ReviewablePostVotingCommentSerializer
end
@@ -30,7 +32,8 @@ class ReviewablePostVotingComment < Reviewable
@comment_creator ||= User.find_by(id: comment.user_id)
end
- def build_actions(actions, guardian, args)
+ # TODO (reviewable-refresh): Remove this method when fully migrated to new UI
+ def build_legacy_combined_actions(actions, guardian, args)
return unless pending?
return if comment.blank?
@@ -73,6 +76,33 @@ class ReviewablePostVotingComment < Reviewable
end
end
+ # TODO (reviewable-refresh): Merge this method into build_actions when fully migrated to new UI
+ def build_new_separated_actions
+ bundle_actions = { no_action_comment: {} }
+ if comment.deleted_at?
+ bundle_actions[:agree_and_restore] = {}
+ bundle_actions[:disagree_and_restore] = {}
+ else
+ bundle_actions[:agree_and_delete] = {}
+ bundle_actions[:agree_and_keep_comment] = {}
+ end
+
+ build_bundle(
+ "#{id}-comment-actions",
+ "discourse_post_voting.reviewables.actions.comment_actions.bundle_title",
+ bundle_actions,
+ )
+ build_user_actions_bundle
+ end
+
+ def perform_no_action_comment(performed_by, args)
+ if comment.deleted_at?
+ create_result(:success, :approved, [created_by_id], true)
+ else
+ create_result(:success, :rejected, [created_by_id], true)
+ end
+ end
+
def perform_agree_and_keep_comment(performed_by, args)
agree
end
@@ -128,26 +158,6 @@ class ReviewablePostVotingComment < Reviewable
result.update_flag_stats = { status: :ignored, user_ids: flagged_by_user_ids }
end
end
-
- def build_action(
- actions,
- id,
- icon:,
- button_class: nil,
- bundle: nil,
- client_action: nil,
- confirm: false
- )
- actions.add(id, bundle: bundle) do |action|
- prefix = "reviewables.actions.#{id}"
- action.icon = icon
- action.button_class = button_class
- action.label = "post_voting.comment.#{prefix}.title"
- action.description = "post_voting.comment.#{prefix}.description"
- action.client_action = client_action
- action.confirm_message = "#{prefix}.confirm" if confirm
- end
- end
end
# == Schema Information
diff --git a/plugins/discourse-post-voting/assets/javascripts/discourse/components/reviewable-refresh/post-voting-comment.gjs b/plugins/discourse-post-voting/assets/javascripts/discourse/components/reviewable-refresh/post-voting-comment.gjs
new file mode 100644
index 00000000000..84748a0c121
--- /dev/null
+++ b/plugins/discourse-post-voting/assets/javascripts/discourse/components/reviewable-refresh/post-voting-comment.gjs
@@ -0,0 +1,35 @@
+import ReviewablePostEdits from "discourse/components/reviewable-post-edits";
+import ReviewableCreatedBy from "discourse/components/reviewable-refresh/created-by";
+import ReviewableTopicLink from "discourse/components/reviewable-refresh/topic-link";
+import highlightWatchedWords from "discourse/lib/highlight-watched-words";
+import { i18n } from "discourse-i18n";
+
+export default <template>
+ <div class="review-item__meta-content">
+ <div class="review-item__meta-label">{{i18n "review.posted_in"}}</div>
+
+ <div class="review-item__meta-topic-title">
+ <ReviewableTopicLink @reviewable={{@reviewable}} @tagName="" />
+ <ReviewablePostEdits @reviewable={{@reviewable}} @tagName="" />
+ </div>
+
+ <div class="review-item__meta-label">{{i18n "review.review_user"}}</div>
+
+ <div class="review-item__meta-flagged-user">
+ <ReviewableCreatedBy @user={{@reviewable.target_created_by}} />
+ </div>
+ </div>
+
+ <div class="review-item__post">
+ <div class="review-item__post-content-wrapper">
+ <div class="review-item__post-content">
+ {{#if @reviewable.blank_post}}
+ <p>{{i18n "review.deleted_post"}}</p>
+ {{else}}
+ {{highlightWatchedWords @reviewable.cooked @reviewable}}
+ {{/if}}
+ {{yield}}
+ </div>
+ </div>
+ </div>
+</template>
diff --git a/plugins/discourse-post-voting/config/locales/server.en.yml b/plugins/discourse-post-voting/config/locales/server.en.yml
index 970b582fe47..a629ef1f17a 100644
--- a/plugins/discourse-post-voting/config/locales/server.en.yml
+++ b/plugins/discourse-post-voting/config/locales/server.en.yml
@@ -32,6 +32,29 @@ en:
keywords:
flag_posts_voting_comments_allowed_groups: "min_trust_to_flag_posts_voting_comments"
+ discourse_post_voting:
+ reviewables:
+ actions:
+ comment_actions:
+ bundle_title: "What do you want to do with the comment?"
+ no_action_comment:
+ title: "No action"
+ description: "Leave the comment as is."
+ agree_and_keep_comment:
+ title: "Keep comment"
+ description: "Agree with flag and keep the comment unchanged."
+ agree_and_keep_deleted:
+ title: "Keep comment Deleted"
+ description: "Agree with flag and leave the comment deleted."
+ agree_and_restore:
+ title: "Restore comment"
+ description: "Restore the comment so that users can see it."
+ agree_and_delete:
+ title: "Delete comment"
+ description: "Delete the comment so that users cannot see it."
+ disagree_and_restore:
+ title: "Disagree and Restore comment"
+ description: "Restore the comment so that all users can see it."
post_action_types:
vote:
diff --git a/plugins/discourse-post-voting/spec/fabricators/post_voting_comment_fabricator.rb b/plugins/discourse-post-voting/spec/fabricators/post_voting_comment_fabricator.rb
index c851120ff43..45b3e3b1d77 100644
--- a/plugins/discourse-post-voting/spec/fabricators/post_voting_comment_fabricator.rb
+++ b/plugins/discourse-post-voting/spec/fabricators/post_voting_comment_fabricator.rb
@@ -12,4 +12,5 @@ Fabricator(:reviewable_post_voting_comment, class_name: "ReviewablePostVotingCom
created_by { Fabricate(:user) }
target { Fabricate(:post_voting_comment) }
reviewable_scores { |p| [Fabricate.build(:reviewable_score, reviewable_id: p[:id])] }
+ payload { { comment_cooked: "cooked" } }
end
diff --git a/plugins/discourse-post-voting/spec/system/viewing_reviewable_spec.rb b/plugins/discourse-post-voting/spec/system/viewing_reviewable_spec.rb
new file mode 100644
index 00000000000..9aee291b8ab
--- /dev/null
+++ b/plugins/discourse-post-voting/spec/system/viewing_reviewable_spec.rb
@@ -0,0 +1,57 @@
+# frozen_string_literal: true
+
+describe "Viewing reviewable post voting comment", type: :system do
+ fab!(:admin)
+ fab!(:group)
+ fab!(:topic) { Fabricate(:topic, subtype: Topic::POST_VOTING_SUBTYPE) }
+ fab!(:reply) { Fabricate(:post, topic: topic) }
+ fab!(:comment) { Fabricate(:post_voting_comment, post: reply) }
+ fab!(:reviewable) { Fabricate(:reviewable_post_voting_comment, target: comment, topic: topic) }
+ let(:refreshed_review_page) { PageObjects::Pages::RefreshedReview.new }
+
+ before do
+ SiteSetting.reviewable_ui_refresh = group.name
+ group.add(admin)
+ sign_in(admin)
+ end
+
+ it "Allows to delete and restore comment" do
+ refreshed_review_page.visit_reviewable(reviewable)
+
+ expect(page).to have_text(comment.raw)
+
+ refreshed_review_page.select_bundled_action(reviewable, "post_voting_comment-agree_and_delete")
+ expect(refreshed_review_page).to have_reviewable_with_approved_status(reviewable)
+
+ refreshed_review_page.visit_reviewable(reviewable)
+ expect(page).not_to have_text(comment.raw)
+
+ refreshed_review_page.select_bundled_action(reviewable, "post_voting_comment-agree_and_restore")
+ expect(refreshed_review_page).to have_reviewable_with_approved_status(reviewable)
+ expect(page).to have_text(comment.raw)
+
+ refreshed_review_page.select_bundled_action(reviewable, "post_voting_comment-agree_and_delete")
+ refreshed_review_page.select_bundled_action(
+ reviewable,
+ "post_voting_comment-disagree_and_restore",
+ )
+ expect(refreshed_review_page).to have_reviewable_with_rejected_status(reviewable)
+ end
+
+ it "Allows to ignore the reviewable" do
+ refreshed_review_page.visit_reviewable(reviewable)
+
+ refreshed_review_page.select_bundled_action(reviewable, "post_voting_comment-no_action_comment")
+ expect(refreshed_review_page).to have_reviewable_with_rejected_status(reviewable)
+ end
+
+ it "Allows to keep comment" do
+ refreshed_review_page.visit_reviewable(reviewable)
+
+ refreshed_review_page.select_bundled_action(
+ reviewable,
+ "post_voting_comment-agree_and_keep_comment",
+ )
+ expect(refreshed_review_page).to have_reviewable_with_approved_status(reviewable)
+ end
+end