A platform for community discussion. Free, open, simple.
FEATURE: Show all categories in composer (#13213)
Jarek Radosz869518e3d22c
diff --git a/app/assets/javascripts/discourse/app/controllers/composer.js b/app/assets/javascripts/discourse/app/controllers/composer.jsindex 5d1459db6b2..e0c09b70b51 100644--- a/app/assets/javascripts/discourse/app/controllers/composer.js+++ b/app/assets/javascripts/discourse/app/controllers/composer.js@@ -101,6 +101,7 @@ export default Controller.extend({showEditReason: false,editReason: null,scopedCategoryId: null,+ prioritizedCategoryId: null,lastValidatedAt: null,isUploading: false,topic: null,@@ -874,15 +875,22 @@ export default Controller.extend({},/**- Open the composer view-- @method open- @param {Object} opts Options for creating a post- @param {String} opts.action The action we're performing: edit, reply or createTopic- @param {Post} [opts.post] The post we're replying to- @param {Topic} [opts.topic] The topic we're replying to- @param {String} [opts.quote] If we're opening a reply from a quote, the quote we're making- **/+ Open the composer view++ @method open+ @param {Object} opts Options for creating a post+ @param {String} opts.action The action we're performing: edit, reply, createTopic, createSharedDraft, privateMessage+ @param {String} opts.draftKey+ @param {Post} [opts.post] The post we're replying to+ @param {Topic} [opts.topic] The topic we're replying to+ @param {String} [opts.quote] If we're opening a reply from a quote, the quote we're making+ @param {Boolean} [opts.ignoreIfChanged]+ @param {Boolean} [opts.disableScopedCategory]+ @param {Number} [opts.categoryId] Sets `scopedCategoryId` and `categoryId` on the Composer model+ @param {Number} [opts.prioritizedCategoryId]+ @param {String} [opts.draftSequence]+ @param {Boolean} [opts.skipDraftCheck]+ **/open(opts) {opts = opts || {};@@ -904,6 +912,7 @@ export default Controller.extend({showEditReason: false,editReason: null,scopedCategoryId: null,+ prioritizedCategoryId: null,skipAutoSave: true,});@@ -915,6 +924,16 @@ export default Controller.extend({}}+ if (opts.prioritizedCategoryId) {+ const category = this.site.categories.findBy(+ "id",+ opts.prioritizedCategoryId+ );+ if (category) {+ this.set("prioritizedCategoryId", opts.prioritizedCategoryId);+ }+ }+// If we want a different draft than the current composer, close it and clear our model.if (composerModel &&diff --git a/app/assets/javascripts/discourse/app/controllers/topic.js b/app/assets/javascripts/discourse/app/controllers/topic.jsindex c6a5289b2b6..c3e4060c9b3 100644--- a/app/assets/javascripts/discourse/app/controllers/topic.js+++ b/app/assets/javascripts/discourse/app/controllers/topic.js@@ -1036,7 +1036,8 @@ export default Controller.extend(bufferedProperty("model"), {options = {action: Composer.CREATE_TOPIC,draftKey: post.topic.draft_key,- categoryId: this.get("model.category.id"),+ topicCategoryId: this.get("model.category.id"),+ prioritizedCategoryId: this.get("model.category.id"),};}diff --git a/app/assets/javascripts/discourse/app/mixins/open-composer.js b/app/assets/javascripts/discourse/app/mixins/open-composer.jsindex 8b21b283a1d..250469854a6 100644--- a/app/assets/javascripts/discourse/app/mixins/open-composer.js+++ b/app/assets/javascripts/discourse/app/mixins/open-composer.js@@ -14,7 +14,8 @@ export default Mixin.create({}this.controllerFor("composer").open({- categoryId,+ prioritizedCategoryId: categoryId,+ topicCategoryId: categoryId,action: Composer.CREATE_TOPIC,draftKey: controller.get("model.draft_key") || Composer.NEW_TOPIC_KEY,draftSequence: controller.get("model.draft_sequence") || 0,diff --git a/app/assets/javascripts/discourse/app/models/composer.js b/app/assets/javascripts/discourse/app/models/composer.jsindex b36abfb5249..9851d480dc3 100644--- a/app/assets/javascripts/discourse/app/models/composer.js+++ b/app/assets/javascripts/discourse/app/models/composer.js@@ -693,15 +693,30 @@ const Composer = RestModel.extend({}},- /*- Open a composer-- opts:- action - The action we're performing: edit, reply or createTopic- post - The post we're replying to, if present- topic - The topic we're replying to, if present- quote - If we're opening a reply from a quote, the quote we're making- */+ /**+ Open a composer++ @method open+ @param {Object} opts+ @param {String} opts.action The action we're performing: edit, reply, createTopic, createSharedDraft, privateMessage+ @param {String} opts.draftKey+ @param {String} opts.draftSequence+ @param {Post} [opts.post] The post we're replying to, if present+ @param {Topic} [opts.topic] The topic we're replying to, if present+ @param {String} [opts.quote] If we're opening a reply from a quote, the quote we're making+ @param {String} [opts.reply]+ @param {String} [opts.recipients]+ @param {Number} [opts.composerTime]+ @param {Number} [opts.typingTime]+ @param {Boolean} [opts.whisper]+ @param {Boolean} [opts.noBump]+ @param {String} [opts.archetypeId] One of `site.archetypes` e.g. `regular` or `private_message`+ @param {Object} [opts.metaData]+ @param {Number} [opts.categoryId]+ @param {Number} [opts.postId]+ @param {Number} [opts.destinationCategoryId]+ @param {String} [opts.title]+ **/open(opts) {let promise = Promise.resolve();diff --git a/app/assets/javascripts/discourse/app/templates/composer.hbs b/app/assets/javascripts/discourse/app/templates/composer.hbsindex d06cbcdd5b6..955df36efe8 100644--- a/app/assets/javascripts/discourse/app/templates/composer.hbs+++ b/app/assets/javascripts/discourse/app/templates/composer.hbs@@ -80,6 +80,7 @@isDisabled=disableCategoryChooseroptions=(hashscopedCategoryId=scopedCategoryId+ prioritizedCategoryId=prioritizedCategoryId)}}{{popup-input-tip validation=categoryValidation}}diff --git a/app/assets/javascripts/discourse/tests/integration/components/select-kit/category-chooser-test.js b/app/assets/javascripts/discourse/tests/integration/components/select-kit/category-chooser-test.jsindex c695a350b58..b3e18a6e302 100644--- a/app/assets/javascripts/discourse/tests/integration/components/select-kit/category-chooser-test.js+++ b/app/assets/javascripts/discourse/tests/integration/components/select-kit/category-chooser-test.js@@ -89,6 +89,44 @@ discourseModule(},});+ componentTest("with prioritizedCategoryId", {+ template: hbs`+ {{category-chooser+ value=value+ options=(hash+ prioritizedCategoryId=5+ )+ }}+ `,++ async test(assert) {+ await this.subject.expand();++ // The prioritized category+ assert.equal(this.subject.rowByIndex(0).value(), 5);+ // The prioritized category's child+ assert.equal(this.subject.rowByIndex(1).value(), 22);+ // Other categories in the default order+ assert.equal(this.subject.rowByIndex(2).value(), 6);+ assert.equal(this.subject.rowByIndex(3).value(), 21);+ assert.equal(this.subject.rowByIndex(4).value(), 1);++ assert.equal(+ this.subject.rows().length,+ 20,+ "all categories are visible"+ );++ await this.subject.fillInFilter("bug");++ assert.equal(+ this.subject.rowByIndex(0).name(),+ "bug",+ "search still finds categories"+ );+ },+ });+componentTest("with allowUncategorized=null", {template: hbs`{{category-chooserdiff --git a/app/assets/javascripts/select-kit/addon/components/category-chooser.js b/app/assets/javascripts/select-kit/addon/components/category-chooser.jsindex fa56c7a4430..a81cf0cd9cc 100644--- a/app/assets/javascripts/select-kit/addon/components/category-chooser.js+++ b/app/assets/javascripts/select-kit/addon/components/category-chooser.js@@ -90,16 +90,31 @@ export default ComboBoxComponent.extend({content: computed("selectKit.filter","selectKit.options.scopedCategoryId",+ "selectKit.options.prioritizedCategoryId",function () {- if (!this.selectKit.filter && this.selectKit.options.scopedCategoryId) {- return this.categoriesByScope(this.selectKit.options.scopedCategoryId);- } else {- return this.categoriesByScope();+ if (!this.selectKit.filter) {+ let {+ scopedCategoryId,+ prioritizedCategoryId,+ } = this.selectKit.options;++ if (scopedCategoryId) {+ return this.categoriesByScope({ scopedCategoryId });+ }++ if (prioritizedCategoryId) {+ return this.categoriesByScope({ prioritizedCategoryId });+ }}++ return this.categoriesByScope();}),- categoriesByScope(scopedCategoryId = null) {+ categoriesByScope({+ scopedCategoryId = null,+ prioritizedCategoryId = null,+ } = {}) {const categories = this.fixedCategoryPositionsOnCreate? Category.list(): Category.listByActivity();@@ -109,9 +124,14 @@ export default ComboBoxComponent.extend({scopedCategoryId = scopedCat.parent_category_id || scopedCat.id;}+ if (prioritizedCategoryId) {+ const category = Category.findById(prioritizedCategoryId);+ prioritizedCategoryId = category.parent_category_id || category.id;+ }+const excludeCategoryId = this.selectKit.options.excludeCategoryId;- return categories.filter((category) => {+ let scopedCategories = categories.filter((category) => {const categoryId = this.getValue(category);if (@@ -144,6 +164,28 @@ export default ComboBoxComponent.extend({return true;});++ if (prioritizedCategoryId) {+ let prioritized = [];+ let other = [];++ for (let category of scopedCategories) {+ const categoryId = this.getValue(category);++ if (+ categoryId === prioritizedCategoryId ||+ category.parent_category_id === prioritizedCategoryId+ ) {+ prioritized.push(category);+ } else {+ other.push(category);+ }+ }++ return prioritized.concat(other);+ } else {+ return scopedCategories;+ }},_matchCategory(filter, categoryName) {