From 2af490ff4f4f123e838ecad1eb5276b61507d3d2 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Thu, 14 Sep 2023 17:29:57 +0100 Subject: [PATCH 1/4] DEV: Modernise assignment topic-list implementation - Reuse core ` group-assigned-show.hbs} | 2 +- .../templates/user-activity-assigned.hbs | 2 +- package.json | 3 +- yarn.lock | 1028 ++++++++++++----- 20 files changed, 852 insertions(+), 493 deletions(-) create mode 100644 assets/javascripts/discourse/components/assigned-topic-list-column.gjs delete mode 100644 assets/javascripts/discourse/components/assigned-topic-list-item.hbs delete mode 100644 assets/javascripts/discourse/components/assigned-topic-list-item.js delete mode 100644 assets/javascripts/discourse/components/assigned-topic-list.hbs delete mode 100644 assets/javascripts/discourse/components/assigned-topic-list.js delete mode 100644 assets/javascripts/discourse/components/basic-assigned-topic-list.hbs delete mode 100644 assets/javascripts/discourse/components/basic-assigned-topic-list.js create mode 100644 assets/javascripts/discourse/connectors/topic-list-after-columns/assign-buttons.hbr create mode 100644 assets/javascripts/discourse/raw-templates/assign-topic-buttons.hbr create mode 100644 assets/javascripts/discourse/raw-views/assign-topic-buttons.gjs rename assets/javascripts/discourse/templates/{group-topics-list.hbs => group-assigned-show.hbs} (97%) diff --git a/.prettierrc b/.prettierrc index 0967ef42..8a1423e9 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1 +1,17 @@ -{} +{ + "plugins": ["prettier-plugin-ember-template-tag"], + "overrides": [ + { + "files": "*.gjs", + "options": { + "parser": "ember-template-tag" + } + }, + { + "files": "*.gts", + "options": { + "parser": "ember-template-tag" + } + } + ] +} diff --git a/assets/javascripts/discourse/components/assigned-topic-list-column.gjs b/assets/javascripts/discourse/components/assigned-topic-list-column.gjs new file mode 100644 index 00000000..a910e42a --- /dev/null +++ b/assets/javascripts/discourse/components/assigned-topic-list-column.gjs @@ -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 { + + + @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(), + }); + } +} diff --git a/assets/javascripts/discourse/components/assigned-topic-list-item.hbs b/assets/javascripts/discourse/components/assigned-topic-list-item.hbs deleted file mode 100644 index c7396151..00000000 --- a/assets/javascripts/discourse/components/assigned-topic-list-item.hbs +++ /dev/null @@ -1,86 +0,0 @@ -{{! - The `~` syntax strip spaces between the elements, making it produce - `Some text`, - with no space between them. - This causes the topic-post-badge to be considered the same word as "text" - at the end of the link, preventing it from line wrapping onto its own line. -}} -{{#if this.bulkSelectEnabled}} - - - -{{/if}} - - - {{~raw "topic-status" topic=this.topic}} - {{~#if this.isPrivateMessage}} - {{~d-icon "envelope" class="private-message-icon"}} - {{~/if}} - {{~topic-link this.topic class="raw-link raw-topic-link"}} - {{~#if this.topic.featured_link}} - {{~topic-featured-link this.topic}} - {{~/if}} - {{~#if this.showTopicPostBadges}} - {{~raw - "topic-post-badges" - unread=this.topic.unread - unseen=this.topic.unseen - url=this.topic.lastUnreadUrl - newDotText=this.newDotText - }} - {{~/if}} - - - {{#if this.expandPinned}} - {{raw "list/topic-excerpt" topic=this.topic}} - {{/if}} - - -{{#if this.showPosters}} - {{raw "list/posters-column" posters=this.topic.featuredUsers}} -{{/if}} - -{{raw "list/posts-count-column" topic=this.topic}} - -{{number - this.topic.views - numberKey="views_long" - }} -{{raw - "list/activity-column" - topic=this.topic - class="num topic-list-data" - tagName="td" -}} - - {{#if this.topic.assigned_to_user}} - - {{else if this.topic.assigned_to_group}} - - {{else}} - - {{/if}} - \ No newline at end of file diff --git a/assets/javascripts/discourse/components/assigned-topic-list-item.js b/assets/javascripts/discourse/components/assigned-topic-list-item.js deleted file mode 100644 index a112ea92..00000000 --- a/assets/javascripts/discourse/components/assigned-topic-list-item.js +++ /dev/null @@ -1,8 +0,0 @@ -import TopicListItem from "discourse/components/topic-list-item"; -import { equal } from "@ember/object/computed"; - -export default class AssignedTopicListItem extends TopicListItem { - classNames = ["assigned-topic-list-item"]; - - @equal("topic.archetype", "private_message") isPrivateMessage; -} diff --git a/assets/javascripts/discourse/components/assigned-topic-list.hbs b/assets/javascripts/discourse/components/assigned-topic-list.hbs deleted file mode 100644 index 4d38c6ae..00000000 --- a/assets/javascripts/discourse/components/assigned-topic-list.hbs +++ /dev/null @@ -1,46 +0,0 @@ -{{#unless this.skipHeader}} - - {{raw - "topic-list-header" - canBulkSelect=this.canBulkSelect - canDoBulkActions=this.canDoBulkActions - toggleInTitle=this.toggleInTitle - hideCategory=this.hideCategory - showPosters=true - showLikes=this.showLikes - showOpLikes=this.showOpLikes - order=this.order - ascending=this.ascending - sortable=this.sortable - listTitle=this.listTitle - bulkSelectEnabled=this.bulkSelectEnabled - }} - -{{/unless}} - - - {{#each this.filteredTopics as |topic|}} - - - {{raw - "list/visited-line" - lastVisitedTopic=this.lastVisitedTopic - topic=topic - }} - {{/each}} - \ No newline at end of file diff --git a/assets/javascripts/discourse/components/assigned-topic-list.js b/assets/javascripts/discourse/components/assigned-topic-list.js deleted file mode 100644 index 057566b3..00000000 --- a/assets/javascripts/discourse/components/assigned-topic-list.js +++ /dev/null @@ -1,3 +0,0 @@ -import TopicList from "discourse/components/topic-list"; - -export default class AssignedTopicList extends TopicList {} diff --git a/assets/javascripts/discourse/components/basic-assigned-topic-list.hbs b/assets/javascripts/discourse/components/basic-assigned-topic-list.hbs deleted file mode 100644 index 16ca1068..00000000 --- a/assets/javascripts/discourse/components/basic-assigned-topic-list.hbs +++ /dev/null @@ -1,40 +0,0 @@ - - {{#if this.hasIncoming}} -
- - - -
- {{/if}} - - {{#if this.topics}} - - {{else}} - {{#unless this.loadingMore}} -
- {{i18n "choose_topic.none_found"}} -
- {{/unless}} - {{/if}} -
\ No newline at end of file diff --git a/assets/javascripts/discourse/components/basic-assigned-topic-list.js b/assets/javascripts/discourse/components/basic-assigned-topic-list.js deleted file mode 100644 index d667de3c..00000000 --- a/assets/javascripts/discourse/components/basic-assigned-topic-list.js +++ /dev/null @@ -1,3 +0,0 @@ -import BasicTopicList from "discourse/components/basic-topic-list"; - -export default class BasicAssignedTopicList extends BasicTopicList {} diff --git a/assets/javascripts/discourse/connectors/topic-list-after-columns/assign-buttons.hbr b/assets/javascripts/discourse/connectors/topic-list-after-columns/assign-buttons.hbr new file mode 100644 index 00000000..a0ec055b --- /dev/null +++ b/assets/javascripts/discourse/connectors/topic-list-after-columns/assign-buttons.hbr @@ -0,0 +1 @@ +{{raw "assign-topic-buttons" topic=context.topic}} \ No newline at end of file diff --git a/assets/javascripts/discourse/controllers/group-assigned-show.js b/assets/javascripts/discourse/controllers/group-assigned-show.js index 9edba01e..43fab2a4 100644 --- a/assets/javascripts/discourse/controllers/group-assigned-show.js +++ b/assets/javascripts/discourse/controllers/group-assigned-show.js @@ -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"]; @@ -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(), }); } diff --git a/assets/javascripts/discourse/controllers/user-activity-assigned.js b/assets/javascripts/discourse/controllers/user-activity-assigned.js index 06d0e3bf..260021cf 100644 --- a/assets/javascripts/discourse/controllers/user-activity-assigned.js +++ b/assets/javascripts/discourse/controllers/user-activity-assigned.js @@ -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) { diff --git a/assets/javascripts/discourse/raw-templates/assign-topic-buttons.hbr b/assets/javascripts/discourse/raw-templates/assign-topic-buttons.hbr new file mode 100644 index 00000000..82b20e11 --- /dev/null +++ b/assets/javascripts/discourse/raw-templates/assign-topic-buttons.hbr @@ -0,0 +1 @@ +{{{view.html}}} \ No newline at end of file diff --git a/assets/javascripts/discourse/raw-views/assign-topic-buttons.gjs b/assets/javascripts/discourse/raw-views/assign-topic-buttons.gjs new file mode 100644 index 00000000..d96a8fd9 --- /dev/null +++ b/assets/javascripts/discourse/raw-views/assign-topic-buttons.gjs @@ -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", + , + { topic: this.topic } + ); + } + } +} diff --git a/assets/javascripts/discourse/routes/group-assigned-show.js b/assets/javascripts/discourse/routes/group-assigned-show.js index e560b70b..c00a5c83 100644 --- a/assets/javascripts/discourse/routes/group-assigned-show.js +++ b/assets/javascripts/discourse/routes/group-assigned-show.js @@ -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)) { @@ -36,8 +30,4 @@ export default class GroupAssignedShow extends DiscourseRoute { search: this.currentModel.params.search, }); } - - renderTemplate() { - this.render("group-topics-list"); - } } diff --git a/assets/javascripts/discourse/routes/group-assigned.js b/assets/javascripts/discourse/routes/group-assigned.js index c6352f26..0b7faa10 100644 --- a/assets/javascripts/discourse/routes/group-assigned.js +++ b/assets/javascripts/discourse/routes/group-assigned.js @@ -28,9 +28,4 @@ export default class GroupAssigned extends DiscourseRoute { this.transitionTo("group.assigned.show", "everyone"); } } - - @action - changeAssigned() { - this.refresh(); - } } diff --git a/assets/javascripts/discourse/routes/user-activity-assigned.js b/assets/javascripts/discourse/routes/user-activity-assigned.js index daca6215..6b0a2125 100644 --- a/assets/javascripts/discourse/routes/user-activity-assigned.js +++ b/assets/javascripts/discourse/routes/user-activity-assigned.js @@ -34,9 +34,4 @@ export default class UserActivityAssigned extends UserTopicListRoute { titleToken() { return I18n.t("discourse_assign.assigned"); } - - @action - changeAssigned() { - this.refresh(); - } } diff --git a/assets/javascripts/discourse/templates/group-topics-list.hbs b/assets/javascripts/discourse/templates/group-assigned-show.hbs similarity index 97% rename from assets/javascripts/discourse/templates/group-topics-list.hbs rename to assets/javascripts/discourse/templates/group-assigned-show.hbs index ac5e0f4c..52252a8b 100644 --- a/assets/javascripts/discourse/templates/group-topics-list.hbs +++ b/assets/javascripts/discourse/templates/group-assigned-show.hbs @@ -16,7 +16,7 @@ @selector=".paginated-topics-list .topic-list tr" @action={{action "loadMore"}} > - - Date: Fri, 15 Sep 2023 16:25:19 +0100 Subject: [PATCH 2/4] lint & core branch --- .github/workflows/discourse-plugin.yml | 2 ++ assets/javascripts/discourse/components/assign-user-form.hbs | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/discourse-plugin.yml b/.github/workflows/discourse-plugin.yml index f5cf62e5..5eab13e9 100644 --- a/.github/workflows/discourse-plugin.yml +++ b/.github/workflows/discourse-plugin.yml @@ -9,3 +9,5 @@ on: jobs: ci: uses: discourse/.github/.github/workflows/discourse-plugin.yml@v1 + with: + core_ref: render-glimmer-raw diff --git a/assets/javascripts/discourse/components/assign-user-form.hbs b/assets/javascripts/discourse/components/assign-user-form.hbs index 2160f236..2aeb2a5b 100644 --- a/assets/javascripts/discourse/components/assign-user-form.hbs +++ b/assets/javascripts/discourse/components/assign-user-form.hbs @@ -51,7 +51,6 @@