A platform for community discussion. Free, open, simple.
FIX: Make select all and below skip small actions. (#7425)
Dan Ungureanu33e06dd79685
diff --git a/app/assets/javascripts/discourse/controllers/topic.js.es6 b/app/assets/javascripts/discourse/controllers/topic.js.es6index dcac19a49a0..a340b95293d 100644--- a/app/assets/javascripts/discourse/controllers/topic.js.es6+++ b/app/assets/javascripts/discourse/controllers/topic.js.es6@@ -173,11 +173,32 @@ export default Ember.Controller.extend(bufferedProperty("model"), {},_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._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) {if (this.get("loadingPostIds")) return;@@ -664,7 +685,12 @@ export default Ember.Controller.extend(bufferedProperty("model"), {},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();},diff --git a/test/javascripts/controllers/topic-test.js.es6 b/test/javascripts/controllers/topic-test.js.es6index 2ba53e12218..98575b66291 100644--- a/test/javascripts/controllers/topic-test.js.es6+++ b/test/javascripts/controllers/topic-test.js.es6@@ -467,10 +467,22 @@ QUnit.test("togglePostSelection", 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 controller = this.subject({ model });- const selectedPostIds = controller.get("selectedPostIds");+ const controller = this.subject({ site, model });+ let selectedPostIds = controller.get("selectedPostIds");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[1], 4, "also selected 1st 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) {