File tree Expand file tree Collapse file tree 4 files changed +38
-0
lines changed
app/assets/javascripts/discourse
components/post/meta-data
tests/integration/components/post/meta-data Expand file tree Collapse file tree 4 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,12 @@ export default class PostMetaDataPosterName extends Component {
82
82
);
83
83
}
84
84
85
+ get additionalClasses () {
86
+ return applyValueTransformer (" poster-name-class" , [], {
87
+ user: this .user ,
88
+ });
89
+ }
90
+
85
91
@bind
86
92
refreshUserStatus () {
87
93
this .#stopTrackingUserStatus ();
@@ -139,6 +145,7 @@ export default class PostMetaDataPosterName extends Component {
139
145
@ post.primary_group_name
140
146
( concat " group--" @ post.primary_group_name)
141
147
)
148
+ this . additionalClasses
142
149
}}
143
150
>
144
151
{{! use the position argument to choose between the first and second name if needed}}
Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ export const VALUE_TRANSFORMERS = Object.freeze([
50
50
"post-small-action-custom-component" ,
51
51
"post-small-action-icon" ,
52
52
"post-text-selection-prevent-close" ,
53
+ "poster-name-class" ,
53
54
"site-setting-enable-welcome-banner" ,
54
55
"site-setting-search-experience" ,
55
56
"small-user-attrs" ,
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { h } from "virtual-dom";
3
3
import getURL from "discourse/lib/get-url" ;
4
4
import { iconNode } from "discourse/lib/icon-library" ;
5
5
import { prioritizeNameInUx } from "discourse/lib/settings" ;
6
+ import { applyValueTransformer } from "discourse/lib/transformer" ;
6
7
import { formatUsername } from "discourse/lib/utilities" ;
7
8
import RenderGlimmer from "discourse/widgets/render-glimmer" ;
8
9
import { applyDecorators , createWidget } from "discourse/widgets/widget" ;
@@ -105,6 +106,12 @@ export default createWidget("poster-name", {
105
106
) ;
106
107
} ,
107
108
109
+ additionalClasses ( attrs ) {
110
+ return applyValueTransformer ( "poster-name-class" , [ ] , {
111
+ user : attrs . user ,
112
+ } ) ;
113
+ } ,
114
+
108
115
html ( attrs ) {
109
116
const username = attrs . username ;
110
117
const name = attrs . name ;
@@ -129,6 +136,7 @@ export default createWidget("poster-name", {
129
136
if ( attrs . new_user ) {
130
137
classNames . push ( "new-user" ) ;
131
138
}
139
+ classNames . push ( ...this . additionalClasses ( attrs ) ) ;
132
140
133
141
const primaryGroupName = attrs . primary_group_name ;
134
142
if ( primaryGroupName && primaryGroupName . length ) {
Original file line number Diff line number Diff line change @@ -187,5 +187,27 @@ module(
187
187
.dom (" span.poster-icon.test-smile > a > .emoji[alt='smile']" )
188
188
.exists ();
189
189
});
190
+
191
+ test (" poster name additional classes" , async function (assert ) {
192
+ this .post .username = " eviltrout" ;
193
+ this .post .user = this .store .createRecord (" user" , {
194
+ username: " eviltrout" ,
195
+ });
196
+ withPluginApi ((api ) => {
197
+ api .registerValueTransformer (
198
+ " poster-name-class" ,
199
+ ({ value, context }) => {
200
+ if (context .user .username === " eviltrout" ) {
201
+ value .push (... [" custom-class" , " another-class" ]);
202
+ }
203
+ return value;
204
+ }
205
+ );
206
+ });
207
+
208
+ await renderComponent (this .post );
209
+ assert .dom (" span.custom-class" ).exists ();
210
+ assert .dom (" span.another-class" ).exists ();
211
+ });
190
212
}
191
213
);
You can’t perform that action at this time.
0 commit comments