FEATURE: Show all categories in composer (#13213)

…and just prioritize the current one, instead of hiding other categories.

Context: when you open the composer by clicking "New Topic" button when in a category, or by clicking "New Topic" in the share-popup, the category selector shows only the current category and its children (and "Uncategorized"). You can still find other categories, but you have to search by name.
This PR changes that, so you now can see all the categories in the dropdown, and those that are relevant (again: current, children and uncategorized) are displayed before all other categories.

tldr: don't make choosing other categories harder - make choosing relevant ones easier.
This commit is contained in:
Jarek Radosz
2021-05-31 20:50:23 +02:00
committed by GitHub
parent be92f4e959
commit 869518e3d2
7 changed files with 141 additions and 24 deletions

View File

@@ -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) {