FEATURE: allow adding small action codes dedicated to groups (#14109)

FEATURE: allow adding small action codes dedicated to groups (#14109)

Plugin API is allowing to add small action codes dedicated to groups. This will be used by assign-plugin when topic is assigned or unassigned from group.

diff --git a/app/assets/javascripts/discourse/app/lib/plugin-api.js b/app/assets/javascripts/discourse/app/lib/plugin-api.js
index fa3d98c..71a6210 100644
--- a/app/assets/javascripts/discourse/app/lib/plugin-api.js
+++ b/app/assets/javascripts/discourse/app/lib/plugin-api.js
@@ -53,7 +53,10 @@ import { addPluginOutletDecorator } from "discourse/components/plugin-connector"
 import { addPluginReviewableParam } from "discourse/components/reviewable-item";
 import { addPopupMenuOptionsCallback } from "discourse/controllers/composer";
 import { addPostClassesCallback } from "discourse/widgets/post";
-import { addPostSmallActionIcon } from "discourse/widgets/post-small-action";
+import {
+  addGroupPostSmallActionCode,
+  addPostSmallActionIcon,
+} from "discourse/widgets/post-small-action";
 import { addQuickAccessProfileItem } from "discourse/widgets/quick-access-profile";
 import { addTagsHtmlCallback } from "discourse/lib/render-tags";
 import { addToolbarCallback } from "discourse/components/d-editor";
@@ -81,7 +84,7 @@ import { addSearchResultsCallback } from "discourse/lib/search";
 import { addSearchSuggestion } from "discourse/widgets/search-menu-results";
 
 // If you add any methods to the API ensure you bump up this number
-const PLUGIN_API_VERSION = "0.12.1";
+const PLUGIN_API_VERSION = "0.12.2";
 
 class PluginApi {
   constructor(version, container) {
@@ -716,6 +719,17 @@ class PluginApi {
   }
 
   /**
+   * Register a small action code to be used for small post actions containing a link to a group
+   *
+   * `‍``javascript
+   * api.addGroupPostSmallActionCode('group_assigned');
+   * `‍``
+   **/
+  addGroupPostSmallActionCode(actionCode) {
+    addGroupPostSmallActionCode(actionCode);
+  }
+
+  /**
    * Register an additional query param with topic discovery,
    * this allows for filters on the topic list
    *
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 7607550..7331ce4 100644
--- a/app/assets/javascripts/discourse/app/widgets/post-small-action.js
+++ b/app/assets/javascripts/discourse/app/widgets/post-small-action.js
@@ -16,7 +16,7 @@ export function actionDescriptionHtml(actionCode, createdAt, username) {
 
   let who = "";
   if (username) {
-    if (actionCode === "invited_group" || actionCode === "removed_group") {
+    if (groupActionCodes.includes(actionCode)) {
       who = `<a class="mention-group" href="/g/${username}">@${username}</a>`;
     } else {
       who = `<a class="mention" href="${userPath(username)}">@${username}</a>`;
@@ -34,6 +34,8 @@ export function actionDescription(actionCode, createdAt, username) {
   });
 }
 
+const groupActionCodes = ["invited_group", "removed_group"];
+
 const icons = {
   "closed.enabled": "lock",
   "closed.disabled": "unlock-alt",
@@ -64,6 +66,10 @@ export function addPostSmallActionIcon(key, icon) {
   icons[key] = icon;
 }
 
+export function addGroupPostSmallActionCode(actionCode) {
+  groupActionCodes.push(actionCode);
+}
+
 export default createWidget("post-small-action", {
   buildKey: (attrs) => `post-small-act-${attrs.id}`,
   tagName: "div.small-action.onscreen-post",

GitHub sha: d41aa5e9f53d4c878ac563e37c844c364a642e29

This commit appears in #14109 which was approved by SamSaffron. It was merged by lis2.