From 8f03baaf8e51c8df7ab33bcf49626bf9a3f51da4 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Wed, 6 Apr 2022 14:07:38 +0200 Subject: [PATCH] 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. --- .../discourse/app/components/user-info.js | 2 + .../app/templates/components/user-info.hbs | 32 +++++++++++---- .../integration/components/user-info-test.js | 39 +++++++++++++++++++ 3 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 app/assets/javascripts/discourse/tests/integration/components/user-info-test.js diff --git a/app/assets/javascripts/discourse/app/components/user-info.js b/app/assets/javascripts/discourse/app/components/user-info.js index 024825ed78a..dc9cf2e86d7 100644 --- a/app/assets/javascripts/discourse/app/components/user-info.js +++ b/app/assets/javascripts/discourse/app/components/user-info.js @@ -13,6 +13,8 @@ export default Component.extend({ attributeBindings: ["data-username"], size: "small", "data-username": alias("user.username"), + includeLink: true, + includeAvatar: true, @discourseComputed("user.username") userPath(username) { diff --git a/app/assets/javascripts/discourse/app/templates/components/user-info.hbs b/app/assets/javascripts/discourse/app/templates/components/user-info.hbs index 86246ae820e..eaf91b06e04 100644 --- a/app/assets/javascripts/discourse/app/templates/components/user-info.hbs +++ b/app/assets/javascripts/discourse/app/templates/components/user-info.hbs @@ -1,14 +1,32 @@ -
-
- {{avatar @user imageSize="large"}} - {{user-avatar-flair user=@user}} +{{#if includeAvatar}} +
+
+ {{avatar @user imageSize="large"}} + {{user-avatar-flair user=@user}} +
-
+{{/if}}
- {{if nameFirst this.name (format-username @user.username)}} - {{if nameFirst (format-username @user.username) this.name}} + + {{#if includeLink}} + + {{if nameFirst this.name (format-username @user.username)}} + + {{else}} + {{if nameFirst this.name (format-username @user.username)}} + {{/if}} + + + {{#if includeLink}} + + {{if nameFirst (format-username @user.username) this.name}} + + {{else}} + {{if nameFirst (format-username @user.username) this.name}} + {{/if}} + {{plugin-outlet name="after-user-name" tagName="span" connectorTagName="span" args=(hash user=user)}}
{{@user.title}}
diff --git a/app/assets/javascripts/discourse/tests/integration/components/user-info-test.js b/app/assets/javascripts/discourse/tests/integration/components/user-info-test.js new file mode 100644 index 00000000000..0fc0ef05544 --- /dev/null +++ b/app/assets/javascripts/discourse/tests/integration/components/user-info-test.js @@ -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")); + }, + }); +});