From 206969e49d89807b6eed2a3057e77cab1ecc2e7b Mon Sep 17 00:00:00 2001 From: David Taylor Date: Thu, 7 Sep 2023 19:05:41 +0100 Subject: [PATCH] DEV: Replace BulkTopicSelection mixin with a helper object (#23268) Mixins are considered deprecated by Ember, and cannot be applied to modern framework objects. Also, the coupling they introduce can make things very difficult to refactor. This commit takes the state/logic from BulkTopicSelection and turns it into a helper object. This avoids it polluting any controllers/components its included in. In future, the entire helper object can be passed down to child components so that they don't need to lookup controllers using the resolver. Those kinds of changes would involve changing some very heavily-overridden templates, so they are not included in this PR. It will likely be done as part of the larger refactor in https://github.com/discourse/discourse/pull/22622. --- .../app/components/bulk-select-toggle.hbs | 6 +- .../app/components/bulk-select-toggle.js | 18 ++-- .../discourse/app/components/d-navigation.hbs | 2 +- .../app/controllers/discovery/topics.js | 50 +++++++++-- .../discourse/app/controllers/tag-show.js | 50 +++++++++-- .../app/controllers/user-topics-list.js | 41 ++++++++-- .../discourse/app/lib/bulk-select-helper.js | 66 +++++++++++++++ .../discourse/app/lib/filter-mode.js | 2 +- .../app/mixins/bulk-topic-selection.js | 82 ------------------- .../app/routes/build-category-route.js | 2 +- .../routes/build-private-messages-route.js | 2 +- .../discourse/app/routes/build-topic-route.js | 2 +- .../user-private-messages-tags-index.js | 2 +- .../discourse/app/templates/user/messages.hbs | 2 +- 14 files changed, 200 insertions(+), 127 deletions(-) create mode 100644 app/assets/javascripts/discourse/app/lib/bulk-select-helper.js delete mode 100644 app/assets/javascripts/discourse/app/mixins/bulk-topic-selection.js diff --git a/app/assets/javascripts/discourse/app/components/bulk-select-toggle.hbs b/app/assets/javascripts/discourse/app/components/bulk-select-toggle.hbs index 2caf4cb5717..e0b31d677f3 100644 --- a/app/assets/javascripts/discourse/app/components/bulk-select-toggle.hbs +++ b/app/assets/javascripts/discourse/app/components/bulk-select-toggle.hbs @@ -1,5 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/app/assets/javascripts/discourse/app/components/bulk-select-toggle.js b/app/assets/javascripts/discourse/app/components/bulk-select-toggle.js index 80ddbc7decc..09e2a1c22f1 100644 --- a/app/assets/javascripts/discourse/app/components/bulk-select-toggle.js +++ b/app/assets/javascripts/discourse/app/components/bulk-select-toggle.js @@ -1,17 +1,15 @@ -import Component from "@ember/component"; +import Component from "@glimmer/component"; import { action } from "@ember/object"; import { getOwner } from "discourse-common/lib/get-owner"; -export default Component.extend({ - parentController: null, - +export default class BulkSelectToggle extends Component { @action toggleBulkSelect() { const controller = getOwner(this).lookup( - `controller:${this.parentController}` + `controller:${this.args.parentController}` ); - const selection = controller.selected; - controller.toggleProperty("bulkSelectEnabled"); - selection.clear(); - }, -}); + const helper = controller.bulkSelectHelper; + helper.clear(); + helper.bulkSelectEnabled = !helper.bulkSelectEnabled; + } +} diff --git a/app/assets/javascripts/discourse/app/components/d-navigation.hbs b/app/assets/javascripts/discourse/app/components/d-navigation.hbs index ae8e4a23b25..98907cbba12 100644 --- a/app/assets/javascripts/discourse/app/components/d-navigation.hbs +++ b/app/assets/javascripts/discourse/app/components/d-navigation.hbs @@ -17,7 +17,7 @@