From f336aeee6f08ddb3b42d8dbbc8199b504be60274 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Mon, 24 Feb 2020 19:19:53 +0100 Subject: [PATCH] FIX: ensures scoped search category is searching in all categories (#9031) --- .../components/category-chooser.js.es6 | 18 +++++++----------- .../select-kit/category-chooser-test.js.es6 | 10 +++++++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/select-kit/components/category-chooser.js.es6 b/app/assets/javascripts/select-kit/components/category-chooser.js.es6 index 9b475bc5749..d929bfac3ef 100644 --- a/app/assets/javascripts/select-kit/components/category-chooser.js.es6 +++ b/app/assets/javascripts/select-kit/components/category-chooser.js.es6 @@ -66,15 +66,7 @@ export default ComboBoxComponent.extend({ search(filter) { if (filter) { - let content = this.content; - - if (this.selectKit.options.scopedCategoryId) { - content = this.categoriesByScope( - this.selectKit.options.scopedCategoryId - ); - } - - return content.filter(item => { + return this.content.filter(item => { const category = Category.findById(this.getValue(item)); const categoryName = this.getName(item); @@ -93,8 +85,12 @@ export default ComboBoxComponent.extend({ } }, - content: computed("selectKit.options.scopedCategoryId", function() { - return this.categoriesByScope(this.selectKit.options.scopedCategoryId); + content: computed("selectKit.{filter,options.scopedCategoryId}", function() { + if (!this.selectKit.filter && this.selectKit.options.scopedCategoryId) { + return this.categoriesByScope(this.selectKit.options.scopedCategoryId); + } else { + return this.categoriesByScope(); + } }), categoriesByScope(scopedCategoryId = null) { diff --git a/test/javascripts/components/select-kit/category-chooser-test.js.es6 b/test/javascripts/components/select-kit/category-chooser-test.js.es6 index 10fb3bb5c14..196f692e3c5 100644 --- a/test/javascripts/components/select-kit/category-chooser-test.js.es6 +++ b/test/javascripts/components/select-kit/category-chooser-test.js.es6 @@ -52,11 +52,15 @@ componentTest("with scopedCategoryId", { "My idea here is to have mini specs for features we would like built but have no bandwidth to build" ); assert.equal(this.subject.rowByIndex(1).value(), 26); - assert.equal(this.subject.rows().length, 2); + assert.equal(this.subject.rows().length, 2, "default content is scoped"); - await this.subject.fillInFilter("spec"); + await this.subject.fillInFilter("bug"); - assert.equal(this.subject.rows().length, 1); + assert.equal( + this.subject.rowByIndex(0).name(), + "bug", + "search finds outside of scope" + ); } });