diff --git a/app/assets/javascripts/discourse/app/components/post/small-action.gjs b/app/assets/javascripts/discourse/app/components/post/small-action.gjs index e0c8b6aebd5cc..9f53360678f1e 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 code export 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.js index 908adb7c016d5..08fe7c07dd83d 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 = `@${username}`; } else { who = `@${username}`; 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.gjs index 2c45bb6954951..06188b9ad3721 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(); @@ -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.gjs index 092cccff2af6a..a561bb89674ff 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 code module( @@ -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( + + ); + 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;