A platform for community discussion. Free, open, simple.
DEV:Register post-user-title transformer (#34032)
Amanda Alves Branquinho1720a6e057fb
diff --git a/app/assets/javascripts/discourse/app/components/post/meta-data/poster-name.gjs b/app/assets/javascripts/discourse/app/components/post/meta-data/poster-name.gjsindex 87bb6bc1ef8..b380aab9ebc 100644--- a/app/assets/javascripts/discourse/app/components/post/meta-data/poster-name.gjs+++ b/app/assets/javascripts/discourse/app/components/post/meta-data/poster-name.gjs@@ -69,8 +69,18 @@ export default class PostMetaDataPosterName extends Component {return this.args.post.user;}+ get userTitle() {+ return applyValueTransformer(+ "poster-name-user-title",+ this.args.post.user_title,+ {+ post: this.args.post,+ }+ );+ }+get titleClassNames() {- const classNames = [this.args.post.user_title];+ const classNames = [this.userTitle];if (this.args.post.title_is_group && this.args.post.primary_group_name) {classNames.push(this.args.post.primary_group_name);@@ -195,17 +205,17 @@ export default class PostMetaDataPosterName extends Component {</span>{{/if}}- {{#if @post.user_title}}+ {{#if this.userTitle}}<span class={{concatClass "user-title" this.titleClassNames}}>{{#if (and @post.primary_group_name @post.title_is_group)}}<GroupLink@name={{@post.primary_group_name}}@href={{this.primaryGroupHref}}>- {{@post.user_title}}+ {{this.userTitle}}</GroupLink>{{else}}- {{@post.user_title}}+ {{this.userTitle}}{{/if}}</span>{{/if}}diff --git a/app/assets/javascripts/discourse/app/lib/transformer/registry.js b/app/assets/javascripts/discourse/app/lib/transformer/registry.jsindex 1ccd9fe708a..8ad0cb3c9af 100644--- a/app/assets/javascripts/discourse/app/lib/transformer/registry.js+++ b/app/assets/javascripts/discourse/app/lib/transformer/registry.js@@ -60,6 +60,7 @@ export const VALUE_TRANSFORMERS = Object.freeze(["post-small-action-class","post-small-action-custom-component","post-small-action-icon",+ "poster-name-user-title","poster-name-class","small-user-attrs","tag-separator",diff --git a/app/assets/javascripts/discourse/tests/integration/components/post/meta-data/poster-name-test.gjs b/app/assets/javascripts/discourse/tests/integration/components/post/meta-data/poster-name-test.gjsindex 3964b57ad51..1ff7594f064 100644--- a/app/assets/javascripts/discourse/tests/integration/components/post/meta-data/poster-name-test.gjs+++ b/app/assets/javascripts/discourse/tests/integration/components/post/meta-data/poster-name-test.gjs@@ -209,5 +209,19 @@ module(assert.dom("span.custom-class").exists();assert.dom("span.another-class").exists();});++ test("poster-name-user-title transformer", async function (assert) {+ this.post.username = "eviltrout";+ this.post.user_title = "Original Title";++ withPluginApi((api) => {+ api.registerValueTransformer("poster-name-user-title", ({ value }) => {+ return value + " - Transformed";+ });+ });++ await renderComponent(this.post);+ assert.dom(".user-title").hasText("Original Title - Transformed");+ });});