Skip to content

Commit

Permalink
DEV: Modernise assignment topic-list implementation (#510)
Browse files Browse the repository at this point in the history
- Reuse core `<BasicTopicList` instead of reimplementing
- Use raw plugin outlet to add assign controls to topic-list-item (requires discourse/discourse#23592)
- Remove use of `.render()` in route
  • Loading branch information
davidtaylorhq authored Sep 28, 2023
1 parent e9c7cb5 commit 8980754
Show file tree
Hide file tree
Showing 22 changed files with 854 additions and 498 deletions.
18 changes: 17 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
{}
{
"plugins": ["prettier-plugin-ember-template-tag"],
"overrides": [
{
"files": "*.gjs",
"options": {
"parser": "ember-template-tag"
}
},
{
"files": "*.gts",
"options": {
"parser": "ember-template-tag"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
<Textarea
id="assign-modal-note"
@value={{@model.note}}
{{! template-lint-disable no-down-event-binding }}
{{on "keydown" this.handleTextAreaKeydown}}
/>
</div>
4 changes: 2 additions & 2 deletions assets/javascripts/discourse/components/assign-user-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export default class AssignUserForm extends Component {
@service capabilities;

@tracked assigneeError = false;
@tracked assigneeName =
this.args.model.username || this.args.model.group_name;
@tracked
assigneeName = this.args.model.username || this.args.model.group_name;

constructor() {
super(...arguments);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import Component from "@glimmer/component";
import AssignActionsDropdown from "./assign-actions-dropdown";
import { inject as service } from "@ember/service";
import { action } from "@ember/object";

export default class AssignedTopicListColumn_Test extends Component {
<template>
<td class="topic-list-data">
{{#if @topic.assigned_to_user}}
<AssignActionsDropdown
@topic={{@topic}}
@assignee={{@topic.assigned_to_user.username}}
@unassign={{this.unassign}}
@reassign={{this.reassign}}
/>
{{else if @topic.assigned_to_group}}
<AssignActionsDropdown
@topic={{@topic}}
@assignee={{@topic.assigned_to_group.name}}
@group={{true}}
@unassign={{this.unassign}}
@reassign={{this.reassign}}
/>
{{else}}
<AssignActionsDropdown @topic={{@topic}} @unassign={{this.unassign}} />
{{/if}}
</td>
</template>

@service taskActions;
@service router;

@action
async unassign(targetId, targetType = "Topic") {
await this.taskActions.unassign(targetId, targetType);
this.router.refresh();
}

@action
reassign(topic) {
this.taskActions.showAssignModal(topic, {
onSuccess: () => this.router.refresh(),
});
}
}

This file was deleted.

This file was deleted.

46 changes: 0 additions & 46 deletions assets/javascripts/discourse/components/assigned-topic-list.hbs

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{raw "assign-topic-buttons" topic=context.topic}}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { action } from "@ember/object";

export default class GroupAssignedShow extends UserTopicsList {
@service taskActions;
@service router;
@controller user;

queryParams = ["order", "ascending", "search"];
Expand Down Expand Up @@ -45,13 +46,13 @@ export default class GroupAssignedShow extends UserTopicsList {
@action
async unassign(targetId, targetType = "Topic") {
await this.taskActions.unassign(targetId, targetType);
this.send("changeAssigned");
this.router.refresh();
}

@action
reassign(topic) {
this.taskActions.showAssignModal(topic, {
onSuccess: () => this.send("changeAssigned"),
onSuccess: () => this.router.refresh(),
});
}

Expand Down
13 changes: 0 additions & 13 deletions assets/javascripts/discourse/controllers/user-activity-assigned.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,6 @@ export default class UserActivityAssigned extends UserTopicsList {
});
}

@action
async unassign(targetId, targetType = "Topic") {
await this.taskActions.unassign(targetId, targetType);
this.send("changeAssigned");
}

@action
reassign(topic) {
this.taskActions.showAssignModal(topic, {
onSuccess: () => this.send("changeAssigned"),
});
}

@action
changeSort(sortBy) {
if (sortBy === this.order) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{{view.html}}}
21 changes: 21 additions & 0 deletions assets/javascripts/discourse/raw-views/assign-topic-buttons.gjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import EmberObject from "@ember/object";
import rawRenderGlimmer from "discourse/lib/raw-render-glimmer";
import AssignedTopicListColumn from "../components/assigned-topic-list-column";
import { inject as service } from "@ember/service";

const ASSIGN_LIST_ROUTES = ["userActivity.assigned", "group.assigned.show"];

export default class extends EmberObject {
@service router;

get html() {
if (ASSIGN_LIST_ROUTES.includes(this.router.currentRouteName)) {
return rawRenderGlimmer(
this,
"div.assign-topic-buttons",
<template><AssignedTopicListColumn @topic={{@data.topic}} /></template>,
{ topic: this.topic }
);
}
}
}
10 changes: 0 additions & 10 deletions assets/javascripts/discourse/routes/group-assigned-show.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ import DiscourseRoute from "discourse/routes/discourse";
import { findOrResetCachedTopicList } from "discourse/lib/cached-topic-list";

export default class GroupAssignedShow extends DiscourseRoute {
beforeModel(transition) {
if (transition.from?.localName === "show") {
this.session.set("topicListScrollPosition", 1);
}
}

model(params) {
let filter;
if (["everyone", this.modelFor("group").name].includes(params.filter)) {
Expand Down Expand Up @@ -36,8 +30,4 @@ export default class GroupAssignedShow extends DiscourseRoute {
search: this.currentModel.params.search,
});
}

renderTemplate() {
this.render("group-topics-list");
}
}
6 changes: 0 additions & 6 deletions assets/javascripts/discourse/routes/group-assigned.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import DiscourseRoute from "discourse/routes/discourse";
import { ajax } from "discourse/lib/ajax";
import { action } from "@ember/object";

export default class GroupAssigned extends DiscourseRoute {
model() {
Expand Down Expand Up @@ -28,9 +27,4 @@ export default class GroupAssigned extends DiscourseRoute {
this.transitionTo("group.assigned.show", "everyone");
}
}

@action
changeAssigned() {
this.refresh();
}
}
Loading

0 comments on commit 8980754

Please sign in to comment.