DEV: optionally removes links/avatars from user-info (#16388)
Usage: ``` {{user-info user=user includeLink=false includeAvatar=false}} ``` This is useful when using user-info in a dropdown list for example.
This commit is contained in:
parent
254f48e568
commit
8f03baaf8e
|
@ -13,6 +13,8 @@ export default Component.extend({
|
||||||
attributeBindings: ["data-username"],
|
attributeBindings: ["data-username"],
|
||||||
size: "small",
|
size: "small",
|
||||||
"data-username": alias("user.username"),
|
"data-username": alias("user.username"),
|
||||||
|
includeLink: true,
|
||||||
|
includeAvatar: true,
|
||||||
|
|
||||||
@discourseComputed("user.username")
|
@discourseComputed("user.username")
|
||||||
userPath(username) {
|
userPath(username) {
|
||||||
|
|
|
@ -1,14 +1,32 @@
|
||||||
<div class="user-image">
|
{{#if includeAvatar}}
|
||||||
<div class="user-image-inner">
|
<div class="user-image">
|
||||||
<a href={{this.userPath}} data-user-card={{@user.username}}>{{avatar @user imageSize="large"}}</a>
|
<div class="user-image-inner">
|
||||||
{{user-avatar-flair user=@user}}
|
<a href={{this.userPath}} data-user-card={{@user.username}}>{{avatar @user imageSize="large"}}</a>
|
||||||
|
{{user-avatar-flair user=@user}}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
{{/if}}
|
||||||
|
|
||||||
<div class="user-detail">
|
<div class="user-detail">
|
||||||
<div class="name-line">
|
<div class="name-line">
|
||||||
<span class={{if nameFirst "name bold" "username bold"}}><a href={{this.userPath}} data-user-card={{@user.username}}>{{if nameFirst this.name (format-username @user.username)}}</a></span>
|
<span class={{if nameFirst "name bold" "username bold"}}>
|
||||||
<span class={{if nameFirst "username margin" "name margin"}}><a href={{this.userPath}} data-user-card={{@user.username}}>{{if nameFirst (format-username @user.username) this.name}}</a></span>
|
{{#if includeLink}}
|
||||||
|
<a href={{this.userPath}} data-user-card={{@user.username}}>
|
||||||
|
{{if nameFirst this.name (format-username @user.username)}}
|
||||||
|
</a>
|
||||||
|
{{else}}
|
||||||
|
{{if nameFirst this.name (format-username @user.username)}}
|
||||||
|
{{/if}}
|
||||||
|
</span>
|
||||||
|
<span class={{if nameFirst "username margin" "name margin"}}>
|
||||||
|
{{#if includeLink}}
|
||||||
|
<a href={{this.userPath}} data-user-card={{@user.username}}>
|
||||||
|
{{if nameFirst (format-username @user.username) this.name}}
|
||||||
|
</a>
|
||||||
|
{{else}}
|
||||||
|
{{if nameFirst (format-username @user.username) this.name}}
|
||||||
|
{{/if}}
|
||||||
|
</span>
|
||||||
{{plugin-outlet name="after-user-name" tagName="span" connectorTagName="span" args=(hash user=user)}}
|
{{plugin-outlet name="after-user-name" tagName="span" connectorTagName="span" args=(hash user=user)}}
|
||||||
</div>
|
</div>
|
||||||
<div class="title">{{@user.title}}</div>
|
<div class="title">{{@user.title}}</div>
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
import componentTest, {
|
||||||
|
setupRenderingTest,
|
||||||
|
} from "discourse/tests/helpers/component-test";
|
||||||
|
import hbs from "htmlbars-inline-precompile";
|
||||||
|
import { discourseModule, exists } from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
|
||||||
|
discourseModule("Integration | Component | user-info", function (hooks) {
|
||||||
|
setupRenderingTest(hooks);
|
||||||
|
|
||||||
|
componentTest("includeLink", {
|
||||||
|
template: hbs`{{user-info user=currentUser includeLink=includeLink}}`,
|
||||||
|
|
||||||
|
async test(assert) {
|
||||||
|
this.set("includeLink", true);
|
||||||
|
|
||||||
|
assert.ok(exists(`.username a[href="/u/${this.currentUser.username}"]`));
|
||||||
|
|
||||||
|
this.set("includeLink", false);
|
||||||
|
|
||||||
|
assert.notOk(
|
||||||
|
exists(`.username a[href="/u/${this.currentUser.username}"]`)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
componentTest("includeAvatar", {
|
||||||
|
template: hbs`{{user-info user=currentUser includeAvatar=includeAvatar}}`,
|
||||||
|
|
||||||
|
async test(assert) {
|
||||||
|
this.set("includeAvatar", true);
|
||||||
|
|
||||||
|
assert.ok(exists(".user-image"));
|
||||||
|
|
||||||
|
this.set("includeAvatar", false);
|
||||||
|
|
||||||
|
assert.notOk(exists(".user-image"));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue