DEV: add outlet wrapper for small user list (#29763)

* DEV: add outlet wrapper for small user list

* DEV: use value transformer to extend small user attrs function

* Update app/assets/javascripts/discourse/app/components/small-user-list.gjs

Co-authored-by: Jarek Radosz <jradosz@gmail.com>

---------

Co-authored-by: Jarek Radosz <jradosz@gmail.com>
This commit is contained in:
Amanda Alves Branquinho 2024-11-20 19:22:02 -03:00 committed by GitHub
parent b98af3bc53
commit 71a8d48d21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 66 additions and 63 deletions

View File

@ -21,6 +21,7 @@
@outletArgs={{hash @outletArgs={{hash
availableBadges=this.availableBadges availableBadges=this.availableBadges
userBadges=this.userBadges userBadges=this.userBadges
user=this.user
}} }}
> >
<form class="form-horizontal"> <form class="form-horizontal">

View File

@ -1,31 +1,22 @@
import Component from "@glimmer/component"; import Component from "@glimmer/component";
import { hash } from "@ember/helper";
import { service } from "@ember/service"; import { service } from "@ember/service";
import PluginOutlet from "discourse/components/plugin-outlet";
import avatar from "discourse/helpers/bound-avatar-template"; import avatar from "discourse/helpers/bound-avatar-template";
import { userPath } from "discourse/lib/url"; import { smallUserAttrs } from "discourse/lib/user-list-attrs";
import getURL from "discourse-common/lib/get-url"; import getURL from "discourse-common/lib/get-url";
import { i18n } from "discourse-i18n"; import { i18n } from "discourse-i18n";
export default class SmallUserList extends Component { export default class SmallUserList extends Component {
@service currentUser; @service currentUser;
smallUserAtts(user) {
return {
template: user.avatar_template,
username: user.username,
post_url: user.post_url,
url: userPath(user.username_lower),
unknown: user.unknown,
};
}
get users() { get users() {
let users = this.args.users; let users = this.args.users;
if ( if (
this.args.addSelf && this.args.addSelf &&
!users.some((u) => u.username === this.currentUser.username) !users.some((u) => u.username === this.currentUser.username)
) { ) {
users = users.concat(this.smallUserAtts(this.currentUser)); users = users.concat(smallUserAttrs(this.currentUser));
} }
return users; return users;
} }
@ -39,6 +30,10 @@ export default class SmallUserList extends Component {
<template> <template>
{{#if this.users}} {{#if this.users}}
<PluginOutlet
@name="small-user-list-internal"
@outletArgs={{hash data=this.args}}
>
<div class="clearfix small-user-list" ...attributes> <div class="clearfix small-user-list" ...attributes>
<span <span
class="small-user-list-content" class="small-user-list-content"
@ -80,6 +75,7 @@ export default class SmallUserList extends Component {
{{/if}} {{/if}}
</span> </span>
</div> </div>
</PluginOutlet>
{{/if}} {{/if}}
</template> </template>
} }

View File

@ -14,4 +14,5 @@ export const VALUE_TRANSFORMERS = Object.freeze([
"mentions-class", "mentions-class",
"more-topics-tabs", "more-topics-tabs",
"post-menu-buttons", "post-menu-buttons",
"small-user-attrs",
]); ]);

View File

@ -0,0 +1,16 @@
import { applyValueTransformer } from "discourse/lib/transformer";
import { userPath } from "discourse/lib/url";
export function smallUserAttrs(user) {
const defaultAttrs = {
template: user.avatar_template,
username: user.username,
post_url: user.post_url,
url: userPath(user.username_lower),
unknown: user.unknown,
};
return applyValueTransformer("small-user-attrs", defaultAttrs, {
user,
});
}

View File

@ -6,7 +6,7 @@ import AdminPostMenu from "discourse/components/admin-post-menu";
import DeleteTopicDisallowedModal from "discourse/components/modal/delete-topic-disallowed"; import DeleteTopicDisallowedModal from "discourse/components/modal/delete-topic-disallowed";
import { formattedReminderTime } from "discourse/lib/bookmark"; import { formattedReminderTime } from "discourse/lib/bookmark";
import { recentlyCopied, showAlert } from "discourse/lib/post-action-feedback"; import { recentlyCopied, showAlert } from "discourse/lib/post-action-feedback";
import { userPath } from "discourse/lib/url"; import { smallUserAttrs } from "discourse/lib/user-list-attrs";
import { import {
NO_REMINDER_ICON, NO_REMINDER_ICON,
WITH_REMINDER_ICON, WITH_REMINDER_ICON,
@ -55,16 +55,6 @@ function registerButton(name, builder) {
_builders[name] = builder; _builders[name] = builder;
} }
function smallUserAtts(user) {
return {
template: user.avatar_template,
username: user.username,
post_url: user.post_url,
url: userPath(user.username_lower),
unknown: user.unknown,
};
}
export function buildButton(name, widget) { export function buildButton(name, widget) {
let { attrs, state, siteSettings, settings, currentUser } = widget; let { attrs, state, siteSettings, settings, currentUser } = widget;
@ -907,14 +897,13 @@ export default createWidget("post-menu", {
getWhoLiked() { getWhoLiked() {
const { attrs, state } = this; const { attrs, state } = this;
return this.store return this.store
.find("post-action-user", { .find("post-action-user", {
id: attrs.id, id: attrs.id,
post_action_type_id: LIKE_ACTION, post_action_type_id: LIKE_ACTION,
}) })
.then((users) => { .then((users) => {
state.likedUsers = users.map(smallUserAtts); state.likedUsers = users.map(smallUserAttrs);
state.total = users.totalRows; state.total = users.totalRows;
}); });
}, },
@ -923,7 +912,7 @@ export default createWidget("post-menu", {
const { attrs, state } = this; const { attrs, state } = this;
return this.store.find("post-reader", { id: attrs.id }).then((users) => { return this.store.find("post-reader", { id: attrs.id }).then((users) => {
state.readers = users.map(smallUserAtts); state.readers = users.map(smallUserAttrs);
state.totalReaders = users.totalRows; state.totalReaders = users.totalRows;
}); });
}, },