A platform for community discussion. Free, open, simple.
UX: allows to click on topic item for bulk select (#36102)
Joffrey JAFFEUX3cb11a51bb58
diff --git a/app/assets/stylesheets/common/base/_topic-list.scss b/app/assets/stylesheets/common/base/_topic-list.scssindex a69008c62b4..2f7476a67c2 100644--- a/app/assets/stylesheets/common/base/_topic-list.scss+++ b/app/assets/stylesheets/common/base/_topic-list.scss@@ -174,6 +174,15 @@.topic-list-separator {text-align: center;}++ &.bulk-selecting {+ @include user-select(none);+ cursor: pointer;+ }++ &.selected {+ background: var(--tertiary-low);+ }}.topic-list-item-separator {diff --git a/frontend/discourse/app/components/topic-list/header/bulk-select-cell.gjs b/frontend/discourse/app/components/topic-list/header/bulk-select-cell.gjsindex f02c4087195..313c41ccb16 100644--- a/frontend/discourse/app/components/topic-list/header/bulk-select-cell.gjs+++ b/frontend/discourse/app/components/topic-list/header/bulk-select-cell.gjs@@ -8,7 +8,7 @@ const BulkSelectCell = <template><button{{on "click" @bulkSelectHelper.toggleBulkSelect}}title={{i18n "topics.bulk.toggle"}}- class="btn-transparent bulk-select no-text"+ class="btn-transparent bulk-select no-text btn-primary">{{icon "list-check"}}</button>diff --git a/frontend/discourse/app/components/topic-list/item.gjs b/frontend/discourse/app/components/topic-list/item.gjsindex 89d848dfe54..a6eda903043 100644--- a/frontend/discourse/app/components/topic-list/item.gjs+++ b/frontend/discourse/app/components/topic-list/item.gjs@@ -115,33 +115,60 @@ export default class Item extends Component {@actiononBulkSelectToggle(e) {+ e.stopImmediatePropagation();+if (e.target.checked) {- this.args.selected.addObject(this.args.topic);+ this.selectTopic(e.target.closest(".topic-list-item"), e.shiftKey);+ } else {+ this.unselectTopic();+ }+ }- if (this.args.bulkSelectHelper.lastCheckedElementId && e.shiftKey) {- const bulkSelects = [...document.querySelectorAll("input.bulk-select")];- const from = bulkSelects.indexOf(e.target);- const to = bulkSelects.findIndex(- (el) => el.id === this.args.bulkSelectHelper.lastCheckedElementId- );- const start = Math.min(from, to);- const end = Math.max(from, to);+ unselectTopic() {+ this.args.selected.removeObject(this.args.topic);+ this.args.bulkSelectHelper.lastCheckedElementId = null;+ }- bulkSelects- .slice(start, end)- .filter((el) => !el.checked)- .forEach((checkbox) => checkbox.click());- }+ selectTopic(topicNode, shiftKey) {+ this.args.selected.addObject(this.args.topic);- this.args.bulkSelectHelper.lastCheckedElementId = e.target.id;- } else {- this.args.selected.removeObject(this.args.topic);- this.args.bulkSelectHelper.lastCheckedElementId = null;+ if (this.args.bulkSelectHelper.lastCheckedElementId && shiftKey) {+ const topics = Array.from(topicNode.parentNode.children);+ const from = topics.indexOf(topicNode);+ const to = topics.findIndex(+ (el) =>+ el.dataset.topicId === this.args.bulkSelectHelper.lastCheckedElementId+ );+ const start = Math.min(from, to);+ const end = Math.max(from, to);+ const bulkSelects = [...document.querySelectorAll("input.bulk-select")];+ bulkSelects+ .slice(start, end)+ .filter((el) => !el.checked)+ .forEach((checkbox) => checkbox.click());}++ this.args.bulkSelectHelper.lastCheckedElementId = topicNode.dataset.topicId;}@actionclick(event) {+ if (this.args.bulkSelectEnabled) {+ event.preventDefault();++ const checked = this.args.selected.includes(this.args.topic);+ if (checked) {+ this.unselectTopic();+ } else {+ this.selectTopic(+ event.target.closest(".topic-list-item"),+ event.shiftKey+ );+ }++ return;+ }+applyBehaviorTransformer("topic-list-item-click",() => {@@ -256,6 +283,8 @@ export default class Item extends Component {(if @topic.bookmarked "bookmarked")(if @topic.pinned "pinned")(if @topic.closed "closed")+ (if @bulkSelectEnabled "bulk-selecting")+ (if this.isSelected "selected")this.tagClassNamesthis.additionalClasses}}diff --git a/spec/system/page_objects/components/topic_list.rb b/spec/system/page_objects/components/topic_list.rbindex c09e90a98dd..896ea435f5f 100644--- a/spec/system/page_objects/components/topic_list.rb+++ b/spec/system/page_objects/components/topic_list.rb@@ -62,6 +62,10 @@ module PageObjectsfind("#{topic_list_item_class(topic)} input#bulk-select-#{topic.id}").clickend+ def click_topic_title(topic)+ find("#{topic_list_item_class(topic)} .raw-topic-link").click+ end+def visit_topic_with_title(title)find("#{TOPIC_LIST_BODY_SELECTOR} a", text: title).clickenddiff --git a/spec/system/topic_bulk_select_spec.rb b/spec/system/topic_bulk_select_spec.rbindex 14ece57c855..45dcf0d3006 100644--- a/spec/system/topic_bulk_select_spec.rb+++ b/spec/system/topic_bulk_select_spec.rb@@ -390,6 +390,18 @@ describe "Topic bulk select", type: :system doendend+ context "when clicking on the row" do+ it "selects it" do+ sign_in(admin)+ visit("/latest")++ topic_list_header.click_bulk_select_button+ topic_list.click_topic_title(topics.last)++ expect(topic_list).to have_checkbox_selected_on_row(1)+ end+ end+context "when changing topic notification levels" doit "allows changing notification levels for selected topics" dosign_in(admin)