A platform for community discussion. Free, open, simple.
UX: separate secondary reviewable actions that don't answer the question posed (#43535)
Krisbf3c2041dbde
diff --git a/app/assets/stylesheets/common/base/review.scss b/app/assets/stylesheets/common/base/review.scssindex 9b46e23205f..770dd6d8d1d 100644--- a/app/assets/stylesheets/common/base/review.scss+++ b/app/assets/stylesheets/common/base/review.scss@@ -500,6 +500,14 @@}}+.review-item__secondary-actions {+ display: flex;+ flex-direction: column;+ gap: var(--space-2);+ padding-top: var(--space-2);+ border-top: 1px solid var(--content-border-color);+}+.review-resources {&__list {@include unstyled-list;diff --git a/app/models/concerns/reviewable_action_builder.rb b/app/models/concerns/reviewable_action_builder.rbindex 52f7af7a796..c61b339c512 100644--- a/app/models/concerns/reviewable_action_builder.rb+++ b/app/models/concerns/reviewable_action_builder.rb@@ -39,9 +39,10 @@ module ReviewableActionBuilderclient_action: nil,confirm: false,require_reject_reason: false,+ secondary: false,source: nil)- actions.add(id, bundle: bundle) do |action|+ actions.add(id, bundle:, secondary:) do |action|source ||= type_sourceif source == "core"prefix = "reviewables.actions.#{id}"diff --git a/app/models/reviewable_flagged_post.rb b/app/models/reviewable_flagged_post.rbindex e190f8e272e..932d1b67151 100644--- a/app/models/reviewable_flagged_post.rb+++ b/app/models/reviewable_flagged_post.rb@@ -168,7 +168,7 @@ class ReviewableFlaggedPost < Reviewablereturn if !author_silenced?return if !guardian.can_unsilence_user?(target_created_by)- build_action(actions, :unsilence_user, icon: "microphone-slash")+ build_action(actions, :unsilence_user, icon: "microphone-slash", secondary: true)enddef perform_ignore(performed_by, args)diff --git a/app/models/reviewable_user.rb b/app/models/reviewable_user.rbindex 72f89f8eb78..40666a6c58c 100644--- a/app/models/reviewable_user.rb+++ b/app/models/reviewable_user.rb@@ -49,7 +49,7 @@ class ReviewableUser < Reviewableendif status == "pending" && target&.uploaded_avatar_id.present?- build_action(actions, :remove_avatar, icon: "user-xmark")+ build_action(actions, :remove_avatar, icon: "user-xmark", secondary: true)endif guardian.can_approve?(target)diff --git a/app/serializers/reviewable_bundled_action_serializer.rb b/app/serializers/reviewable_bundled_action_serializer.rbindex e55241af05d..a347e0217f7 100644--- a/app/serializers/reviewable_bundled_action_serializer.rb+++ b/app/serializers/reviewable_bundled_action_serializer.rb@@ -1,7 +1,7 @@# frozen_string_literal: trueclass ReviewableBundledActionSerializer < ApplicationSerializer- attributes :id, :icon, :label+ attributes :id, :icon, :label, :secondaryhas_many :actions, serializer: ReviewableActionSerializer, root: "actions"def label@@ -15,4 +15,8 @@ class ReviewableBundledActionSerializer < ApplicationSerializerdef include_icon?icon.present?end++ def include_secondary?+ object.secondary+ endenddiff --git a/frontend/discourse/app/components/reviewable/item.gjs b/frontend/discourse/app/components/reviewable/item.gjsindex 1477d45cc2d..36ae2ea928c 100644--- a/frontend/discourse/app/components/reviewable/item.gjs+++ b/frontend/discourse/app/components/reviewable/item.gjs@@ -39,7 +39,7 @@ import Composer from "discourse/models/composer";import { PENDING } from "discourse/models/reviewable";import { CLAIMED, UNCLAIMED } from "discourse/models/reviewable-history";import Topic from "discourse/models/topic";-import { eq, not } from "discourse/truth-helpers";+import { eq, not, or } from "discourse/truth-helpers";import DAsyncContent from "discourse/ui-kit/d-async-content";import DButton from "discourse/ui-kit/d-button";import DHorizontalOverflowNav from "discourse/ui-kit/d-horizontal-overflow-nav";@@ -232,6 +232,18 @@ export default class ReviewableItem extends Component {return this.siteSettings?.reviewable_claiming !== "required";}+ get primaryBundles() {+ return (this.args.reviewable?.bundled_actions ?? []).filter(+ (bundle) => !bundle.secondary+ );+ }++ get secondaryBundles() {+ return (this.args.reviewable?.bundled_actions ?? []).filter(+ (bundle) => bundle.secondary+ );+ }+get tagCategoryId() {return (this.state.updates?.category_id || this.args.reviewable?.category?.id@@ -865,7 +877,7 @@ export default class ReviewableItem extends Component {@label="review.cancel"/>{{else}}- {{#each @reviewable.bundled_actions as |bundle|}}+ {{#each this.primaryBundles as |bundle|}}<ReviewableBundledAction@authorPenalties={{@reviewable.author_penalties}}@bundle={{bundle}}@@ -874,13 +886,26 @@ export default class ReviewableItem extends Component {/>{{/each}}- {{#if @reviewable.can_edit}}- <DButton- class="reviewable-action btn-default edit"- @action={{this.edit}}- @disabled={{this.disabled}}- @label="review.edit"- />+ {{#if (or this.secondaryBundles.length @reviewable.can_edit)}}+ <div class="review-item__secondary-actions">+ {{#each this.secondaryBundles as |bundle|}}+ <ReviewableBundledAction+ @authorPenalties={{@reviewable.author_penalties}}+ @bundle={{bundle}}+ @performAction={{this.perform}}+ @reviewableUpdating={{this.disabled}}+ />+ {{/each}}++ {{#if @reviewable.can_edit}}+ <DButton+ class="reviewable-action btn-default edit"+ @action={{this.edit}}+ @disabled={{this.disabled}}+ @label="review.edit"+ />+ {{/if}}+ </div>{{/if}}{{/if}}</div>diff --git a/frontend/discourse/tests/integration/components/reviewable/item-test.gjs b/frontend/discourse/tests/integration/components/reviewable/item-test.gjsindex d65dcebac73..a328ff43d01 100644--- a/frontend/discourse/tests/integration/components/reviewable/item-test.gjs+++ b/frontend/discourse/tests/integration/components/reviewable/item-test.gjs@@ -177,6 +177,31 @@ module("Integration | Component | Reviewable | Item", function (hooks) {assert.dom(".review-item__aside-title").hasText("Moderator actions");});+ test("lists secondary actions below the answers to the context question", async function (assert) {+ const pending = userReviewable(this, {+ bundled_actions: [+ actionBundle("approve_user", "Yes"),+ { ...actionBundle("remove_avatar", "Remove avatar"), secondary: true },+ actionBundle("delete_user", "No"),+ ],+ });++ await render(+ <template><ReviewableItem @reviewable={{pending}} /></template>+ );++ const answers = [+ ...document.querySelectorAll(+ ".review-item__moderator-actions > .reviewable-action"+ ),+ ].map((button) => button.textContent.trim());++ assert.deepEqual(answers, ["Yes", "No"], "the answers stay together");+ assert+ .dom(".review-item__secondary-actions .reviewable-action")+ .hasText("Remove avatar", "the secondary action is set apart");+ });+test("does not render help resources when not required", async function (assert) {await render(<template><ReviewableItem @reviewable={{reviewable}} /></template>diff --git a/lib/reviewable/actions.rb b/lib/reviewable/actions.rbindex 04d7e4ca43a..b42e673929b 100644--- a/lib/reviewable/actions.rb+++ b/lib/reviewable/actions.rb@@ -22,12 +22,15 @@ class Reviewable < ActiveRecord::Baseendclass Bundle < Item- attr_accessor :icon, :label, :actions+ attr_accessor :icon, :label, :actions, :secondary- def initialize(id, icon: nil, label: nil)+ # A secondary bundle holds actions that don't resolve the reviewable, so+ # the client lists them apart from the answers to its context question.+ def initialize(id, icon: nil, label: nil, secondary: false)super(id)@icon = icon@label = label+ @secondary = secondary@actions = []end@@ -71,8 +74,8 @@ class Reviewable < ActiveRecord::Baseendend- def add_bundle(id, icon: nil, label: nil)- bundle = Bundle.new(id, icon: icon, label: label)+ def add_bundle(id, icon: nil, label: nil, secondary: false)+ bundle = Bundle.new(id, icon:, label:, secondary:)@bundles << bundlebundleend@@ -81,14 +84,14 @@ class Reviewable < ActiveRecord::Base# id-keyed collection for the whole queue. Two reviewables offering the same# action would otherwise collapse into a single record, and every one of# them would render the last copy. Bundle ids are scoped by their callers.- def add(id, bundle: nil)+ def add(id, bundle: nil, secondary: false)action_name = [reviewable.target_type&.underscore, id].compact_blank.join("-")scoped_id = [reviewable.id, action_name].compact_blank.join("-")action = Actions.common_actions[action_name] || Action.new(scoped_id)yield action if block_given?@content << action- bundle ||= add_bundle(scoped_id)+ bundle ||= add_bundle(scoped_id, secondary:)bundle.actions << actionendenddiff --git a/plugins/chat/app/models/chat/reviewable_message.rb b/plugins/chat/app/models/chat/reviewable_message.rbindex 964789693e7..2b78d763468 100644--- a/plugins/chat/app/models/chat/reviewable_message.rb+++ b/plugins/chat/app/models/chat/reviewable_message.rb@@ -109,7 +109,7 @@ module Chatreturn if !chat_message_creator&.silenced?return if !guardian.can_unsilence_user?(chat_message_creator)- build_action(actions, :unsilence_user, icon: "microphone-slash")+ build_action(actions, :unsilence_user, icon: "microphone-slash", secondary: true)enddef penalty_effect_for(action_id)diff --git a/plugins/chat/spec/models/chat/reviewable_chat_message_spec.rb b/plugins/chat/spec/models/chat/reviewable_chat_message_spec.rbindex 6ee475d0a7e..09cd9a68e1a 100644--- a/plugins/chat/spec/models/chat/reviewable_chat_message_spec.rb+++ b/plugins/chat/spec/models/chat/reviewable_chat_message_spec.rb@@ -168,6 +168,12 @@ RSpec.describe Chat::ReviewableMessage, type: :model doexpect(I18n.t(action.completed_message)).to eq("Author unsilenced.")end+ it "is set apart from the actions that resolve the flag" do+ secondary_bundles = reviewable.actions_for(moderator.guardian).bundles.select(&:secondary)++ expect(secondary_bundles.flat_map(&:actions).map(&:server_action)).to eq(["unsilence_user"])+ end+it "is not offered to a user who cannot unsilence the author" doexpect(unsilence_action(Fabricate(:user).guardian)).to eq(nil)enddiff --git a/spec/models/reviewable_flagged_post_spec.rb b/spec/models/reviewable_flagged_post_spec.rbindex 34151ee2f73..4f4b56ff0b2 100644--- a/spec/models/reviewable_flagged_post_spec.rb+++ b/spec/models/reviewable_flagged_post_spec.rb@@ -560,6 +560,14 @@ RSpec.describe ReviewableFlaggedPost, type: :model doexpect(reviewable.reload.actions_for(guardian).has?(:unsilence_user)).to eq(true)end+ it "is set apart from the actions that resolve the reviewable" do+ UserSilencer.silence(author, moderator, post_id: flagged_post.id)++ secondary_bundles = reviewable.reload.actions_for(guardian).bundles.select(&:secondary)++ expect(secondary_bundles.flat_map(&:actions).map(&:server_action)).to eq(["unsilence_user"])+ end+it "is offered even when the silence is not linked to this post" doother_post = Fabricate(:post, user: author)UserSilencer.silence(author, moderator, post_id: other_post.id)diff --git a/spec/models/reviewable_user_spec.rb b/spec/models/reviewable_user_spec.rbindex 6f8ac09034e..0cff3c1ed90 100644--- a/spec/models/reviewable_user_spec.rb+++ b/spec/models/reviewable_user_spec.rb@@ -286,6 +286,12 @@ RSpec.describe ReviewableUser, type: :model doexpect(reviewable.actions_for(Guardian.new(moderator)).has?(:remove_avatar)).to eq(false)end++ it "is set apart from the approve and reject answers" do+ secondary_bundles = reviewable.actions_for(moderator.guardian).bundles.select(&:secondary)++ expect(secondary_bundles.flat_map(&:actions).map(&:server_action)).to eq(["remove_avatar"])+ endendcontext "when approving" dodiff --git a/spec/serializers/reviewable_bundled_action_serializer_spec.rb b/spec/serializers/reviewable_bundled_action_serializer_spec.rbnew file mode 100644index 00000000000..bae03f1a780--- /dev/null+++ b/spec/serializers/reviewable_bundled_action_serializer_spec.rb@@ -0,0 +1,20 @@+# frozen_string_literal: true++RSpec.describe ReviewableBundledActionSerializer do+ fab!(:admin)+ fab!(:reviewable, :reviewable_user)++ it "includes the secondary flag only on secondary bundles" do+ reviewable.target.update!(uploaded_avatar_id: Fabricate(:upload).id)++ json =+ reviewable+ .actions_for(admin.guardian)+ .bundles+ .map { |bundle| described_class.new(bundle, root: false).as_json }++ expect(json.select { |bundle| bundle.key?(:secondary) }).to contain_exactly(+ include(id: "#{reviewable.id}-user-remove_avatar", secondary: true),+ )+ end+end