A platform for community discussion. Free, open, simple.
FIX: Wrong link to groups in post-small-action widget (#33099)
Alan Guo Xiang Tanff1f2ee0a004
diff --git a/app/assets/javascripts/discourse/app/components/post/small-action.gjs b/app/assets/javascripts/discourse/app/components/post/small-action.gjsindex e0c8b6aebd5..9f53360678f 100644--- a/app/assets/javascripts/discourse/app/components/post/small-action.gjs+++ b/app/assets/javascripts/discourse/app/components/post/small-action.gjs@@ -14,7 +14,7 @@ import { i18n } from "discourse-i18n";// TODO (glimmer-post-stream) remove the export after removing the legacy widget codeexport const GROUP_ACTION_CODES = ["invited_group", "removed_group"];-const customGroupActionCodes = [];+export const customGroupActionCodes = [];export const ICONS = {"closed.enabled": "lock",diff --git a/app/assets/javascripts/discourse/app/widgets/post-small-action.js b/app/assets/javascripts/discourse/app/widgets/post-small-action.jsindex 908adb7c016..08fe7c07dd8 100644--- a/app/assets/javascripts/discourse/app/widgets/post-small-action.js+++ b/app/assets/javascripts/discourse/app/widgets/post-small-action.js@@ -2,6 +2,7 @@ import { computed } from "@ember/object";import { htmlSafe } from "@ember/template";import { h } from "virtual-dom";import {+ customGroupActionCodes,GROUP_ACTION_CODES,ICONS,} from "discourse/components/post/small-action";@@ -24,7 +25,10 @@ export function actionDescriptionHtml(actionCode, createdAt, username, path) {let who = "";if (username) {- if (GROUP_ACTION_CODES.includes(actionCode)) {+ if (+ GROUP_ACTION_CODES.includes(actionCode) ||+ customGroupActionCodes.includes(actionCode)+ ) {who = `<a class="mention-group" href="/g/${username}">@${username}</a>`;} else {who = `<a class="mention" href="${userPath(username)}">@${username}</a>`;diff --git a/app/assets/javascripts/discourse/tests/integration/components/post/small-action-test.gjs b/app/assets/javascripts/discourse/tests/integration/components/post/small-action-test.gjsindex 2c45bb69549..06188b9ad37 100644--- a/app/assets/javascripts/discourse/tests/integration/components/post/small-action-test.gjs+++ b/app/assets/javascripts/discourse/tests/integration/components/post/small-action-test.gjs@@ -4,6 +4,7 @@ import { module, test } from "qunit";import PostSmallAction from "discourse/components/post/small-action";import { withPluginApi } from "discourse/lib/plugin-api";import { setupRenderingTest } from "discourse/tests/helpers/component-test";+import I18n from "discourse-i18n";function renderComponent(post) {return render(<template><PostSmallAction @post={{post}} /></template>);@@ -100,6 +101,36 @@ module("Integration | Component | Post | PostSmallAction", function (hooks) {.exists("the custom icon was rendered");});+ test("api.addGroupPostSmallActionCode", async function (assert) {+ withPluginApi((api) => {+ api.addGroupPostSmallActionCode("some_code");+ });++ this.post.action_code = "some_code";+ this.post.action_code_who = "somegroup";++ I18n.translations[I18n.locale].js.action_codes = {+ some_code: "Some %{who} Code Action",+ };++ await renderComponent(this.post);++ assert+ .dom(".small-action")+ .hasText(+ "Some @somegroup Code Action",+ "the action code text was rendered correctly"+ );++ assert+ .dom("a.mention-group")+ .hasAttribute(+ "href",+ "/g/somegroup",+ "the group mention link has the correct href"+ );+ });+test("api.addPostSmallActionIcon", async function (assert) {withPluginApi((api) => {api.addPostSmallActionIcon("open_topic", "far-circle-check");diff --git a/app/assets/javascripts/discourse/tests/integration/components/widgets/post-small-action-test.gjs b/app/assets/javascripts/discourse/tests/integration/components/widgets/post-small-action-test.gjsindex 092cccff2af..a561bb89674 100644--- a/app/assets/javascripts/discourse/tests/integration/components/widgets/post-small-action-test.gjs+++ b/app/assets/javascripts/discourse/tests/integration/components/widgets/post-small-action-test.gjs@@ -4,6 +4,7 @@ import MountWidget from "discourse/components/mount-widget";import { withSilencedDeprecations } from "discourse/lib/deprecated";import { withPluginApi } from "discourse/lib/plugin-api";import { setupRenderingTest } from "discourse/tests/helpers/component-test";+import I18n from "discourse-i18n";// TODO (glimmer-post-stream) remove this test when removing the widget post stream codemodule(@@ -114,6 +115,42 @@ module(.exists("adds the recover small action button");});+ test("`addGroupPostSmallActionCode` plugin api", async function (assert) {+ const self = this;++ withPluginApi("1.6.0", (api) => {+ api.addGroupPostSmallActionCode("some_code");+ });++ this.set("args", {+ id: 123,+ actionCode: "some_code",+ actionCodeWho: "somegroup",+ });++ I18n.translations[I18n.locale].js.action_codes = {+ some_code: "Some %{who} Code Action",+ };+ await render(+ <template>+ <MountWidget @widget="post-small-action" @args={{self.args}} />+ </template>+ );+ assert+ .dom(".small-action")+ .hasText(+ "Some @somegroup Code Action",+ "the action code text was rendered correctly"+ );+ assert+ .dom("a.mention-group")+ .hasAttribute(+ "href",+ "/g/somegroup",+ "the group mention link has the correct href"+ );+ });+test("`addPostSmallActionClassesCallback` plugin api", async function (assert) {const self = this;