mirror of
https://github.com/discourse/discourse.git
synced 2025-02-07 03:48:23 +00:00
DEV: Update glimmer menu to use value transformer (#30930)
- Use the `smallUserAttrs` function in the new glimmer menu - Replace the sugar syntax `@data` with `this.args` to fix tests
This commit is contained in:
parent
7b76d25946
commit
6aa492254f
@ -9,12 +9,13 @@ import { and, eq } from "truth-helpers";
|
|||||||
import AdminPostMenu from "discourse/components/admin-post-menu";
|
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 PluginOutlet from "discourse/components/plugin-outlet";
|
import PluginOutlet from "discourse/components/plugin-outlet";
|
||||||
import SmallUserList from "discourse/components/small-user-list";
|
import SmallUserList, {
|
||||||
|
smallUserAttrs,
|
||||||
|
} from "discourse/components/small-user-list";
|
||||||
import UserTip from "discourse/components/user-tip";
|
import UserTip from "discourse/components/user-tip";
|
||||||
import concatClass from "discourse/helpers/concat-class";
|
import concatClass from "discourse/helpers/concat-class";
|
||||||
import DAG from "discourse/lib/dag";
|
import DAG from "discourse/lib/dag";
|
||||||
import { applyMutableValueTransformer } from "discourse/lib/transformer";
|
import { applyMutableValueTransformer } from "discourse/lib/transformer";
|
||||||
import { userPath } from "discourse/lib/url";
|
|
||||||
import { i18n } from "discourse-i18n";
|
import { i18n } from "discourse-i18n";
|
||||||
import PostMenuButtonConfig from "./menu/button-config";
|
import PostMenuButtonConfig from "./menu/button-config";
|
||||||
import PostMenuButtonWrapper from "./menu/button-wrapper";
|
import PostMenuButtonWrapper from "./menu/button-wrapper";
|
||||||
@ -64,16 +65,6 @@ const coreButtonComponents = new Map([
|
|||||||
[buttonKeys.SHOW_MORE, PostMenuShowMoreButton],
|
[buttonKeys.SHOW_MORE, PostMenuShowMoreButton],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
function smallUserAttributes(user) {
|
|
||||||
return {
|
|
||||||
template: user.avatar_template,
|
|
||||||
username: user.username,
|
|
||||||
post_url: user.post_url,
|
|
||||||
url: userPath(user.username_lower),
|
|
||||||
unknown: user.unknown,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const defaultDagOptions = {
|
const defaultDagOptions = {
|
||||||
defaultPosition: { before: buttonKeys.SHOW_MORE },
|
defaultPosition: { before: buttonKeys.SHOW_MORE },
|
||||||
throwErrorOnCycle: false,
|
throwErrorOnCycle: false,
|
||||||
@ -565,7 +556,7 @@ export default class PostMenu extends Component {
|
|||||||
post_action_type_id: LIKE_ACTION,
|
post_action_type_id: LIKE_ACTION,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.likedUsers = users.map(smallUserAttributes);
|
this.likedUsers = users.map(smallUserAttrs);
|
||||||
this.totalLikedUsers = users.totalRows;
|
this.totalLikedUsers = users.totalRows;
|
||||||
this.isWhoLikedVisible = true;
|
this.isWhoLikedVisible = true;
|
||||||
}
|
}
|
||||||
@ -575,7 +566,7 @@ export default class PostMenu extends Component {
|
|||||||
id: this.args.post.id,
|
id: this.args.post.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.readers = users.map(smallUserAttributes);
|
this.readers = users.map(smallUserAttrs);
|
||||||
this.totalReaders = users.totalRows;
|
this.totalReaders = users.totalRows;
|
||||||
this.isWhoReadVisible = true;
|
this.isWhoReadVisible = true;
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,26 @@
|
|||||||
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 PluginOutlet from "discourse/components/plugin-outlet";
|
||||||
import avatar from "discourse/helpers/bound-avatar-template";
|
import avatar from "discourse/helpers/bound-avatar-template";
|
||||||
import getURL from "discourse/lib/get-url";
|
import getURL from "discourse/lib/get-url";
|
||||||
import { smallUserAttrs } from "discourse/lib/user-list-attrs";
|
import { applyValueTransformer } from "discourse/lib/transformer";
|
||||||
|
import { userPath } from "discourse/lib/url";
|
||||||
import { i18n } from "discourse-i18n";
|
import { i18n } from "discourse-i18n";
|
||||||
|
|
||||||
|
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,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export default class SmallUserList extends Component {
|
export default class SmallUserList extends Component {
|
||||||
@service currentUser;
|
@service currentUser;
|
||||||
|
|
||||||
@ -30,10 +44,7 @@ export default class SmallUserList extends Component {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
{{#if this.users}}
|
{{#if this.users}}
|
||||||
<PluginOutlet
|
<PluginOutlet @name="small-user-list-internal" @outletArgs={{this.args}}>
|
||||||
@name="small-user-list-internal"
|
|
||||||
@outletArgs={{hash data=@data}}
|
|
||||||
>
|
|
||||||
<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"
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
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,
|
|
||||||
});
|
|
||||||
}
|
|
@ -4,10 +4,10 @@ import { Promise } from "rsvp";
|
|||||||
import { h } from "virtual-dom";
|
import { h } from "virtual-dom";
|
||||||
import AdminPostMenu from "discourse/components/admin-post-menu";
|
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 { smallUserAttrs } from "discourse/components/small-user-list";
|
||||||
import { formattedReminderTime } from "discourse/lib/bookmark";
|
import { formattedReminderTime } from "discourse/lib/bookmark";
|
||||||
import discourseLater from "discourse/lib/later";
|
import discourseLater from "discourse/lib/later";
|
||||||
import { recentlyCopied, showAlert } from "discourse/lib/post-action-feedback";
|
import { recentlyCopied, showAlert } from "discourse/lib/post-action-feedback";
|
||||||
import { smallUserAttrs } from "discourse/lib/user-list-attrs";
|
|
||||||
import {
|
import {
|
||||||
NO_REMINDER_ICON,
|
NO_REMINDER_ICON,
|
||||||
WITH_REMINDER_ICON,
|
WITH_REMINDER_ICON,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user