mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 14:12:10 +08:00
FIX: Make select all and below skip small actions. (#7425)
This commit is contained in:
@ -173,11 +173,32 @@ export default Ember.Controller.extend(bufferedProperty("model"), {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_updateSelectedPostIds(postIds) {
|
_updateSelectedPostIds(postIds) {
|
||||||
this.get("selectedPostIds").pushObjects(postIds);
|
const smallActionsPostIds = this._smallActionPostIds();
|
||||||
|
this.get("selectedPostIds").pushObjects(
|
||||||
|
postIds.filter(postId => !smallActionsPostIds.has(postId))
|
||||||
|
);
|
||||||
this.set("selectedPostIds", [...new Set(this.get("selectedPostIds"))]);
|
this.set("selectedPostIds", [...new Set(this.get("selectedPostIds"))]);
|
||||||
this._forceRefreshPostStream();
|
this._forceRefreshPostStream();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_smallActionPostIds() {
|
||||||
|
const smallActionsPostIds = new Set();
|
||||||
|
const posts = this.get("model.postStream.posts");
|
||||||
|
if (posts) {
|
||||||
|
const small_action = this.site.get("post_types.small_action");
|
||||||
|
const whisper = this.site.get("post_types.whisper");
|
||||||
|
posts.forEach(post => {
|
||||||
|
if (
|
||||||
|
post.post_type === small_action ||
|
||||||
|
(!post.cooked && post.post_type === whisper)
|
||||||
|
) {
|
||||||
|
smallActionsPostIds.add(post.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return smallActionsPostIds;
|
||||||
|
},
|
||||||
|
|
||||||
_loadPostIds(post) {
|
_loadPostIds(post) {
|
||||||
if (this.get("loadingPostIds")) return;
|
if (this.get("loadingPostIds")) return;
|
||||||
|
|
||||||
@ -664,7 +685,12 @@ export default Ember.Controller.extend(bufferedProperty("model"), {
|
|||||||
},
|
},
|
||||||
|
|
||||||
selectAll() {
|
selectAll() {
|
||||||
this.set("selectedPostIds", [...this.get("model.postStream.stream")]);
|
const smallActionsPostIds = this._smallActionPostIds();
|
||||||
|
this.set("selectedPostIds", [
|
||||||
|
...this.get("model.postStream.stream").filter(
|
||||||
|
postId => !smallActionsPostIds.has(postId)
|
||||||
|
)
|
||||||
|
]);
|
||||||
this._forceRefreshPostStream();
|
this._forceRefreshPostStream();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -467,10 +467,22 @@ QUnit.test("togglePostSelection", function(assert) {
|
|||||||
// });
|
// });
|
||||||
|
|
||||||
QUnit.test("selectBelow", function(assert) {
|
QUnit.test("selectBelow", function(assert) {
|
||||||
const postStream = { stream: [1, 2, 3, 4, 5] };
|
const site = Ember.Object.create({
|
||||||
|
post_types: { small_action: 3, whisper: 4 }
|
||||||
|
});
|
||||||
|
|
||||||
|
const postStream = {
|
||||||
|
stream: [1, 2, 3, 4, 5, 6, 7, 8],
|
||||||
|
posts: [
|
||||||
|
{ id: 5, cooked: "whisper post", post_type: 4 },
|
||||||
|
{ id: 6, cooked: "a small action", post_type: 3 },
|
||||||
|
{ id: 7, cooked: "", post_type: 4 }
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
const model = Topic.create({ postStream });
|
const model = Topic.create({ postStream });
|
||||||
const controller = this.subject({ model });
|
const controller = this.subject({ site, model });
|
||||||
const selectedPostIds = controller.get("selectedPostIds");
|
let selectedPostIds = controller.get("selectedPostIds");
|
||||||
|
|
||||||
assert.equal(selectedPostIds[0], undefined, "no posts selected by default");
|
assert.equal(selectedPostIds[0], undefined, "no posts selected by default");
|
||||||
|
|
||||||
@ -479,6 +491,7 @@ QUnit.test("selectBelow", function(assert) {
|
|||||||
assert.equal(selectedPostIds[0], 3, "selected post #3");
|
assert.equal(selectedPostIds[0], 3, "selected post #3");
|
||||||
assert.equal(selectedPostIds[1], 4, "also selected 1st post below post #3");
|
assert.equal(selectedPostIds[1], 4, "also selected 1st post below post #3");
|
||||||
assert.equal(selectedPostIds[2], 5, "also selected 2nd post below post #3");
|
assert.equal(selectedPostIds[2], 5, "also selected 2nd post below post #3");
|
||||||
|
assert.equal(selectedPostIds[3], 8, "also selected 3rd post below post #3");
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test("topVisibleChanged", function(assert) {
|
QUnit.test("topVisibleChanged", function(assert) {
|
||||||
|
Reference in New Issue
Block a user