mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 20:03:15 +08:00
FEATURE: Select range in topic list with Shift + click (#15682)
This commit is contained in:
parent
c52e8ef8b6
commit
d13117fa05
|
@ -204,25 +204,44 @@ export default Component.extend({
|
|||
}
|
||||
|
||||
const topic = this.topic;
|
||||
const target = $(e.target);
|
||||
if (target.hasClass("bulk-select")) {
|
||||
if (e.target.classList.contains("bulk-select")) {
|
||||
const selected = this.selected;
|
||||
|
||||
if (target.is(":checked")) {
|
||||
if (e.target.checked) {
|
||||
selected.addObject(topic);
|
||||
|
||||
if (this.lastChecked && e.shiftKey) {
|
||||
const bulkSelects = Array.from(
|
||||
document.querySelectorAll("input.bulk-select")
|
||||
),
|
||||
from = bulkSelects.indexOf(e.target),
|
||||
to = bulkSelects.findIndex((el) => el.id === this.lastChecked.id),
|
||||
start = Math.min(from, to),
|
||||
end = Math.max(from, to);
|
||||
|
||||
bulkSelects
|
||||
.slice(start, end)
|
||||
.filter((el) => el.checked !== true)
|
||||
.forEach((checkbox) => {
|
||||
checkbox.click();
|
||||
});
|
||||
}
|
||||
|
||||
this.set("lastChecked", e.target);
|
||||
} else {
|
||||
selected.removeObject(topic);
|
||||
this.set("lastChecked", null);
|
||||
}
|
||||
}
|
||||
|
||||
if (target.hasClass("raw-topic-link")) {
|
||||
if (e.target.classList.contains("raw-topic-link")) {
|
||||
if (wantsNewWindow(e)) {
|
||||
return true;
|
||||
}
|
||||
return this.navigateToTopic(topic, target.attr("href"));
|
||||
return this.navigateToTopic(topic, e.target.getAttribute("href"));
|
||||
}
|
||||
|
||||
if (target.closest("a.topic-status").length === 1) {
|
||||
if (e.target.closest("a.topic-status")) {
|
||||
this.topic.togglePinnedForUser();
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ export default Mixin.create({
|
|||
bulkSelectEnabled: false,
|
||||
autoAddTopicsToBulkSelect: false,
|
||||
selected: null,
|
||||
lastChecked: null,
|
||||
|
||||
canBulkSelect: or("currentUser.staff", "showDismissRead", "showResetNew"),
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
expandAllPinned=expandAllPinned
|
||||
lastVisitedTopic=lastVisitedTopic
|
||||
selected=selected
|
||||
lastChecked=lastChecked
|
||||
tagsForUser=tagsForUser}}
|
||||
{{raw "list/visited-line" lastVisitedTopic=lastVisitedTopic topic=topic}}
|
||||
{{/each}}
|
||||
|
|
|
@ -4,7 +4,7 @@ import {
|
|||
queryAll,
|
||||
updateCurrentUser,
|
||||
} from "discourse/tests/helpers/qunit-helpers";
|
||||
import { click, visit } from "@ember/test-helpers";
|
||||
import { click, triggerEvent, visit } from "@ember/test-helpers";
|
||||
import { test } from "qunit";
|
||||
import I18n from "I18n";
|
||||
|
||||
|
@ -121,4 +121,32 @@ acceptance("Topic - Bulk Actions", function (needs) {
|
|||
"it closes the bulk select modal"
|
||||
);
|
||||
});
|
||||
|
||||
test("bulk select - Shift click selection", async function (assert) {
|
||||
updateCurrentUser({ moderator: true });
|
||||
await visit("/latest");
|
||||
await click("button.bulk-select");
|
||||
|
||||
await click(queryAll("input.bulk-select")[0]);
|
||||
await triggerEvent(queryAll("input.bulk-select")[3], "click", {
|
||||
shiftKey: true,
|
||||
});
|
||||
assert.equal(
|
||||
queryAll("input.bulk-select:checked").length,
|
||||
4,
|
||||
"Shift click selects a range"
|
||||
);
|
||||
|
||||
await click("button.bulk-clear-all");
|
||||
|
||||
await click(queryAll("input.bulk-select")[5]);
|
||||
await triggerEvent(queryAll("input.bulk-select")[1], "click", {
|
||||
shiftKey: true,
|
||||
});
|
||||
assert.equal(
|
||||
queryAll("input.bulk-select:checked").length,
|
||||
5,
|
||||
"Bottom-up Shift click range selection works"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user