Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV: Add compatibility with the Glimmer Post Stream #651

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions assets/javascripts/discourse/components/assigned-to-first-post.gjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import Component from "@glimmer/component";
import { concat } from "@ember/helper";

Check failure on line 2 in assets/javascripts/discourse/components/assigned-to-first-post.gjs

View workflow job for this annotation

GitHub Actions / ci / linting

'concat' is defined but never used
import icon from "discourse/helpers/d-icon";
import userPrioritizedName from "discourse/helpers/user-prioritized-name";
import { i18n } from "discourse-i18n";
import { assignedToGroupPath, assignedToUserPath } from "../lib/url";

export default class AssignedToFirstPost extends Component {
get assignedToUser() {
return this.args.post?.topic?.assigned_to_user;
}

get assignedToGroup() {
return this.args.post?.topic?.assigned_to_group;
}

get icon() {
return this.assignedToUser ? "user-plus" : "group-plus";
}

get indirectlyAssignedTo() {
return this.args.post?.topic?.indirectly_assigned_to;
}

get indirectAssignments() {
if (!this.indirectlyAssignedTo) {
return null;
}

return Object.keys(this.indirectlyAssignedTo).map((postId) => {
const postNumber = this.indirectlyAssignedTo[postId].post_number;

return {
postId,
assignee: this.indirectlyAssignedTo[postId].assigned_to,
postNumber,
url: `${this.args.post.topic.url}/${postNumber}`,
};
});
}

get isAssigned() {
return !!(
this.assignedToUser ||
this.assignedToGroup ||
this.args.post?.topic?.indirectly_assigned_to
);
}

<template>
{{#if this.isAssigned}}
<p class="assigned-to">
{{icon this.icon}}
{{#if this.assignedToUser}}
<span class="assignee">
<span class="assigned-to--user">
{{i18n
"discourse_assign.assigned_topic_to"
username=(userPrioritizedName this.assignedToUser)
path=(assignedToUserPath this.assignedToUser)
}}
</span>
</span>
{{/if}}

{{#if this.assignedToGroup}}
<span class="assignee">
<span class="assigned-to--group">
{{i18n
"discourse_assign.assigned_topic_to"
username=this.assignedToGroup.name
path=(assignedToGroupPath this.assignedToGroup)
}}
</span>
</span>
{{/if}}

{{#each this.indirectAssignments key="postId" as |indirectAssignment|}}
<span class="assign-text">
{{i18n "discourse_assign.assigned"}}
</span>
<span class="assignee">
<a href={{indirectAssignment.url}} class="assigned-indirectly">
{{i18n
"discourse_assign.assign_post_to_multiple"
post_number=indirectAssignment.postNumber
username=(userPrioritizedName indirectAssignment.assignee)
}}
</a>
</span>
{{/each}}
</p>
{{/if}}
</template>
}
11 changes: 2 additions & 9 deletions assets/javascripts/discourse/components/assigned-to-post.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,14 @@ import { service } from "@ember/service";
import DButton from "discourse/components/d-button";
import DropdownMenu from "discourse/components/dropdown-menu";
import icon from "discourse/helpers/d-icon";
import userPrioritizedName from "discourse/helpers/user-prioritized-name";
import { i18n } from "discourse-i18n";
import DMenu from "float-kit/components/d-menu";

export default class AssignedToPost extends Component {
@service taskActions;
@service siteSettings;

get nameOrUsername() {
if (!this.siteSettings.prioritize_username_in_ux) {
return this.args.assignedToUser.name || this.args.assignedToUser.username;
} else {
return this.args.assignedToUser.username;
}
}

@action
unassign() {
this.taskActions.unassignPost(this.args.post);
Expand All @@ -42,7 +35,7 @@ export default class AssignedToPost extends Component {

<a href={{@href}} class="assigned-to-username">
{{#if @assignedToUser}}
{{this.nameOrUsername}}
{{userPrioritizedName @assignedToUser}}
{{else}}
{{@assignedToGroup.name}}
{{/if}}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import Component from "@glimmer/component";
import { assignedToGroupPath, assignedToUserPath } from "../lib/url";
import AssignedFirstPost from "./assigned-to-first-post";
import AssignedToPost from "./assigned-to-post";

export default class PostAssignmentsDisplay extends Component {
static shouldRender(args) {
return args.post;
}

get post() {
return this.args.outletArgs.post;
}

get assignedTo() {
return this.post.topic?.indirectly_assigned_to?.[this.post.id]?.assigned_to;
}

get assignedToUser() {
return this.assignedTo.username ? this.assignedTo : null;
}

get assignedToGroup() {
return !this.assignedToUser && this.assignedTo.name
? this.assignedTo
: null;
}

get assignedHref() {
return this.assignedToUser
? assignedToUserPath(this.assignedToUser)
: assignedToGroupPath(this.assignedToGroup);
}

<template>
{{#if this.post.firstPost}}
<AssignedFirstPost @post={{this.post}} />
{{else if this.assignedTo}}
<p class="assigned-to">
<AssignedToPost
@assignedToUser={{this.assignedToUser}}
@assignedToGroup={{this.assignedToGroup}}
@href={{this.assignedHref}}
@post={{this.post}}
/>
</p>
{{/if}}
</template>
}
Loading
Loading