Skip to content

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

DEV: Extract help resources into conditional component (#35592)

Krzysztof Kotlarek58165eec7f5d
diff --git a/frontend/discourse/app/components/reviewable-refresh/help-resources.gjs b/frontend/discourse/app/components/reviewable-refresh/help-resources.gjs
new file mode 100644
index 00000000000..5e2ea157164
--- /dev/null
+++ b/frontend/discourse/app/components/reviewable-refresh/help-resources.gjs
@@ -0,0 +1,49 @@
+import Component from "@glimmer/component";
+import { service } from "@ember/service";
+import icon from "discourse/helpers/d-icon";
+import { i18n } from "discourse-i18n";
+
+export default class ReviewableHelpResources extends Component {
+ @service siteSettings;
+
+ <template>
+ <div class="review-item__resources">
+ <h3 class="review-item__aside-title">{{i18n "review.need_help"}}</h3>
+ <ul class="review-resources__list">
+ <li class="review-resources__item">
+ <span class="review-resources__icon">
+ {{icon "book"}}
+ </span>
+ <a
+ href={{this.siteSettings.moderation_guide_url}}
+ class="review-resources__link"
+ >
+ {{i18n "review.help.moderation_guide"}}
+ </a>
+ </li>
+ <li class="review-resources__item">
+ <span class="review-resources__icon">
+ {{icon "book"}}
+ </span>
+ <a
+ href={{this.siteSettings.flag_priorities_url}}
+ class="review-resources__link"
+ >
+ {{i18n "review.help.flag_priorities"}}
+ </a>
+ </li>
+ <li class="review-resources__item">
+ <span class="review-resources__icon">
+ {{icon "book"}}
+ </span>
+ <a
+ href={{this.siteSettings.spam_detection_url}}
+ class="review-resources__link"
+ >
+ {{i18n "review.help.spam_detection"}}
+ </a>
+ </li>
+ </ul>
+ </div>
+ </template>
+}
diff --git a/frontend/discourse/app/components/reviewable-refresh/insights.gjs b/frontend/discourse/app/components/reviewable-refresh/insights.gjs
index 520cbb73c5c..1a4ad90fe97 100644
--- a/frontend/discourse/app/components/reviewable-refresh/insights.gjs
+++ b/frontend/discourse/app/components/reviewable-refresh/insights.gjs
@@ -47,11 +47,13 @@ export default class ReviewableInsights extends Component {
if (Date.now() - Date.parse(user.created_at) < 7 * 24 * 60 * 60 * 1000) {
activities.push(i18n("review.insights.activities.new_account"));
}
- activities.push(
- i18n("review.insights.activities.trust_level", {
- trustLevelName: user.trustLevel.name,
- })
- );
+ if (user.trustLevel) {
+ activities.push(
+ i18n("review.insights.activities.trust_level", {
+ trustLevelName: user.trustLevel.name,
+ })
+ );
+ }
activities.push(
i18n("review.insights.activities.posts", {
count: user.post_count,
diff --git a/frontend/discourse/app/components/reviewable-refresh/item.gjs b/frontend/discourse/app/components/reviewable-refresh/item.gjs
index eddc67b0d29..ccd21dba8c6 100644
--- a/frontend/discourse/app/components/reviewable-refresh/item.gjs
+++ b/frontend/discourse/app/components/reviewable-refresh/item.gjs
@@ -19,6 +19,7 @@ import ReviewableBundledAction from "discourse/components/reviewable-bundled-act
import ReviewableClaimedTopic from "discourse/components/reviewable-claimed-topic";
import ReviewableCreatedBy from "discourse/components/reviewable-created-by";
import ReviewableFlagReason from "discourse/components/reviewable-refresh/flag-reason";
+import ReviewableHelpResources from "discourse/components/reviewable-refresh/help-resources";
import ReviewableInsights from "discourse/components/reviewable-refresh/insights";
import ReviewableTimeline from "discourse/components/reviewable-refresh/timeline";
import concatClass from "discourse/helpers/concat-class";
@@ -713,66 +714,19 @@ export default class ReviewableItem extends Component {
{{/if}}
{{/unless}}
- <div class="review-item__moderator-actions --extra">
- {{#if this.claimEnabled}}
+ {{#if this.claimEnabled}}
+ <div class="review-item__moderator-actions --extra">
<ReviewableClaimedTopic
@topicId={{this.topicId}}
@claimedBy={{this.reviewable.claimed_by}}
@onClaim={{fn (mut this.reviewable.claimed_by)}}
/>
- {{/if}}
- <DButton
- @label="review.copy_link"
- @icon="link"
- class="btn-secondary"
- />
- <DButton
- @label="review.view_source"
- @icon="code"
- class="btn-secondary"
- />
- </div>
+ </div>
+ {{/if}}
- <div class="review-item__resources">
- <h3 class="review-item__aside-title">{{i18n
- "review.need_help"
- }}</h3>
- <ul class="review-resources__list">
- <li class="review-resources__item">
- <span class="review-resources__icon">
- {{icon "book"}}
- </span>
- <a
- href={{this.siteSettings.moderation_guide_url}}
- class="review-resources__link"
- >
- {{i18n "review.help.moderation_guide"}}
- </a>
- </li>
- <li class="review-resources__item">
- <span class="review-resources__icon">
- {{icon "book"}}
- </span>
- <a
- href={{this.siteSettings.flag_priorities_url}}
- class="review-resources__link"
- >
- {{i18n "review.help.flag_priorities"}}
- </a>
- </li>
- <li class="review-resources__item">
- <span class="review-resources__icon">
- {{icon "book"}}
- </span>
- <a
- href={{this.siteSettings.spam_detection_url}}
- class="review-resources__link"
- >
- {{i18n "review.help.spam_detection"}}
- </a>
- </li>
- </ul>
- </div>
+ {{#if @showHelp}}
+ <ReviewableHelpResources />
+ {{/if}}
</div>
</div>
</div>
diff --git a/frontend/discourse/app/templates/review/show.gjs b/frontend/discourse/app/templates/review/show.gjs
index f3e30d08a60..dda23e964e3 100644
--- a/frontend/discourse/app/templates/review/show.gjs
+++ b/frontend/discourse/app/templates/review/show.gjs
@@ -49,7 +49,10 @@ export default RouteTemplate(
{{i18n "review.back_to_queue"}}
</LinkTo>
</div>
- <ReviewableItemRefresh @reviewable={{@controller.reviewable}} />
+ <ReviewableItemRefresh
+ @reviewable={{@controller.reviewable}}
+ @showHelp={{true}}
+ />
{{else}}
<ul class="nav nav-pills reviewable-title">
<NavItem @route="review.index" @label="review.view_all" />
diff --git a/frontend/discourse/tests/integration/components/reviewable-refresh/item-test.gjs b/frontend/discourse/tests/integration/components/reviewable-refresh/item-test.gjs
new file mode 100644
index 00000000000..9f1d45c5eeb
--- /dev/null
+++ b/frontend/discourse/tests/integration/components/reviewable-refresh/item-test.gjs
@@ -0,0 +1,70 @@
+import { render } from "@ember/test-helpers";
+import { module, test } from "qunit";
+import ReviewableItemRefresh from "discourse/components/reviewable-refresh/item";
+import { setupRenderingTest } from "discourse/tests/helpers/component-test";
+
+module("Integration | Component | reviewable-refresh | item", function (hooks) {
+ setupRenderingTest(hooks);
+ hooks.beforeEach(function () {
+ this.siteSettings.moderation_guide_url =
+ "https://example.com/moderation_guide";
+ this.siteSettings.flag_priorities_url =
+ "https://example.com/flag_priorities";
+ this.siteSettings.spam_detection_url = "https://example.com/spam_detection";
+ });
+
+ const reviewable = {
+ topic: {
+ fancyTitle: "Test Topic Title",
+ id: 123,
+ },
+ target_url: "/t/test-topic/123",
+ category: {
+ id: 5,
+ name: "General",
+ color: "0088CC",
+ },
+ topic_tags: ["tag1", "tag2"],
+ type: "topic",
+ reviewable_scores: [],
+ target_created_by: {
+ id: 1,
+ username: "testuser",
+ name: "Test User",
+ flags_agreed: 0,
+ },
+ };
+
+ test("renders help resources ", async function (assert) {
+ await render(
+ <template>
+ <ReviewableItemRefresh @reviewable={{reviewable}} @showHelp={{true}} />
+ </template>
+ );
+ assert.dom(".review-item__resources").exists("renders the help content");
+ assert
+ .dom(
+ `a.review-resources__link[href="https://example.com/moderation_guide"]`
+ )
+ .exists();
+ assert
+ .dom(
+ `a.review-resources__link[href="https://example.com/flag_priorities"]`
+ )
+ .exists();
+ assert
+ .dom(
+ `a.review-resources__link[href="https://example.com/spam_detection"]`
+ )
+ .exists();
+ });
+
+ test("does not render help resources when not required", async function (assert) {
+ await render(
+ <template><ReviewableItemRefresh @reviewable={{reviewable}} /></template>
+ );
+ assert
+ .dom(".review-item__resources")
+ .doesNotExist("does not render the help content");
+ });
+});