mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06: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 topic = this.topic;
|
||||||
const target = $(e.target);
|
if (e.target.classList.contains("bulk-select")) {
|
||||||
if (target.hasClass("bulk-select")) {
|
|
||||||
const selected = this.selected;
|
const selected = this.selected;
|
||||||
|
|
||||||
if (target.is(":checked")) {
|
if (e.target.checked) {
|
||||||
selected.addObject(topic);
|
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 {
|
} else {
|
||||||
selected.removeObject(topic);
|
selected.removeObject(topic);
|
||||||
|
this.set("lastChecked", null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target.hasClass("raw-topic-link")) {
|
if (e.target.classList.contains("raw-topic-link")) {
|
||||||
if (wantsNewWindow(e)) {
|
if (wantsNewWindow(e)) {
|
||||||
return true;
|
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();
|
this.topic.togglePinnedForUser();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ export default Mixin.create({
|
|||||||
bulkSelectEnabled: false,
|
bulkSelectEnabled: false,
|
||||||
autoAddTopicsToBulkSelect: false,
|
autoAddTopicsToBulkSelect: false,
|
||||||
selected: null,
|
selected: null,
|
||||||
|
lastChecked: null,
|
||||||
|
|
||||||
canBulkSelect: or("currentUser.staff", "showDismissRead", "showResetNew"),
|
canBulkSelect: or("currentUser.staff", "showDismissRead", "showResetNew"),
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
expandAllPinned=expandAllPinned
|
expandAllPinned=expandAllPinned
|
||||||
lastVisitedTopic=lastVisitedTopic
|
lastVisitedTopic=lastVisitedTopic
|
||||||
selected=selected
|
selected=selected
|
||||||
|
lastChecked=lastChecked
|
||||||
tagsForUser=tagsForUser}}
|
tagsForUser=tagsForUser}}
|
||||||
{{raw "list/visited-line" lastVisitedTopic=lastVisitedTopic topic=topic}}
|
{{raw "list/visited-line" lastVisitedTopic=lastVisitedTopic topic=topic}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
@ -4,7 +4,7 @@ import {
|
|||||||
queryAll,
|
queryAll,
|
||||||
updateCurrentUser,
|
updateCurrentUser,
|
||||||
} from "discourse/tests/helpers/qunit-helpers";
|
} 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 { test } from "qunit";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
|
|
||||||
@ -121,4 +121,32 @@ acceptance("Topic - Bulk Actions", function (needs) {
|
|||||||
"it closes the bulk select modal"
|
"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