diff --git a/packages/ui-default/pages/problem_edit.page.js b/packages/ui-default/pages/problem_edit.page.js index a47953901..49aef70be 100644 --- a/packages/ui-default/pages/problem_edit.page.js +++ b/packages/ui-default/pages/problem_edit.page.js @@ -116,13 +116,16 @@ function buildCategoryFilter() { }); $(document).on('click', '.widget--category-filter__tag', (ev) => { if (ev.shiftKey || ev.metaKey || ev.ctrlKey) return; - const category = $(ev.currentTarget).text(); - const treeItem = categories[category]; + const tag = $(ev.currentTarget).text(); + const category = $(ev.currentTarget).attr('data-category'); + const treeItem = category ? categories[category].children[tag] : categories[tag]; // the effect should be cancelSelect if it is shown as selected when clicking const shouldSelect = treeItem.$tag.hasClass('selected') ? false : !treeItem.select; treeItem.select = shouldSelect; - dirtyCategories.push({ type: 'category', category }); - if (!shouldSelect) { + dirtyCategories.push(category + ? { type: 'subcategory', subcategory: tag, category } + : { type: 'category', category: tag }); + if (!category && !shouldSelect) { // de-select children _.forEach(treeItem.children, (treeSubItem, subcategory) => { if (treeSubItem.select) { @@ -134,16 +137,6 @@ function buildCategoryFilter() { updateSelection(); ev.preventDefault(); }); - $(document).on('click', '.widget--category-filter__subcategory-tag', (ev) => { - if (ev.shiftKey || ev.metaKey || ev.ctrlKey) return; - const subcategory = $(ev.currentTarget).text(); - const category = $(ev.currentTarget).attr('data-category'); - const treeItem = categories[category].children[subcategory]; - treeItem.select = !treeItem.select; - dirtyCategories.push({ type: 'subcategory', subcategory, category }); - updateSelection(); - ev.preventDefault(); - }); } async function handleSection(ev, sidebar, type) {