Skip to content

Commit bbb5147

Browse files
authored
DEV: Add compatibility with the Glimmer Post Stream (#651)
1 parent bf52519 commit bbb5147

File tree

8 files changed

+904
-620
lines changed

8 files changed

+904
-620
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import Component from "@glimmer/component";
2+
import { service } from "@ember/service";
3+
import { htmlSafe } from "@ember/template";
4+
import icon from "discourse/helpers/d-icon";
5+
import { bind } from "discourse/lib/decorators";
6+
import { i18n } from "discourse-i18n";
7+
import { assignedToGroupPath, assignedToUserPath } from "../lib/url";
8+
9+
export default class AssignedToFirstPost extends Component {
10+
@service siteSettings;
11+
12+
get assignedToUser() {
13+
return this.args.post?.topic?.assigned_to_user;
14+
}
15+
16+
get assignedToGroup() {
17+
return this.args.post?.topic?.assigned_to_group;
18+
}
19+
20+
get icon() {
21+
return this.assignedToUser ? "user-plus" : "group-plus";
22+
}
23+
24+
get indirectlyAssignedTo() {
25+
return this.args.post?.topic?.indirectly_assigned_to;
26+
}
27+
28+
get indirectAssignments() {
29+
if (!this.indirectlyAssignedTo) {
30+
return null;
31+
}
32+
33+
return Object.keys(this.indirectlyAssignedTo).map((postId) => {
34+
const postNumber = this.indirectlyAssignedTo[postId].post_number;
35+
36+
return {
37+
postId,
38+
assignee: this.indirectlyAssignedTo[postId].assigned_to,
39+
postNumber,
40+
url: `${this.args.post.topic.url}/${postNumber}`,
41+
};
42+
});
43+
}
44+
45+
get isAssigned() {
46+
return !!(
47+
this.assignedToUser ||
48+
this.assignedToGroup ||
49+
this.args.post?.topic?.indirectly_assigned_to
50+
);
51+
}
52+
53+
get hasOnlyIndirectAssignments() {
54+
return !this.assignedToUser && !this.assignedToGroup;
55+
}
56+
57+
@bind
58+
prioritizedAssigneeName(assignee) {
59+
// if this code is ever replaced to use `prioritize_username_in_ux`, remove this function and use the helper
60+
// userPrioritizedName instead
61+
return this.siteSettings.prioritize_full_name_in_ux || !assignee.username
62+
? assignee.name || assignee.username
63+
: assignee.username;
64+
}
65+
66+
<template>
67+
{{#if this.isAssigned}}
68+
<p class="assigned-to">
69+
{{icon this.icon}}
70+
{{#if this.assignedToUser}}
71+
<span class="assignee">
72+
<span class="assigned-to--user">
73+
{{htmlSafe
74+
(i18n
75+
"discourse_assign.assigned_topic_to"
76+
username=(this.prioritizedAssigneeName this.assignedToUser)
77+
path=(assignedToUserPath this.assignedToUser)
78+
)
79+
}}
80+
</span>
81+
</span>
82+
{{/if}}
83+
84+
{{#if this.assignedToGroup}}
85+
<span class="assignee">
86+
<span class="assigned-to--group">
87+
{{htmlSafe
88+
(i18n
89+
"discourse_assign.assigned_topic_to"
90+
username=this.assignedToGroup.name
91+
path=(assignedToGroupPath this.assignedToGroup)
92+
)
93+
}}
94+
</span>
95+
</span>
96+
{{/if}}
97+
98+
{{#if this.hasOnlyIndirectAssignments}}
99+
<span class="assign-text">
100+
{{i18n "discourse_assign.assigned"}}
101+
</span>
102+
{{/if}}
103+
{{#if this.indirectlyAssignedTo}}
104+
{{#each
105+
this.indirectAssignments key="postId"
106+
as |indirectAssignment|
107+
}}
108+
<span class="assignee">
109+
<a href={{indirectAssignment.url}} class="assigned-indirectly">
110+
{{i18n
111+
"discourse_assign.assign_post_to_multiple"
112+
post_number=indirectAssignment.postNumber
113+
username=(this.prioritizedAssigneeName
114+
indirectAssignment.assignee
115+
)
116+
}}
117+
</a>
118+
</span>
119+
{{/each}}
120+
{{/if}}
121+
</p>
122+
{{/if}}
123+
</template>
124+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import Component from "@glimmer/component";
2+
import { assignedToGroupPath, assignedToUserPath } from "../lib/url";
3+
import AssignedFirstPost from "./assigned-to-first-post";
4+
import AssignedToPost from "./assigned-to-post";
5+
6+
export default class PostAssignmentsDisplay extends Component {
7+
static shouldRender(args) {
8+
return args.post;
9+
}
10+
11+
get post() {
12+
return this.args.outletArgs.post;
13+
}
14+
15+
get assignedTo() {
16+
return this.post.topic?.indirectly_assigned_to?.[this.post.id]?.assigned_to;
17+
}
18+
19+
get assignedToUser() {
20+
return this.assignedTo.username ? this.assignedTo : null;
21+
}
22+
23+
get assignedToGroup() {
24+
return !this.assignedToUser && this.assignedTo.name
25+
? this.assignedTo
26+
: null;
27+
}
28+
29+
get assignedHref() {
30+
return this.assignedToUser
31+
? assignedToUserPath(this.assignedToUser)
32+
: assignedToGroupPath(this.assignedToGroup);
33+
}
34+
35+
<template>
36+
{{#if this.post.firstPost}}
37+
<AssignedFirstPost @post={{this.post}} />
38+
{{else if this.assignedTo}}
39+
<p class="assigned-to">
40+
<AssignedToPost
41+
@assignedToUser={{this.assignedToUser}}
42+
@assignedToGroup={{this.assignedToGroup}}
43+
@href={{this.assignedHref}}
44+
@post={{this.post}}
45+
/>
46+
</p>
47+
{{/if}}
48+
</template>
49+
}

0 commit comments

Comments
 (0)